linuxtool/Menus/Software.sh

143 lines
4.6 KiB
Bash
Raw Normal View History

#!/bin/bash
2024-09-23 15:54:00 +08:00
echo "正在更新系统包管理器"
declare install_str
declare version="$(cat /etc/os-release | grep "^ID" | awk -F '=' '{print $2}')"
2024-09-22 23:02:07 +08:00
declare status=0
declare pkg
if [[ -f "/usr/bin/apt-get" ]];then
2024-09-21 18:32:46 +08:00
pkg='apt-get'
install_str+="${pkg} install -y"
2024-09-23 17:59:28 +08:00
apt-get update -y
elif [[ -f "/usr/bin/apt" ]];then
2024-09-21 18:32:46 +08:00
pkg='apt'
install_str+="${pkg} 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
pkg='pacman'
install_str+="${pkg} -Sy --noconfirm"
2024-09-23 17:59:28 +08:00
pacman -Syu --noconfirm
else
echo "暂不支持该系统一键安装常用软件"
exit
fi
declare pick
2024-09-23 14:57:22 +08:00
declare soft_number
declare -A soft_dick
declare -a soft_array
2024-09-23 14:57:22 +08:00
soft_dick['git']=0
soft_dick['vim']=0
soft_dick['wget']=0
soft_dick['curl']=0
soft_dick['sudo']=0
2024-09-23 14:57:22 +08:00
soft_dick['ssh']=0
soft_dick['zsh']=0
2024-09-23 18:36:20 +08:00
soft_dick['zsh-beautify']=1
2024-09-23 14:57:22 +08:00
soft_dick['docker']=1
soft_dick['x-cmd']=1
echo "======一键安装常用软件======"
2024-09-23 14:57:22 +08:00
for i in "${!soft_dick[@]}" ; do
soft_number=$(( soft_number+1 ))
soft_array[$soft_number]=$i
echo "${soft_number}.${i}"
done
2024-09-23 18:42:47 +08:00
echo "请输入需要安装的软件序号(默认安装全部)"
read -p "用 空格 隔开:" pick
2024-09-23 19:41:47 +08:00
2024-09-23 15:03:35 +08:00
if [[ -z $pick ]];then
for (( i = 1; i <= ${#soft_dick[@]}; i++ )); do
if [[ $i != 1 ]]; then
pick="$pick $i"
else
2024-09-23 18:36:20 +08:00
pick="$i"
fi
done
2024-09-23 20:17:45 +08:00
else
for i in $pick ; do
2024-09-23 20:18:54 +08:00
if [[ ! $i =~ [1-${#soft_dick[@]}] ]]; then
2024-09-23 20:17:45 +08:00
echo "输入错误"
exit
fi
done
2024-09-23 14:57:22 +08:00
fi
2024-09-23 14:57:22 +08:00
for i in $pick ; do
if [[ ${soft_dick[${soft_array[$i]}]} == 0 ]]; then
2024-09-23 18:37:36 +08:00
eval "$install_str ${soft_array[$i]}"
2024-09-23 14:57:22 +08:00
else
soft_dick[${soft_array[$i]}]=2
fi
done
2024-09-23 14:57:22 +08:00
if [[ ${soft_dick['x-cmd']} == 2 ]];then
eval "$(curl https://get.x-cmd.com)"
fi
2024-09-23 14:57:22 +08:00
if [[ ${soft_dick['docker']} == 2 ]];then
declare -A docker_imgs
docker_imgs['官方']='https://download.docker.com'
docker_imgs['中国科技大学(默认)']='https://mirrors.ustc.edu.cn/docker-ce'
docker_imgs['清华大学']='https://mirrors.tuna.tsinghua.edu.cn/docker-ce'
docker_imgs['阿里云']='https://mirrors.aliyun.com/docker-ce'
2024-07-24 13:25:35 +08:00
docker_imgs['网易云']='https://mirrors.163.com/docker-ce'
declare -a docker_img_number
declare docker_img_number_pick=0
for i in "${!docker_imgs[@]}"; do
docker_img_number_pick=$((docker_img_number_pick + 1))
docker_img_number[$docker_img_number_pick]=$i
echo "${docker_img_number_pick}.${i}"
done
read -p "请输入需要选择的镜像站:" docker_img_number_pick
declare docker_img
if [[ ! $docker_img_number_pick =~ [1-${#docker_imgs[@]}] ]];then
docker_img='https://mirrors.sustc.edu.cn/docker-ce'
else
docker_img_number_pick=${docker_img_number[$docker_img_number_pick]}
docker_img=${docker_imgs[$docker_img_number_pick]}
fi
2024-09-21 18:41:26 +08:00
if [[ ${pkg} == 'apt' || ${pkg} == 'apt-get' ]];then
2024-09-23 17:59:28 +08:00
${pkg} update
${pkg} install ca-certificates curl -y
install -m 0755 -d /etc/apt/keyrings
curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] ${docker_img}/linux/${version} \
$(. /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
${pkg} update
${pkg} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
2024-09-23 14:57:22 +08:00
elif [[ ${pkg} == '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
fi
fi
2024-09-23 14:57:22 +08:00
2024-09-23 18:36:20 +08:00
if [[ ${soft_dick['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
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
chsh -s /bin/zsh
2024-09-21 15:13:43 +08:00
exec zsh -l
2024-09-12 17:21:16 +08:00
fi
echo "软件已经全部安装成功"