rorenv/10-hosts.sh

18 lines
658 B
Bash
Raw Normal View History

2023-04-29 21:11:49 +09:00
#!/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
2023-05-09 08:11:54 +09:00
DOMMEMBER="example\.net git\.example\.net mail\.example\.net smtp\.example\.net test\.example\.net"
2023-04-29 21:11:49 +09:00
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