rorenv/10-hosts.sh

18 lines
639 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
echo "現在のネットワーク設定はこのようになっています。"
ip a | grep "\(^[[:digit:]]\+\|inet \)"
echo "example.netのIPアドレスとして何を登録しますか"
echo "何も入力しなければ 127.0.0.1 を登録します。"
read -p "IPアドレス: " IPADDRESS
if [ -z $IPADDRESS ];then
IPADDRESS="127.0.0.1"
fi
DOMMEMBER="example\.net git\.example\.net mail\.example\.net smtp\.example\.net"
if [ $(grep -c "$DOMMEMBER" /etc/hosts) -eq 0 ]; then
sudo sed -i "\$a $IPADDRESS\t$DOMMEMBER" /etc/hosts
else
sudo sed -i "s/^[0-9.]\+[[:blank:]]\+\($DOMMEMBER\)/$IPADDRESS\t\1/" /etc/hosts
fi