diff --git a/init_root.sh b/init_root.sh index a14600e..5c3421c 100755 --- a/init_root.sh +++ b/init_root.sh @@ -1,7 +1,38 @@ #!/bin/bash -scriptdir=$(dirname $(realpath $0)) +check_google_access() { + abroad=0 + local response=$(curl -s -o /dev/null -w "%{http_code}" -m 5 "http://www.google.com") -mkdir -p ~/.ssh -cat $scriptdir/files/authorized_keys >> ~/.ssh/authorized_keys + if [ "$response" -eq 200 ]; then + echo "Intenet: abroad" + abroad=1 + else + echo "Intenet: internal" + abroad=0 + fi +} +configure_ssh() { + read -p "要配置 .ssh 吗?[Y/n]: " response + + if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then + mkdir -p ~/.ssh + cp $scriptdir/files/authorized_keys ~/.ssh/authorized_keys + fi +} + +configure_ssh_keygen() { + read -p "要生成 sshkey 吗?[Y/n]: " response + + if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then + mkdir -p ~/.ssh + ssh-keygen -t ed25519 -C "ubuntu" + fi +} + +check_google_access +configure_ssh +configure_ssh_keygen + +# scriptdir=$(dirname $(realpath $0))