feat: 增加对 Darwin 的支持
This commit is contained in:
parent
8918ecdd54
commit
cecf62aadb
75
init_priv.sh
75
init_priv.sh
@ -27,32 +27,59 @@ configure_tuna() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_upgrade() {
|
configure_upgrade() {
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
# macOS 系统使用 brew
|
||||||
|
if confirm_action "要运行 brew upgrade 吗?" "N"; then
|
||||||
|
brew update
|
||||||
|
brew upgrade
|
||||||
|
brew cleanup
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# 其他系统使用 apt
|
||||||
if confirm_action "要运行 apt upgrade 吗?" "N"; then
|
if confirm_action "要运行 apt upgrade 吗?" "N"; then
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt upgrade -y
|
sudo apt upgrade -y
|
||||||
sudo apt autoremove -y
|
sudo apt autoremove -y
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_install_basic() {
|
configure_install_basic() {
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
[ "$1" != "noupdate" ] && brew update
|
||||||
|
brew install tmux htop
|
||||||
|
else
|
||||||
[ "$1" != "noupdate" ] && sudo apt update
|
[ "$1" != "noupdate" ] && sudo apt update
|
||||||
sudo apt install tmux git curl htop net-tools tar unzip -y
|
sudo apt install tmux git curl htop net-tools tar unzip -y
|
||||||
|
fi
|
||||||
pip3 install trash-cli
|
pip3 install trash-cli
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_install_useful() {
|
configure_install_useful() {
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
[ "$1" != "noupdate" ] && brew update
|
||||||
|
brew install hexyl bat neofetch tree cloc
|
||||||
|
else
|
||||||
[ "$1" != "noupdate" ] && sudo apt update
|
[ "$1" != "noupdate" ] && sudo apt update
|
||||||
sudo apt install hexyl bat neofetch fd-find fzf tcptraceroute tree cloc -y
|
sudo apt install hexyl bat neofetch fd-find fzf tcptraceroute tree cloc -y
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_install_new() {
|
configure_install_new() {
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
[ "$1" != "noupdate" ] && brew update
|
||||||
|
brew install pigz
|
||||||
|
else
|
||||||
[ "$1" != "noupdate" ] && sudo apt update
|
[ "$1" != "noupdate" ] && sudo apt update
|
||||||
sudo apt install pigz -y
|
sudo apt install pigz -y
|
||||||
|
fi
|
||||||
pip3 install speedtest-cli
|
pip3 install speedtest-cli
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_install_eza() {
|
configure_install_eza() {
|
||||||
if [[ $(uname -m) != "x86_64" ]]; then
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
brew install eza
|
||||||
|
elif [[ $(uname -m) != "x86_64" ]]; then
|
||||||
echo "eza is not supported on $(uname -m)."
|
echo "eza is not supported on $(uname -m)."
|
||||||
elif ! command_exists eza; then
|
elif ! command_exists eza; then
|
||||||
unzip $scriptdir/files/eza_x86_64-unknown-linux-musl.zip -d $tempdir/eza
|
unzip $scriptdir/files/eza_x86_64-unknown-linux-musl.zip -d $tempdir/eza
|
||||||
@ -62,20 +89,31 @@ configure_install_eza() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_install() {
|
configure_install() {
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
# macOS 系统使用 brew
|
||||||
|
if confirm_action "要运行 brew/pip3 install 吗?" "N"; then
|
||||||
|
brew update
|
||||||
|
else
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
else
|
||||||
if confirm_action "要运行 apt/pip3 install 吗?" "N"; then
|
if confirm_action "要运行 apt/pip3 install 吗?" "N"; then
|
||||||
sudo apt update
|
sudo apt update
|
||||||
|
else
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
configure_install_basic noupdate
|
configure_install_basic noupdate
|
||||||
configure_install_useful noupdate
|
configure_install_useful noupdate
|
||||||
configure_install_new noupdate
|
configure_install_new noupdate
|
||||||
configure_install_eza noupdate
|
configure_install_eza noupdate
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_nano() {
|
configure_nano() {
|
||||||
[ -f ~/.nanorc ] && return
|
[ -f ~/.nanorc ] && return
|
||||||
|
|
||||||
if confirm_action "要配置 nano 吗?" "Y"; then
|
if confirm_action "要配置 nano 吗?" "Y"; then
|
||||||
sudo apt install nano -y
|
pkg_install nano
|
||||||
cp $scriptdir/files/.nanorc ~/.nanorc
|
cp $scriptdir/files/.nanorc ~/.nanorc
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -84,16 +122,31 @@ configure_vim() {
|
|||||||
[ -f ~/.vimrc ] && return
|
[ -f ~/.vimrc ] && return
|
||||||
|
|
||||||
if confirm_action "要配置 vim 吗?" "Y"; then
|
if confirm_action "要配置 vim 吗?" "Y"; then
|
||||||
sudo apt install vim -y
|
pkg_install vim
|
||||||
cp $scriptdir/files/.vimrc ~/.vimrc
|
cp $scriptdir/files/.vimrc ~/.vimrc
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replace_zsh_source() {
|
||||||
|
local zshrc="$HOME/.zshrc"
|
||||||
|
local old_source="\$ZSH/oh-my-zsh.sh"
|
||||||
|
local new_source="~/.oh-my-zsh/custom/00-init.zsh"
|
||||||
|
|
||||||
|
# 使用 sed 进行替换,注意 macOS 和 Linux 的 sed 语法稍有不同
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
# macOS 使用的是 BSD sed,需要给 -i 选项传递一个空字符串作为扩展名
|
||||||
|
sed -i '' "s|${old_source}|${new_source}|g" "$zshrc"
|
||||||
|
else
|
||||||
|
# Linux 使用的是 GNU sed
|
||||||
|
sed -i "s|${old_source}|${new_source}|g" "$zshrc"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
configure_zsh() {
|
configure_zsh() {
|
||||||
[ -f ~/.zshrc ] && return
|
[ -f ~/.zshrc ] && return
|
||||||
|
|
||||||
if confirm_action "要配置 zsh 吗?" "Y"; then
|
if confirm_action "要配置 zsh 吗?" "Y"; then
|
||||||
sudo apt install zsh -y
|
pkg_install zsh
|
||||||
|
|
||||||
rm ~/.oh-my-zsh -r
|
rm ~/.oh-my-zsh -r
|
||||||
git_clone ohmyzsh/ohmyzsh ~/.oh-my-zsh
|
git_clone ohmyzsh/ohmyzsh ~/.oh-my-zsh
|
||||||
@ -102,13 +155,11 @@ configure_zsh() {
|
|||||||
git_clone zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
|
git_clone zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
|
||||||
git_clone zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
|
git_clone zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
|
||||||
git_clone paulirish/git-open ~/.oh-my-zsh/custom/plugins/git-open --norecursive
|
git_clone paulirish/git-open ~/.oh-my-zsh/custom/plugins/git-open --norecursive
|
||||||
sudo apt install autojump -y
|
pkg_install autojump
|
||||||
|
|
||||||
if ! grep -Fxq "source ~/.oh-my-zsh/custom/00-init.zsh" ~/.zshrc; then
|
if ! grep -Fxq "source ~/.oh-my-zsh/custom/00-init.zsh" ~/.zshrc; then
|
||||||
local line_number=$(grep -n "source \$ZSH/oh-my-zsh.sh" ~/.zshrc | cut -d : -f 1)
|
replace_zsh_source
|
||||||
sed -i "${line_number}i source ~/.oh-my-zsh/custom/00-init.zsh\n" ~/.zshrc
|
|
||||||
fi
|
fi
|
||||||
echo -e "\nsource ~/.zsh_user" | sudo tee -a ~/.zshrc >/dev/null
|
|
||||||
|
|
||||||
cp $scriptdir/files/zsh/.zsh_user ~/.zsh_user
|
cp $scriptdir/files/zsh/.zsh_user ~/.zsh_user
|
||||||
cp $scriptdir/files/zsh/00-init.zsh ~/.oh-my-zsh/custom/
|
cp $scriptdir/files/zsh/00-init.zsh ~/.oh-my-zsh/custom/
|
||||||
@ -138,6 +189,7 @@ configure_tmux() {
|
|||||||
git_clone seebi/tmux-colors-solarized ~/.tmux/plugins/tmux-colors-solarized
|
git_clone seebi/tmux-colors-solarized ~/.tmux/plugins/tmux-colors-solarized
|
||||||
|
|
||||||
cp $scriptdir/files/.tmux.conf ~/.tmux.conf
|
cp $scriptdir/files/.tmux.conf ~/.tmux.conf
|
||||||
|
[ "$(uname)" = "Darwin" ] && return
|
||||||
sudo apt install xsel -y # 能够让 tmux 剪切板与 terminal 同步
|
sudo apt install xsel -y # 能够让 tmux 剪切板与 terminal 同步
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -198,6 +250,7 @@ configure_nginx() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_fail2ban() {
|
configure_fail2ban() {
|
||||||
|
[ "$(uname)" = "Darwin" ] && return
|
||||||
[ -f /etc/fail2ban/jail.local ] && return
|
[ -f /etc/fail2ban/jail.local ] && return
|
||||||
|
|
||||||
if confirm_action "要配置 fail2ban 吗?" "N"; then
|
if confirm_action "要配置 fail2ban 吗?" "N"; then
|
||||||
@ -228,6 +281,7 @@ configure_hostname() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_timedate() {
|
configure_timedate() {
|
||||||
|
[ "$(uname)" = "Darwin" ] && return
|
||||||
[[ $(timedatectl | grep "Time zone" | awk '{print $3}') == "Asia/Shanghai" ]] && return
|
[[ $(timedatectl | grep "Time zone" | awk '{print $3}') == "Asia/Shanghai" ]] && return
|
||||||
|
|
||||||
if confirm_action "要修改 时区 吗?" "N"; then
|
if confirm_action "要修改 时区 吗?" "N"; then
|
||||||
@ -236,6 +290,7 @@ configure_timedate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_bootinfo() {
|
configure_bootinfo() {
|
||||||
|
[ "$(uname)" = "Darwin" ] && return
|
||||||
[ -d /etc/update-motd.d/disable ] && return
|
[ -d /etc/update-motd.d/disable ] && return
|
||||||
|
|
||||||
if confirm_action "要修改 启动信息 吗?" "Y"; then
|
if confirm_action "要修改 启动信息 吗?" "Y"; then
|
||||||
@ -251,6 +306,7 @@ configure_bootinfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_oomkiller() {
|
configure_oomkiller() {
|
||||||
|
[ "$(uname)" = "Darwin" ] && return
|
||||||
[ -f /etc/default/earlyoom ] && return
|
[ -f /etc/default/earlyoom ] && return
|
||||||
|
|
||||||
if confirm_action "要启用 earlyoom 吗?" "Y"; then
|
if confirm_action "要启用 earlyoom 吗?" "Y"; then
|
||||||
@ -261,6 +317,7 @@ configure_oomkiller() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configure_proxychains() {
|
configure_proxychains() {
|
||||||
|
[ "$(uname)" = "Darwin" ] && return
|
||||||
[ -f /etc/proxychains4.conf ] && return
|
[ -f /etc/proxychains4.conf ] && return
|
||||||
|
|
||||||
if confirm_action "要配置 proxychains 吗?" "N"; then
|
if confirm_action "要配置 proxychains 吗?" "N"; then
|
||||||
|
|||||||
10
utils.sh
10
utils.sh
@ -47,6 +47,16 @@ command_exists() {
|
|||||||
command -v "$@" >/dev/null 2>&1;
|
command -v "$@" >/dev/null 2>&1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pkg_install() {
|
||||||
|
# 如果已经安装了,就直接返回(只检查第一个)
|
||||||
|
command_exists "$1" && return
|
||||||
|
if [ "$(uname)" = "Darwin" ]; then
|
||||||
|
brew install "$@"
|
||||||
|
else
|
||||||
|
sudo apt install "$@" -y
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
check_google_access
|
check_google_access
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user