2024-07-24 00:56:26 +08:00
|
|
|
|
#!/bin/bash
|
2024-09-23 15:54:00 +08:00
|
|
|
|
echo "正在更新系统包管理器"
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare install_command
|
|
|
|
|
declare os_version="$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}')"
|
|
|
|
|
declare install_status=0
|
2024-07-27 15:12:30 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare package_manager
|
2024-07-27 15:12:30 +08:00
|
|
|
|
if [[ -f "/usr/bin/apt-get" ]];then
|
2024-11-18 23:12:52 +08:00
|
|
|
|
package_manager='apt-get'
|
|
|
|
|
install_command+="${package_manager} install -y"
|
2024-09-23 17:59:28 +08:00
|
|
|
|
apt-get update -y
|
2024-07-27 15:12:30 +08:00
|
|
|
|
elif [[ -f "/usr/bin/apt" ]];then
|
2024-11-18 23:12:52 +08:00
|
|
|
|
package_manager='apt'
|
|
|
|
|
install_command+="${package_manager} install -y"
|
2024-09-23 17:59:28 +08:00
|
|
|
|
apt update -y
|
2024-09-22 23:02:07 +08:00
|
|
|
|
elif [[ -f "/usr/bin/pacman" ]];then
|
2024-11-18 23:12:52 +08:00
|
|
|
|
package_manager='pacman'
|
|
|
|
|
install_command+="${package_manager} -Sy --noconfirm"
|
2024-09-23 17:59:28 +08:00
|
|
|
|
pacman -Syu --noconfirm
|
2024-07-27 15:12:30 +08:00
|
|
|
|
else
|
|
|
|
|
echo "暂不支持该系统一键安装常用软件"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare selected_packages
|
|
|
|
|
declare package_count
|
|
|
|
|
declare -A package_options
|
|
|
|
|
declare -a package_names
|
|
|
|
|
package_options['git']=0
|
|
|
|
|
package_options['vim']=0
|
|
|
|
|
package_options['wget']=0
|
|
|
|
|
package_options['curl']=0
|
|
|
|
|
package_options['sudo']=0
|
|
|
|
|
package_options['ssh']=0
|
|
|
|
|
package_options['zsh']=0
|
|
|
|
|
package_options['zsh-beautify']=1
|
|
|
|
|
package_options['docker']=1
|
|
|
|
|
package_options['x-cmd']=1
|
2024-09-23 14:57:22 +08:00
|
|
|
|
|
2024-09-26 16:20:14 +08:00
|
|
|
|
echo "========$(basename $0 .sh)========"
|
2024-11-18 23:12:52 +08:00
|
|
|
|
for i in "${!package_options[@]}" ; do
|
|
|
|
|
package_count=$(( package_count+1 ))
|
|
|
|
|
package_names[$package_count]=$i
|
|
|
|
|
echo "${package_count}.${i}"
|
2024-07-24 00:56:26 +08:00
|
|
|
|
done
|
2024-09-23 18:42:47 +08:00
|
|
|
|
echo "请输入需要安装的软件序号(默认安装全部)"
|
2024-11-18 23:12:52 +08:00
|
|
|
|
read -p "用 空格 隔开:" selected_packages
|
2024-07-24 00:56:26 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if [[ -z $selected_packages ]];then
|
|
|
|
|
for (( i = 1; i <= ${#package_options[@]}; i++ )); do
|
2024-09-23 18:25:54 +08:00
|
|
|
|
if [[ $i != 1 ]]; then
|
2024-11-18 23:12:52 +08:00
|
|
|
|
selected_packages="$selected_packages $i"
|
2024-09-23 18:25:54 +08:00
|
|
|
|
else
|
2024-11-18 23:12:52 +08:00
|
|
|
|
selected_packages="$i"
|
2024-09-23 18:25:54 +08:00
|
|
|
|
fi
|
|
|
|
|
done
|
2024-11-18 23:12:52 +08:00
|
|
|
|
elif ! [[ $selected_packages -ge 1 && $selected_packages -le ${#package_options[@]} || $selected_packages =~ ([1-${#package_options[@]}][\s]?)+ ]];then
|
2024-09-23 20:32:26 +08:00
|
|
|
|
echo "输入错误"
|
|
|
|
|
exit
|
2024-09-23 14:57:22 +08:00
|
|
|
|
fi
|
2024-07-24 00:56:26 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
for i in $selected_packages ; do
|
|
|
|
|
if [[ ${package_options[${package_names[$i]}]} == 0 ]]; then
|
|
|
|
|
eval "$install_command ${package_names[$i]}"
|
2024-09-23 14:57:22 +08:00
|
|
|
|
else
|
2024-11-18 23:12:52 +08:00
|
|
|
|
package_options[${package_names[$i]}]=2
|
2024-09-23 14:57:22 +08:00
|
|
|
|
fi
|
|
|
|
|
done
|
2024-07-24 00:56:26 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if [[ ${package_options['x-cmd']} == 2 ]];then
|
2024-09-23 14:57:22 +08:00
|
|
|
|
eval "$(curl https://get.x-cmd.com)"
|
|
|
|
|
fi
|
2024-07-24 00:56:26 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if [[ ${package_options['docker']} == 2 ]];then
|
2024-09-26 19:31:17 +08:00
|
|
|
|
echo "请选择docker下载镜像站"
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare -A docker_mirrors
|
|
|
|
|
docker_mirrors['官方']='https://download.docker.com'
|
|
|
|
|
docker_mirrors['清华大学']='https://mirrors.tuna.tsinghua.edu.cn/docker-ce'
|
|
|
|
|
docker_mirrors['阿里云']='https://mirrors.aliyun.com/docker-ce'
|
|
|
|
|
docker_mirrors['网易云']='https://mirrors.163.com/docker-ce'
|
2024-07-24 13:25:35 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
declare -a docker_mirror_options
|
|
|
|
|
declare docker_mirror_choice=0
|
2024-07-24 00:56:26 +08:00
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
for i in "${!docker_mirrors[@]}"; do
|
|
|
|
|
docker_mirror_choice=$((docker_mirror_choice + 1))
|
|
|
|
|
docker_mirror_options[$docker_mirror_choice]=$i
|
|
|
|
|
echo "${docker_mirror_choice}.${i}"
|
2024-07-24 00:56:26 +08:00
|
|
|
|
done
|
2024-11-18 23:12:52 +08:00
|
|
|
|
read -p "请选择Docker镜像站(默认 1):" docker_mirror_choice
|
|
|
|
|
declare docker_mirror
|
|
|
|
|
if [[ $docker_mirror_choice =~ [1-${#docker_mirrors[@]}] ]];then
|
|
|
|
|
docker_mirror_choice=${docker_mirror_options[$docker_mirror_choice]}
|
|
|
|
|
docker_mirror=${docker_mirrors[$docker_mirror_choice]}
|
2024-09-26 19:31:17 +08:00
|
|
|
|
else
|
2024-11-18 23:12:52 +08:00
|
|
|
|
docker_mirror=${docker_mirrors[${docker_mirror_options[1]}]}
|
2024-07-24 00:56:26 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if [[ ${package_manager} == 'apt' || ${package_manager} == 'apt-get' ]];then
|
|
|
|
|
${package_manager} update
|
|
|
|
|
${package_manager} install ca-certificates curl -y
|
2024-09-23 17:59:28 +08:00
|
|
|
|
install -m 0755 -d /etc/apt/keyrings
|
2024-11-18 23:12:52 +08:00
|
|
|
|
curl -fsSL "${docker_mirror}/linux/${os_version}/gpg" -o /etc/apt/keyrings/docker.asc
|
2024-09-23 17:59:28 +08:00
|
|
|
|
chmod a+r /etc/apt/keyrings/docker.asc
|
2024-07-24 00:56:26 +08:00
|
|
|
|
echo \
|
2024-11-18 23:12:52 +08:00
|
|
|
|
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] ${docker_mirror}/linux/${os_version} \
|
2024-07-24 00:56:26 +08:00
|
|
|
|
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
|
2024-09-23 17:59:28 +08:00
|
|
|
|
tee /etc/apt/sources.list.d/docker.list > /dev/null
|
2024-11-18 23:12:52 +08:00
|
|
|
|
${package_manager} update
|
|
|
|
|
${package_manager} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
|
|
|
|
|
elif [[ ${package_manager} == 'pacman' ]];then
|
2024-09-23 17:59:28 +08:00
|
|
|
|
pacman -Sy docker --noconfirm
|
|
|
|
|
systemctl start docker.service
|
|
|
|
|
systemctl enable docker.service
|
|
|
|
|
usermod -aG docker $USER
|
2024-09-23 14:57:22 +08:00
|
|
|
|
newgrp docker
|
2024-07-24 00:56:26 +08:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2024-11-18 23:12:52 +08:00
|
|
|
|
if [[ ${package_options['zsh-beautify']} == 2 ]];then
|
2024-09-21 15:13:43 +08:00
|
|
|
|
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sed 's/read -r opt//g'| sed 's/exec zsh -l//g'| sh
|
2024-09-21 14:17:49 +08:00
|
|
|
|
while [[ ! -d "$HOME/.oh-my-zsh" ]]; do
|
|
|
|
|
sleep 3
|
|
|
|
|
done
|
2024-09-12 17:21:16 +08:00
|
|
|
|
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
|
|
|
|
|
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
|
|
|
|
|
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
|
2024-09-23 17:59:28 +08:00
|
|
|
|
sed -i 's/^#\?ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc
|
|
|
|
|
sed -i 's/^#\?plugins.*/plugins=(zsh-syntax-highlighting zsh-autosuggestions command-not-found)/g' ~/.zshrc
|
2024-09-21 16:00:55 +08:00
|
|
|
|
chsh -s /bin/zsh
|
2024-09-21 15:13:43 +08:00
|
|
|
|
exec zsh -l
|
2024-09-12 17:21:16 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2024-07-24 00:56:26 +08:00
|
|
|
|
echo "软件已经全部安装成功"
|