lazy/init_root.sh
2023-07-16 01:18:47 +08:00

40 lines
894 B
Bash
Executable File

#!/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")
if [ "$response" -eq 200 ]; then
echo "Internet: abroad"
abroad=1
else
echo "Internet: 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
read -p "sshkey 的名字: " sshkeyname
ssh-keygen -t ed25519 -C $sshkeyname
fi
}
check_google_access
configure_ssh
configure_ssh_keygen