写好了换源,登录,一键安装常用应用
This commit is contained in:
parent
9f6ff02ade
commit
4d6c726209
@ -2,7 +2,7 @@
|
||||
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "docker未安装"
|
||||
bash Run.sh
|
||||
exit
|
||||
fi
|
||||
|
||||
declare pick_array
|
||||
@ -10,7 +10,6 @@ declare pick_number=6
|
||||
declare pick
|
||||
|
||||
echo "========Docker========"
|
||||
echo "0.返回主菜单"
|
||||
echo "1.换源"
|
||||
echo "-----一键搭建软件-----"
|
||||
cd "Config/Docker"
|
||||
@ -21,18 +20,16 @@ for i in *;do
|
||||
done
|
||||
cd - >> /dev/null
|
||||
echo "-----一键搭建软件-----"
|
||||
echo "任意输入返回主菜单"
|
||||
echo "========Docker========"
|
||||
read -p "请输入要使用的功能:" pick
|
||||
|
||||
|
||||
if [[ "$pick" == 0 ]]; then
|
||||
clear
|
||||
bash Run.sh
|
||||
elif [[ "${pick_number}" -gt 0 && "${pick}" -le "$((${#pick_array[*]}+${pick_number}))" ]];then
|
||||
if [[ "${pick_number}" -gt 0 && "${pick}" -le "$((${#pick_array[*]}+${pick_number}))" ]];then
|
||||
clear
|
||||
bash "Config/Docker/${pick_array[${pick}]}.sh"
|
||||
else
|
||||
exit
|
||||
clear
|
||||
fi
|
||||
|
||||
|
||||
|
182
Menus/Login.sh
182
Menus/Login.sh
@ -1,10 +1,182 @@
|
||||
#!bin/bash
|
||||
declare pick
|
||||
echo "========Login========"
|
||||
echo "0.返回主菜单"
|
||||
echo "1.修改root密码"
|
||||
echo "2.新建用户"
|
||||
echo "3.安装密钥"
|
||||
echo "2.ssh安装密钥"
|
||||
echo "3.新建用户"
|
||||
echo "4.管理ssh登录方式"
|
||||
echo "5.更换ssh端口"
|
||||
echo "6.ssh二次验证"
|
||||
echo "========Login========"
|
||||
echo "任意输入返回主菜单"
|
||||
echo "========Login========"
|
||||
read -p "请输入要使用的功能:" pick
|
||||
|
||||
|
||||
case $pick in
|
||||
1)
|
||||
declare password
|
||||
read -p "请输入root密码:" password
|
||||
echo "root:$password" |sudo chpasswd
|
||||
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
|
||||
sudo systemctl restart sshd.service
|
||||
echo "修改成功当前root密码为:$password"
|
||||
;;
|
||||
2)
|
||||
declare key
|
||||
echo "请输入公钥或文件路径:"
|
||||
echo "默认:$HOME/.ssh/id_rsa.pub"
|
||||
read -p "回车默认:" key
|
||||
|
||||
if [[ -z $key ]];then
|
||||
key="$HOME/.ssh/id_rsa.pub"
|
||||
fi
|
||||
|
||||
if [[ -f $key ]];then
|
||||
key=$(cat "$key")
|
||||
fi
|
||||
if [[ ! $key =~ ^ssh-(rsa|ecdsa-sha2-nistp[0-9]+|ed25519|dss) ]];then
|
||||
echo "公钥不合法"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$HOME/.ssh"
|
||||
echo "$key" > "$HOME/.ssh/authorized_keys"
|
||||
|
||||
chmod 600 "$HOME/.ssh/authorized_keys"
|
||||
chmod 700 "$HOME/.ssh"
|
||||
|
||||
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
|
||||
declare pick2
|
||||
echo "是否关闭密码登录:"
|
||||
read -p "输入 n 取消关闭:" pick2
|
||||
|
||||
if [[ ! $pick2 =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
|
||||
fi
|
||||
|
||||
|
||||
sudo systemctl restart sshd.service
|
||||
|
||||
echo "密钥安装完成"
|
||||
;;
|
||||
3)
|
||||
declare user_name
|
||||
read -p "请输入你想创建的用户名:" user_name
|
||||
|
||||
if id "$user_name" &>/dev/null; then
|
||||
echo "用户 $user_name 已存在。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
useradd -m -s /bin/bash "$user_name"
|
||||
|
||||
if grep -q "^$user_name " /etc/sudoers;then
|
||||
sudo sed -i "s/^#\?$user_name.*/lsy ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers
|
||||
else
|
||||
sudo echo "lsy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
fi
|
||||
|
||||
|
||||
declare pick
|
||||
echo "用户登录方式"
|
||||
echo "y.密码登录"
|
||||
echo "n.使用root用户公钥"
|
||||
read -p "默认y,请输入:" pick
|
||||
if [[ ! $pick =~ [Nn] ]];then
|
||||
declare password
|
||||
read -p "请输入密码:" password
|
||||
echo "$user_name:$password" |sudo chpasswd
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
|
||||
echo "创建成功"
|
||||
echo "账号:$user_name"
|
||||
echo "密码:$password"
|
||||
else
|
||||
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
su "$user_name" -c "mkdir -p '/home/$user_name/.ssh'"
|
||||
sudo cp "/root/.ssh/authorized_keys" "/home/$user_name/.ssh/authorized_keys"
|
||||
sudo chown lsy:lsy "/home/$user_name/.ssh/authorized_keys"
|
||||
su "$user_name" -c "chmod 600 '/home/$user_name/.ssh/authorized_keys'"
|
||||
su "$user_name" -c "chmod 700 '/home/$user_name/.ssh/'"
|
||||
|
||||
echo "创建成功"
|
||||
echo "账号:$user_name"
|
||||
echo "密钥登录"
|
||||
fi
|
||||
|
||||
declare pick2
|
||||
echo "是否关闭root登录"
|
||||
read -p "输入 n 取消关闭:" pick2
|
||||
|
||||
if [[ ! $pick2 =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录已关闭"
|
||||
fi
|
||||
|
||||
sudo systemctl restart sshd.service
|
||||
|
||||
;;
|
||||
4)
|
||||
declare pick_root
|
||||
declare pick2_key
|
||||
declare pick2_password
|
||||
echo "是否关闭root登录"
|
||||
read -p "输入 n 关闭:" pick_root
|
||||
echo "是否关闭密码登录"
|
||||
read -p "输入 n 关闭:" pick2_password
|
||||
echo "是否关闭密钥登录"
|
||||
read -p "输入 n 关闭:" pick2_key
|
||||
|
||||
if [[ ! $pick_root =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录:开启"
|
||||
else
|
||||
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
|
||||
echo "root用户登录:关闭"
|
||||
fi
|
||||
|
||||
if [[ ! $pick2_password =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
|
||||
echo "密码登录:开启"
|
||||
else
|
||||
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
|
||||
echo "密码登录:关闭"
|
||||
fi
|
||||
|
||||
if [[ ! $pick2_key =~ [Nn] ]];then
|
||||
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
|
||||
echo "密钥登录:开启"
|
||||
else
|
||||
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config
|
||||
echo "密钥登录:关闭"
|
||||
fi
|
||||
|
||||
sudo systemctl restart sshd.service
|
||||
;;
|
||||
5)
|
||||
read -p "请输入需要修改的端口号(默认22): " port_number
|
||||
|
||||
if [[ -z $port_number ]];then
|
||||
port_number=22
|
||||
fi
|
||||
|
||||
if ! [[ $port_number =~ ^[0-9]+$ ]] || ! ((port_number > 0 && port_number < 65535)); then
|
||||
echo "端口不合法"
|
||||
exit
|
||||
fi
|
||||
|
||||
if sudo lsof -i :$port_number -t >/dev/null; then
|
||||
echo "$port_number 端口已被占用"
|
||||
exit
|
||||
fi
|
||||
|
||||
sudo sed -i "s/^#\?Port.*/Port $port_number/g" /etc/ssh/sshd_config
|
||||
|
||||
sudo systemctl restart sshd.service
|
||||
|
||||
echo "端口已经修改为$port_number,记得防火墙放行"
|
||||
;;
|
||||
*)
|
||||
clear
|
||||
esac
|
||||
|
||||
|
109
Menus/Software.sh
Normal file
109
Menus/Software.sh
Normal file
@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare install_str
|
||||
declare version=$(cat /etc/os-release | grep -w 'ID' | awk -F '=' '{print $2}')
|
||||
case "$version" in
|
||||
'debian')
|
||||
install_str='apt-get install'
|
||||
|
||||
;;
|
||||
*)
|
||||
echo "暂不支持该系统一键安装常用软件"
|
||||
exit
|
||||
esac
|
||||
|
||||
declare pick
|
||||
declare -a soft_array
|
||||
soft_array[0]='git'
|
||||
soft_array[1]='vim'
|
||||
soft_array[2]='wget'
|
||||
soft_array[3]='curl'
|
||||
soft_array[4]='git'
|
||||
soft_array[5]='ssh'
|
||||
soft_array[6]='zsh'
|
||||
|
||||
|
||||
echo "======一键安装常用软件======"
|
||||
for i in ${soft_array[@]}
|
||||
do
|
||||
read -p "是否安装${i},输入 n 取消安装:" pick
|
||||
if [[ ! $pick =~ [Nn] ]];then
|
||||
install_str+=" ${i}"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
declare pick_x
|
||||
read -p "是否安装x-cmd,输入 n 取消安装:" pick_x
|
||||
|
||||
declare pick_zsh
|
||||
read -p "是否一键美化zsh,输入 n 取消:" pick_zsh
|
||||
|
||||
declare pick_docker
|
||||
read -p "是否安装docker,输入 n 取消:" pick_docker
|
||||
|
||||
if [[ ! $pick_docker =~ [Nn] ]];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'
|
||||
|
||||
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}.${docker_img_number[$docker_img_number_pick]}"
|
||||
done
|
||||
read -p "请输入需要选择的镜像站:" docker_img_number_pick
|
||||
declare docker_img
|
||||
if [[ ! $docker_img_number_pick =~ [1-${#docker_imgs[@]}] ]];then
|
||||
docker_img='https://mirrors.ustc.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
|
||||
fi
|
||||
|
||||
|
||||
if [[ ! $pick_x =~ [Nn] ]];then
|
||||
|
||||
eval "$(curl https://get.x-cmd.com)"
|
||||
fi
|
||||
|
||||
|
||||
eval "$install_str -y"
|
||||
if [[ ! $pick_x =~ [Nn] ]];then
|
||||
eval "$(curl https://get.x-cmd.com)"
|
||||
fi
|
||||
|
||||
if [[ ! $pick_zsh =~ [Nn] ]];then
|
||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
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
|
||||
sudo sed -i 's/^#\?ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc
|
||||
sudo sed -i 's/^#\?plugins.*/plugins=(zsh-syntax-highlighting zsh-autosuggestions command-not-found)/g' ~/.zshrc
|
||||
zsh
|
||||
fi
|
||||
|
||||
|
||||
if [[ ! $pick_docker =~ [Nn] ]];then
|
||||
if [[ $version == 'debian' ]];then
|
||||
sudo apt-get update
|
||||
sudo apt-get install ca-certificates curl -y
|
||||
sudo install -m 0755 -d /etc/apt/keyrings
|
||||
sudo curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc
|
||||
sudo 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" | \
|
||||
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
sudo apt-get update
|
||||
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "软件已经全部安装成功"
|
47
Menus/Sources.sh
Normal file
47
Menus/Sources.sh
Normal file
@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare version=$(cat /etc/os-release | grep VERSION_CODENAME | awk -F '=' '{print $2}')
|
||||
|
||||
case "$version" in
|
||||
'bookworm')
|
||||
;;
|
||||
*)
|
||||
echo "暂不支持该系统一键换源"
|
||||
exit
|
||||
esac
|
||||
|
||||
|
||||
sources_array[1]='http://mirrors.ustc.edu.cn'
|
||||
sources_array[2]='https://mirrors.tuna.tsinghua.edu.cn'
|
||||
sources_array[3]='https://mirrors.aliyun.com'
|
||||
|
||||
|
||||
declare pick
|
||||
echo "========Sources========"
|
||||
echo "1.中国科技技术大学"
|
||||
echo "2.清华大学"
|
||||
echo "3.阿里云"
|
||||
echo "========Sources========"
|
||||
read -p "请输入(默认1):" pick
|
||||
|
||||
if [[ -z $pick ]];then
|
||||
pick=1
|
||||
fi
|
||||
|
||||
echo $pick
|
||||
|
||||
if ! [[ ${pick} =~ [123] ]];then
|
||||
echo "输入错误"
|
||||
exit
|
||||
fi
|
||||
|
||||
case "$version" in
|
||||
'bookworm')
|
||||
{
|
||||
echo "deb ${sources_array[$pick]}/debian/ bookworm main contrib non-free non-free-firmware"
|
||||
echo "deb ${sources_array[$pick]}/debian/ bookworm-updates main contrib non-free non-free-firmware"
|
||||
echo "deb ${sources_array[$pick]}/debian/ bookworm-backports main contrib non-free non-free-firmware"
|
||||
} > /etc/apt/sources.list
|
||||
sudo apt-get update
|
||||
;;
|
||||
esac
|
12
Run.sh
12
Run.sh
@ -6,9 +6,13 @@ fi
|
||||
|
||||
|
||||
declare -a pick_array
|
||||
declare pick_number=0
|
||||
|
||||
declare pick_number
|
||||
declare pick
|
||||
|
||||
while true
|
||||
do
|
||||
|
||||
pick_number=0
|
||||
echo "======Linux工具箱======"
|
||||
cd Menus
|
||||
for i in *
|
||||
@ -25,4 +29,6 @@ if [[ "${pick}" -gt 0 && "${pick}" -le "${#pick_array[*]}" ]];then
|
||||
bash Menus/${pick_array[$pick]}.sh
|
||||
else
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
done
|
Loading…
Reference in New Issue
Block a user