182 lines
5.0 KiB
Bash
Executable File
182 lines
5.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
scriptdir=$(dirname $(realpath $0))
|
|
tempdir=$(mktemp -d)
|
|
|
|
if [[ $(sudo id -u) -ne 0 ]]; then
|
|
echo "Please get sudo access first."
|
|
exit 1
|
|
fi
|
|
|
|
# ============================================================
|
|
|
|
. $scriptdir/init_user.sh
|
|
|
|
# ============================================================
|
|
|
|
configure_tuna() {
|
|
[ $abroad -eq 1 ] && return
|
|
|
|
read -p "要切换 Tuna 源吗?[N]: " response
|
|
|
|
if [[ $response =~ ^[Yy]$ ]]; then
|
|
python3 $scriptdir/files/oh-my-tuna.py
|
|
# 如果 uid 不为 0 则 sudo 再跑一次
|
|
if [[ $EUID -ne 0 ]]; then
|
|
sudo python3 $scriptdir/files/oh-my-tuna.py
|
|
fi
|
|
fi
|
|
}
|
|
|
|
configure_upgrade() {
|
|
read -p "要运行 apt upgrade 吗?[N]: " response
|
|
|
|
if [[ $response =~ ^[Yy]$ ]]; then
|
|
sudo apt update
|
|
sudo apt upgrade -y
|
|
sudo apt autoremove -y
|
|
fi
|
|
}
|
|
|
|
configure_install() {
|
|
read -p "要运行 apt/pip3 install 吗?[N]: " response
|
|
|
|
if [[ $response =~ ^[Yy]$ ]]; then
|
|
sudo apt update
|
|
sudo apt install tmux git curl htop net-tools tcptraceroute tar unzip -y
|
|
sudo apt install hexyl bat neofetch fd-find fzf pigz -y
|
|
pip3 install trash-cli
|
|
|
|
sudo apt install exa -y
|
|
if [ $? -ne 0 ]; then
|
|
unzip $scriptdir/files/exa-linux-x86_64-v0.10.1.zip -d $tempdir/exa
|
|
sudo cp $tempdir/exa/bin/* /usr/local/bin/
|
|
sudo cp $tempdir/exa/man/* /usr/share/man/man1/
|
|
sudo cp $tempdir/exa/completions/exa.zsh /usr/local/share/zsh/site-functions
|
|
rm $tempdir/exa -r
|
|
fi
|
|
fi
|
|
}
|
|
|
|
configure_nano() {
|
|
[ -f ~/.nanorc ] && return
|
|
|
|
read -p "要配置 nano 吗?[Y]: " response
|
|
|
|
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
sudo apt install nano -y
|
|
cp $scriptdir/files/.nanorc ~/.nanorc
|
|
fi
|
|
}
|
|
|
|
configure_vim() {
|
|
[ -f ~/.vimrc ] && return
|
|
|
|
read -p "要配置 vim 吗?[Y]: " response
|
|
|
|
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
sudo apt install vim -y
|
|
cp $scriptdir/files/.vimrc ~/.vimrc
|
|
fi
|
|
}
|
|
|
|
configure_zsh() {
|
|
[ -f ~/.zshrc ] && return
|
|
|
|
read -p "要配置 zsh 吗?[Y]: " response
|
|
|
|
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
sudo apt install zsh -y
|
|
|
|
rm ~/.oh-my-zsh -r
|
|
git_clone ohmyzsh/ohmyzsh ~/.oh-my-zsh
|
|
RUNZSH=no ZSH=~/.oh-my-zsh $scriptdir/files/install-ohmyzsh.sh
|
|
|
|
git_clone zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
|
|
git_clone zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
|
|
git_clone paulirish/git-open ~/.oh-my-zsh/plugins/git-open --norecursive
|
|
sudo apt install autojump -y
|
|
|
|
cp $scriptdir/files/.zshrc ~/.zshrc
|
|
cp $scriptdir/files/ys-simple.zsh-theme ~/.oh-my-zsh/themes/ys-simple.zsh-theme
|
|
fi
|
|
}
|
|
|
|
configure_tmux() {
|
|
[ -f ~/.tmux.conf ] && return
|
|
|
|
read -p "要配置 tmux 吗?[Y]: " response
|
|
|
|
if [[ -z "$response" ]] || [[ $response =~ ^[Yy]$ ]]; then
|
|
sudo apt install tmux -y
|
|
|
|
rm ~/.tmux -r
|
|
git_clone tmux-plugins/tpm ~/.tmux/plugins/tpm --norecursive
|
|
git_clone tmux-plugins/tmux-sensible ~/.tmux/plugins/tmux-sensible
|
|
git_clone tmux-plugins/tmux-yank ~/.tmux/plugins/tmux-yank
|
|
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 同步
|
|
fi
|
|
}
|
|
|
|
configure_fail2ban() {
|
|
[ -f /etc/fail2ban/jail.local ] && return
|
|
|
|
read -p "要配置 fail2ban 吗?[N]: " response
|
|
|
|
if [[ $response =~ ^[Yy]$ ]]; then
|
|
sudo apt install fail2ban
|
|
sudo mkdir -p /etc/fail2ban
|
|
sudo cp $scriptdir/files/jail.local /etc/fail2ban/jail.local
|
|
sudo systemctl start fail2ban
|
|
sudo systemctl enable fail2ban
|
|
sudo fail2ban-client status sshd
|
|
fi
|
|
}
|
|
|
|
configure_iptables() {
|
|
[ -f /etc/network/if-pre-up.d/iptables-load ] && return
|
|
|
|
read -p "要配置 iptables 吗?[N]: " response
|
|
|
|
if [[ $response =~ ^[Yy]$ ]]; then
|
|
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 sh /etc/network/if-pre-up.d/iptables-load
|
|
fi
|
|
}
|
|
|
|
configure_hostname() {
|
|
read -p "要修改 hostname 吗?[N]: " response
|
|
|
|
if [[ $response =~ ^[Yy]$ ]]; then
|
|
read -p "hostname: " new_hostname
|
|
echo $new_hostname | sudo tee /etc/hostname >/dev/null
|
|
fi
|
|
}
|
|
|
|
configure_timedate() {
|
|
read -p "要修改 时区 吗?[N]: " response
|
|
|
|
if [[ $response =~ ^[Yy]$ ]]; then
|
|
sudo timedatectl set-timezone Asia/Shanghai
|
|
fi
|
|
}
|
|
|
|
# ============================================================
|
|
|
|
configure_tuna
|
|
configure_upgrade
|
|
configure_install
|
|
configure_nano
|
|
configure_vim
|
|
configure_zsh
|
|
configure_tmux
|
|
configure_fail2ban
|
|
configure_iptables
|
|
configure_hostname
|
|
configure_timedate
|