From 4945bdd75273a2aa2f3e4dac540b35d4efe910a7 Mon Sep 17 00:00:00 2001 From: Konano Date: Sat, 22 Jul 2023 14:55:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init_root.sh | 22 +++++++++++++++++----- init_sudo.sh | 22 +++++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/init_root.sh b/init_root.sh index 529066f..59fe527 100755 --- a/init_root.sh +++ b/init_root.sh @@ -36,6 +36,8 @@ check_google_access() { } configure_ssh() { + [ -f "~/.ssh/authorized_keys" ] && return + read -p "要配置 .ssh 吗?[Y/n]: " response if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then @@ -45,6 +47,8 @@ configure_ssh() { } configure_ssh_keygen() { + [ -f "~/.ssh/id_ed25519.pub" ] && return + read -p "要生成 sshkey 吗?[y/N]: " response if [[ $response =~ ^[Yy]$ ]]; then @@ -55,6 +59,8 @@ configure_ssh_keygen() { } configure_nano() { + [ -f "~/.nanorc" ] && return + read -p "要配置 nano 吗?[Y/n]: " response if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then @@ -74,7 +80,7 @@ configure_vim() { configure_apt_upgrade() { read -p "要运行 apt upgrade 吗?[y/N]: " response - + if [[ $response =~ ^[Yy]$ ]]; then apt update apt upgrade -y @@ -84,7 +90,7 @@ configure_apt_upgrade() { configure_apt_install() { read -p "要运行 apt install 吗?[Y/n]: " response - + if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then apt update apt install tmux git curl htop net-tools tcptraceroute tar unzip -y @@ -102,6 +108,8 @@ configure_apt_install() { } configure_zsh() { + [ -f "~/.zshrc" ] && return + read -p "要配置 zsh 吗?[Y/n]: " response if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then @@ -120,6 +128,8 @@ configure_zsh() { } configure_tmux() { + [ -f "~/.tmux.conf" ] && return + read -p "要配置 tmux 吗?[Y/n]: " response if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then @@ -130,11 +140,13 @@ configure_tmux() { git_clone tmux-plugins/tmux-prefix-highlight ~/.tmux/plugins/tmux-prefix-highlight git_clone seebi/tmux-colors-solarized ~/.tmux/plugins/tmux-colors-solarized cp $scriptdir/files/.tmux.conf ~/.tmux.conf - apt install xsel -y # 能够让 tmux 剪切板与 terminal 同步 + apt install xsel -y # 能够让 tmux 剪切板与 terminal 同步 fi } configure_iptables() { + [ -f "/etc/network/if-pre-up.d/iptables-load" ] && return + read -p "要配置 iptables 吗?[n/Y]: " response if [[ $response =~ ^[Yy]$ ]]; then @@ -145,8 +157,8 @@ configure_iptables() { } if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root." - exit 1 + echo "This script must be run as root." + exit 1 fi check_google_access diff --git a/init_sudo.sh b/init_sudo.sh index bf92e6f..5f0019e 100755 --- a/init_sudo.sh +++ b/init_sudo.sh @@ -36,6 +36,8 @@ check_google_access() { } configure_ssh() { + [ -f "~/.ssh/authorized_keys" ] && return + read -p "要配置 .ssh 吗?[Y/n]: " response if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then @@ -45,6 +47,8 @@ configure_ssh() { } configure_ssh_keygen() { + [ -f "~/.ssh/id_ed25519.pub" ] && return + read -p "要生成 sshkey 吗?[y/N]: " response if [[ $response =~ ^[Yy]$ ]]; then @@ -55,6 +59,8 @@ configure_ssh_keygen() { } configure_nano() { + [ -f "~/.nanorc" ] && return + read -p "要配置 nano 吗?[Y/n]: " response if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then @@ -74,7 +80,7 @@ configure_vim() { configure_apt_upgrade() { read -p "要运行 apt upgrade 吗?[y/N]: " response - + if [[ $response =~ ^[Yy]$ ]]; then sudo apt update sudo apt upgrade -y @@ -84,7 +90,7 @@ configure_apt_upgrade() { configure_apt_install() { read -p "要运行 apt install 吗?[Y/n]: " response - + if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then sudo apt update sudo apt install tmux git curl htop net-tools tcptraceroute tar unzip -y @@ -102,6 +108,8 @@ configure_apt_install() { } configure_zsh() { + [ -f "~/.zshrc" ] && return + read -p "要配置 zsh 吗?[Y/n]: " response if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then @@ -120,6 +128,8 @@ configure_zsh() { } configure_tmux() { + [ -f "~/.tmux.conf" ] && return + read -p "要配置 tmux 吗?[Y/n]: " response if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then @@ -130,11 +140,13 @@ configure_tmux() { git_clone tmux-plugins/tmux-prefix-highlight ~/.tmux/plugins/tmux-prefix-highlight git_clone seebi/tmux-colors-solarized ~/.tmux/plugins/tmux-colors-solarized cp $scriptdir/files/.tmux.conf ~/.tmux.conf - sudo apt install xsel -y # 能够让 tmux 剪切板与 terminal 同步 + sudo apt install xsel -y # 能够让 tmux 剪切板与 terminal 同步 fi } configure_iptables() { + [ -f "/etc/network/if-pre-up.d/iptables-load" ] && return + read -p "要配置 iptables 吗?[n/Y]: " response if [[ $response =~ ^[Yy]$ ]]; then @@ -145,8 +157,8 @@ configure_iptables() { } if [[ $EUID -eq 0 ]]; then - echo "This script should not be run as root." - exit 1 + echo "This script should not be run as root." + exit 1 fi check_google_access