rorenv/10-hosts.sh

18 lines
658 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 test\.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