add confirm_action
This commit is contained in:
parent
1dc82077bb
commit
da443aaa8f
44
init_priv.sh
44
init_priv.sh
@ -17,9 +17,7 @@ fi
|
|||||||
configure_tuna() {
|
configure_tuna() {
|
||||||
[ $abroad -eq 1 ] && return
|
[ $abroad -eq 1 ] && return
|
||||||
|
|
||||||
read -p "要切换 Tuna 源吗?[N]: " response
|
if confirm_action "要切换 Tuna 源吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
python3 $scriptdir/files/oh-my-tuna.py
|
python3 $scriptdir/files/oh-my-tuna.py
|
||||||
# 如果 uid 不为 0 则 sudo 再跑一次
|
# 如果 uid 不为 0 则 sudo 再跑一次
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
@ -29,9 +27,7 @@ configure_tuna() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_upgrade() {
|
configure_upgrade() {
|
||||||
read -p "要运行 apt upgrade 吗?[N]: " response
|
if confirm_action "要运行 apt upgrade 吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt upgrade -y
|
sudo apt upgrade -y
|
||||||
sudo apt autoremove -y
|
sudo apt autoremove -y
|
||||||
@ -39,9 +35,7 @@ configure_upgrade() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_install() {
|
configure_install() {
|
||||||
read -p "要运行 apt/pip3 install 吗?[N]: " response
|
if confirm_action "要运行 apt/pip3 install 吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install tmux git curl htop net-tools tcptraceroute tar unzip -y
|
sudo apt install tmux git curl htop net-tools tcptraceroute tar unzip -y
|
||||||
sudo apt install hexyl bat neofetch fd-find fzf pigz -y
|
sudo apt install hexyl bat neofetch fd-find fzf pigz -y
|
||||||
@ -61,9 +55,7 @@ configure_install() {
|
|||||||
configure_nano() {
|
configure_nano() {
|
||||||
[ -f ~/.nanorc ] && return
|
[ -f ~/.nanorc ] && return
|
||||||
|
|
||||||
read -p "要配置 nano 吗?[Y]: " response
|
if confirm_action "要配置 nano 吗?" "Y"; then
|
||||||
|
|
||||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo apt install nano -y
|
sudo apt install nano -y
|
||||||
cp $scriptdir/files/.nanorc ~/.nanorc
|
cp $scriptdir/files/.nanorc ~/.nanorc
|
||||||
fi
|
fi
|
||||||
@ -72,9 +64,7 @@ configure_nano() {
|
|||||||
configure_vim() {
|
configure_vim() {
|
||||||
[ -f ~/.vimrc ] && return
|
[ -f ~/.vimrc ] && return
|
||||||
|
|
||||||
read -p "要配置 vim 吗?[Y]: " response
|
if confirm_action "要配置 vim 吗?" "Y"; then
|
||||||
|
|
||||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo apt install vim -y
|
sudo apt install vim -y
|
||||||
cp $scriptdir/files/.vimrc ~/.vimrc
|
cp $scriptdir/files/.vimrc ~/.vimrc
|
||||||
fi
|
fi
|
||||||
@ -83,9 +73,7 @@ configure_vim() {
|
|||||||
configure_zsh() {
|
configure_zsh() {
|
||||||
[ -f ~/.zshrc ] && return
|
[ -f ~/.zshrc ] && return
|
||||||
|
|
||||||
read -p "要配置 zsh 吗?[Y]: " response
|
if confirm_action "要配置 zsh 吗?" "Y"; then
|
||||||
|
|
||||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo apt install zsh -y
|
sudo apt install zsh -y
|
||||||
|
|
||||||
rm ~/.oh-my-zsh -r
|
rm ~/.oh-my-zsh -r
|
||||||
@ -105,9 +93,7 @@ configure_zsh() {
|
|||||||
configure_tmux() {
|
configure_tmux() {
|
||||||
[ -f ~/.tmux.conf ] && return
|
[ -f ~/.tmux.conf ] && return
|
||||||
|
|
||||||
read -p "要配置 tmux 吗?[Y]: " response
|
if confirm_action "要配置 tmux 吗?" "Y"; then
|
||||||
|
|
||||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo apt install tmux -y
|
sudo apt install tmux -y
|
||||||
|
|
||||||
rm ~/.tmux -r
|
rm ~/.tmux -r
|
||||||
@ -125,9 +111,7 @@ configure_tmux() {
|
|||||||
configure_fail2ban() {
|
configure_fail2ban() {
|
||||||
[ -f /etc/fail2ban/jail.local ] && return
|
[ -f /etc/fail2ban/jail.local ] && return
|
||||||
|
|
||||||
read -p "要配置 fail2ban 吗?[N]: " response
|
if confirm_action "要配置 fail2ban 吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo apt install fail2ban
|
sudo apt install fail2ban
|
||||||
sudo mkdir -p /etc/fail2ban
|
sudo mkdir -p /etc/fail2ban
|
||||||
sudo cp $scriptdir/files/jail.local /etc/fail2ban/jail.local
|
sudo cp $scriptdir/files/jail.local /etc/fail2ban/jail.local
|
||||||
@ -140,9 +124,7 @@ configure_fail2ban() {
|
|||||||
configure_iptables() {
|
configure_iptables() {
|
||||||
[ -f /etc/network/if-pre-up.d/iptables-load ] && return
|
[ -f /etc/network/if-pre-up.d/iptables-load ] && return
|
||||||
|
|
||||||
read -p "要配置 iptables 吗?[N]: " response
|
if confirm_action "要配置 iptables 吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo cp $scriptdir/files/iptables-load /etc/network/if-pre-up.d/iptables-load
|
sudo cp $scriptdir/files/iptables-load /etc/network/if-pre-up.d/iptables-load
|
||||||
sudo chmod +x /etc/network/if-pre-up.d/iptables-load
|
sudo chmod +x /etc/network/if-pre-up.d/iptables-load
|
||||||
sudo sh /etc/network/if-pre-up.d/iptables-load
|
sudo sh /etc/network/if-pre-up.d/iptables-load
|
||||||
@ -150,18 +132,14 @@ configure_iptables() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_hostname() {
|
configure_hostname() {
|
||||||
read -p "要修改 hostname 吗?[N]: " response
|
if confirm_action "要修改 hostname 吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
read -p "hostname: " new_hostname
|
read -p "hostname: " new_hostname
|
||||||
echo $new_hostname | sudo tee /etc/hostname >/dev/null
|
echo $new_hostname | sudo tee /etc/hostname >/dev/null
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_timedate() {
|
configure_timedate() {
|
||||||
read -p "要修改 时区 吗?[N]: " response
|
if confirm_action "要修改 时区 吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
sudo timedatectl set-timezone Asia/Shanghai
|
sudo timedatectl set-timezone Asia/Shanghai
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
20
init_user.sh
20
init_user.sh
@ -13,9 +13,7 @@ update_file $scriptdir/files/ys-simple.zsh-theme ~/.oh-my-zsh/themes/ys-simple.z
|
|||||||
configure_ssh() {
|
configure_ssh() {
|
||||||
[ -f ~/.ssh/authorized_keys ] && return
|
[ -f ~/.ssh/authorized_keys ] && return
|
||||||
|
|
||||||
read -p "要配置 authorized_keys 吗?[Y]: " response
|
if confirm_action "要配置 authorized_keys 吗?" "Y"; then
|
||||||
|
|
||||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
cp $scriptdir/files/authorized_keys ~/.ssh/authorized_keys
|
cp $scriptdir/files/authorized_keys ~/.ssh/authorized_keys
|
||||||
fi
|
fi
|
||||||
@ -24,9 +22,7 @@ configure_ssh() {
|
|||||||
configure_ssh_keygen() {
|
configure_ssh_keygen() {
|
||||||
[ -f ~/.ssh/id_ed25519.pub ] && return
|
[ -f ~/.ssh/id_ed25519.pub ] && return
|
||||||
|
|
||||||
read -p "要生成 sshkey 吗?[N]: " response
|
if confirm_action "要生成 sshkey 吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
read -p "sshkey 的名字: " sshkeyname
|
read -p "sshkey 的名字: " sshkeyname
|
||||||
ssh-keygen -t ed25519 -C $sshkeyname
|
ssh-keygen -t ed25519 -C $sshkeyname
|
||||||
@ -36,9 +32,7 @@ configure_ssh_keygen() {
|
|||||||
configure_git() {
|
configure_git() {
|
||||||
[ -f ~/.gitconfig ] && return
|
[ -f ~/.gitconfig ] && return
|
||||||
|
|
||||||
read -p "要配置 git 吗?[N]: " response
|
if confirm_action "要配置 git 吗?" "N"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
cp $scriptdir/files/.gitconfig ~/.gitconfig
|
cp $scriptdir/files/.gitconfig ~/.gitconfig
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -46,9 +40,7 @@ configure_git() {
|
|||||||
configure_miniconda() {
|
configure_miniconda() {
|
||||||
[ -d ~/.miniconda3 ] && return
|
[ -d ~/.miniconda3 ] && return
|
||||||
|
|
||||||
read -p "要安装 miniconda 吗?[N]: " response
|
if confirm_action "要安装 miniconda 吗?" "Y"; then
|
||||||
|
|
||||||
if [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $tempdir/miniconda.sh
|
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $tempdir/miniconda.sh
|
||||||
bash $tempdir/miniconda.sh -b -p ~/.miniconda3
|
bash $tempdir/miniconda.sh -b -p ~/.miniconda3
|
||||||
rm $tempdir/miniconda.sh
|
rm $tempdir/miniconda.sh
|
||||||
@ -62,9 +54,7 @@ configure_miniconda() {
|
|||||||
configure_nodejs() {
|
configure_nodejs() {
|
||||||
[ -d ~/.nvm/.git ] && return
|
[ -d ~/.nvm/.git ] && return
|
||||||
|
|
||||||
read -p "要安装 nodejs 吗?[Y]: " response
|
if confirm_action "要安装 nodejs 吗?" "Y"; then
|
||||||
|
|
||||||
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
||||||
git_clone nvm-sh/nvm ~/.nvm --depth=1
|
git_clone nvm-sh/nvm ~/.nvm --depth=1
|
||||||
\. $scriptdir/files/install-nvm.sh
|
\. $scriptdir/files/install-nvm.sh
|
||||||
\. ~/.nvm/nvm.sh
|
\. ~/.nvm/nvm.sh
|
||||||
|
|||||||
13
utils.sh
13
utils.sh
@ -40,6 +40,19 @@ update_file() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
confirm_action() {
|
||||||
|
local prompt="$1"
|
||||||
|
local default_response="$2"
|
||||||
|
|
||||||
|
read -p "$prompt [$default_response]: " response
|
||||||
|
|
||||||
|
if [[ -z "$response" ]]; then
|
||||||
|
response="$default_response"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ $response =~ ^[Yy]$ ]]
|
||||||
|
}
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
check_google_access
|
check_google_access
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user