更新了文件检测方式,新增更换系统语言

This commit is contained in:
lsy 2024-07-27 15:12:30 +08:00
parent 0288eed8fb
commit 2cec79d034
6 changed files with 218 additions and 174 deletions

View File

@ -19,7 +19,7 @@ if [[ -z ${web_path} ]];then
fi fi
read -p "是否备份到本地,默认 关闭 ,输入 y 开启:" local_pick read -p "是否备份到本地,默认 关闭 ,输入 y 开启:" local_pick
read -p "是否备份到百度网盘,默认 开启 ,输入 n 关闭:" baidu_pick read -p "是否备份到百度网盘,默认 开启 ,输入 n 关闭:" baidu_pick
read -p "是否备份到阿里云盘 默认 开启 输入 n 关闭" aliyun_pick read -p "是否备份到阿里云盘 默认 开启 输入 n 关闭" aliyun_pick
if [[ ! $local_pick =~ [Yy] && $baidu_pick =~ [Nn] && $aliyun_pick =~ [Nn] ]];then if [[ ! $local_pick =~ [Yy] && $baidu_pick =~ [Nn] && $aliyun_pick =~ [Nn] ]];then
echo "没有可备份的选项" echo "没有可备份的选项"
@ -39,7 +39,16 @@ if [[ $local_pick =~ Yy ]];then
fi fi
if [[ ! $baidu_pick =~ [Nn] ]];then if [[ ! $baidu_pick =~ [Nn] ]];then
sudo apt-get install python3-venv -y if ! command -v python3 -m venv &> /dev/null ; then
if [[ -f "/usr/bin/apt-get" ]];then
sudo apt-get install python3-venv -y
elif [[ -f "/usr/bin/apt" ]];then
sudo apt-get install python3-venv -y
else
echo "无法自动安装 python3-venv 请手动安装"
exit
fi
fi
python3 -m venv "${path}/venv" python3 -m venv "${path}/venv"
source "${path}/venv/bin/activate" source "${path}/venv/bin/activate"
pip install bypy pip install bypy
@ -54,11 +63,9 @@ fi
if [[ ! $aliyun_pick =~ [Nn] ]];then if [[ ! $aliyun_pick =~ [Nn] ]];then
if [[ ! -d "${path}/aliyunpan" ]];then if [[ ! -d "${path}/aliyunpan" ]];then
wget -P "${path}" https://github.com/tickstep/aliyunpan/releases/download/v0.3.2/aliyunpan-v0.3.2-linux-amd64.zip -O "${path}/aliyunpan.zip" wget -P "${path}" https://github.com/tickstep/aliyunpan/releases/download/v0.3.2/aliyunpan-v0.3.2-linux-amd64.zip -O "${path}/aliyunpan.zip"
unzip aliyunpan.zip
unzip "${path}/aliyunpan.zip" -d "${path}" unzip "${path}/aliyunpan.zip" -d "${path}"
rm "${path}/aliyunpan.zip" rm "${path}/aliyunpan.zip"
declare tmp_file=$( ls "${path}" | grep "aliyunpan" ) mv "${path}/$(ls "${path}" | grep "aliyunpan")" "${path}/aliyunpan"
mv "${path}/${tmp_file}" "${path}/aliyunpan"
${path}/aliyunpan/aliyunpan login ${path}/aliyunpan/aliyunpan login
else else
echo "检测到阿里云盘已经存在,请确认是否登录" echo "检测到阿里云盘已经存在,请确认是否登录"

View File

@ -1,4 +1,3 @@
declare version=$(cat /etc/os-release | grep '^ID' | awk -F '=' '{print $2}')
declare path=$1 declare path=$1
declare cron=$2 declare cron=$2
@ -6,20 +5,19 @@ if [[ -f "${path}/update.sh" ]];then
echo "该路径文件已经存在" echo "该路径文件已经存在"
fi fi
case "$version" in echo '#!/bin/bash' > "${path}/update.sh"
'debian')
cat > "${path}/update.sh" << EOF if [[ -f "/usr/bin/apt" ]];then
#!/bin/bash echo 'sudo apt update' >> "${path}/update.sh"
sudo apt update echo 'sudo apt-get dist-upgrade' >> "${path}/update.sh"
sudo apt-get update elif [[ -f "/usr/bin/apt-get" ]];then
sudo apt dist-upgrade echo 'sudo apt-get update' >> "${path}/update.sh"
sudo apt-get dist-upgrade echo 'sudo apt dist-upgrade' >> "${path}/update.sh"
EOF else
;; rm "${path}/update.sh"
*) echo "暂不支持该系统配置自动更新软件"
echo "暂不支持该系统配置自动更新软件" exit
exit fi
esac
chmod +x "${path}/update.sh" chmod +x "${path}/update.sh"

View File

@ -13,170 +13,170 @@ read -p "请输入要使用的功能:" pick
case $pick in case $pick in
1) 1)
declare password declare password
read -p "请输入root密码" password read -p "请输入root密码" password
echo "root:$password" |sudo chpasswd echo "root:$password" |sudo chpasswd
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config 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 sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sudo systemctl restart sshd.service sudo systemctl restart sshd.service
echo "修改成功当前root密码为$password" echo "修改成功当前root密码为$password"
;; ;;
2) 2)
declare key declare key
echo "请输入公钥或文件路径:" echo "请输入公钥或文件路径:"
echo "默认:$HOME/.ssh/id_rsa.pub" echo "默认:$HOME/.ssh/id_rsa.pub"
read -p "回车默认:" key read -p "回车默认:" key
if [[ -z $key ]];then if [[ -z $key ]];then
key="$HOME/.ssh/id_rsa.pub" key="$HOME/.ssh/id_rsa.pub"
fi fi
if [[ -f $key ]];then if [[ -f $key ]];then
key=$(cat "$key") key=$(cat "$key")
fi fi
if [[ ! $key =~ ^ssh-(rsa|ecdsa-sha2-nistp[0-9]+|ed25519|dss) ]];then if [[ ! $key =~ ^ssh-(rsa|ecdsa-sha2-nistp[0-9]+|ed25519|dss) ]];then
echo "公钥不合法" echo "公钥不合法"
exit 1 exit 1
fi fi
mkdir -p "$HOME/.ssh" mkdir -p "$HOME/.ssh"
echo "$key" > "$HOME/.ssh/authorized_keys" echo "$key" > "$HOME/.ssh/authorized_keys"
chmod 600 "$HOME/.ssh/authorized_keys" chmod 600 "$HOME/.ssh/authorized_keys"
chmod 700 "$HOME/.ssh" chmod 700 "$HOME/.ssh"
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
declare pick2 declare pick2
echo "是否关闭密码登录:" echo "是否关闭密码登录:"
read -p "输入 n 取消关闭:" pick2 read -p "输入 n 取消关闭:" pick2
if [[ ! $pick2 =~ [Nn] ]];then if [[ ! $pick2 =~ [Nn] ]];then
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
fi fi
sudo systemctl restart sshd.service sudo systemctl restart sshd.service
echo "密钥安装完成" echo "密钥安装完成"
;; ;;
3) 3)
declare user_name declare user_name
read -p "请输入你想创建的用户名:" user_name read -p "请输入你想创建的用户名:" user_name
if id "$user_name" &>/dev/null; then if id "$user_name" &>/dev/null; then
echo "用户 $user_name 已存在。" echo "用户 $user_name 已存在。"
exit 1 exit 1
fi fi
useradd -m -s /bin/bash "$user_name" useradd -m -s /bin/bash "$user_name"
if grep -q "^$user_name " /etc/sudoers;then if grep -q "^$user_name " /etc/sudoers;then
sudo sed -i "s/^#\?$user_name.*/lsy ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers sudo sed -i "s/^#\?$user_name.*/lsy ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers
else else
sudo echo "lsy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers sudo echo "lsy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
fi fi
declare pick declare pick
echo "用户登录方式" echo "用户登录方式"
echo "y.密码登录" echo "y.密码登录"
echo "n.使用root用户公钥" echo "n.使用root用户公钥"
read -p "默认y请输入" pick read -p "默认y请输入" pick
if [[ ! $pick =~ [Nn] ]];then if [[ ! $pick =~ [Nn] ]];then
declare password declare password
read -p "请输入密码:" password read -p "请输入密码:" password
echo "$user_name:$password" |sudo chpasswd echo "$user_name:$password" |sudo chpasswd
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config; sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
echo "创建成功" echo "创建成功"
echo "账号:$user_name" echo "账号:$user_name"
echo "密码:$password" echo "密码:$password"
else else
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
su "$user_name" -c "mkdir -p '/home/$user_name/.ssh'" su "$user_name" -c "mkdir -p '/home/$user_name/.ssh'"
sudo cp "/root/.ssh/authorized_keys" "/home/$user_name/.ssh/authorized_keys" sudo cp "/root/.ssh/authorized_keys" "/home/$user_name/.ssh/authorized_keys"
sudo chown lsy:lsy "/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 600 '/home/$user_name/.ssh/authorized_keys'"
su "$user_name" -c "chmod 700 '/home/$user_name/.ssh/'" su "$user_name" -c "chmod 700 '/home/$user_name/.ssh/'"
echo "创建成功" echo "创建成功"
echo "账号:$user_name" echo "账号:$user_name"
echo "密钥登录" echo "密钥登录"
fi fi
declare pick2 declare pick2
echo "是否关闭root登录" echo "是否关闭root登录"
read -p "输入 n 取消关闭:" pick2 read -p "输入 n 取消关闭:" pick2
if [[ ! $pick2 =~ [Nn] ]];then if [[ ! $pick2 =~ [Nn] ]];then
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
echo "root用户登录已关闭" echo "root用户登录已关闭"
fi fi
sudo systemctl restart sshd.service sudo systemctl restart sshd.service
;; ;;
4) 4)
declare pick_root declare pick_root
declare pick2_key declare pick2_key
declare pick2_password declare pick2_password
echo "是否关闭root登录" echo "是否关闭root登录"
read -p "输入 n 关闭:" pick_root read -p "输入 n 关闭:" pick_root
echo "是否关闭密码登录" echo "是否关闭密码登录"
read -p "输入 n 关闭:" pick2_password read -p "输入 n 关闭:" pick2_password
echo "是否关闭密钥登录" echo "是否关闭密钥登录"
read -p "输入 n 关闭:" pick2_key read -p "输入 n 关闭:" pick2_key
if [[ ! $pick_root =~ [Nn] ]];then if [[ ! $pick_root =~ [Nn] ]];then
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
echo "root用户登录开启" echo "root用户登录开启"
else else
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
echo "root用户登录关闭" echo "root用户登录关闭"
fi fi
if [[ ! $pick2_password =~ [Nn] ]];then if [[ ! $pick2_password =~ [Nn] ]];then
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
echo "密码登录:开启" echo "密码登录:开启"
else else
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
echo "密码登录:关闭" echo "密码登录:关闭"
fi fi
if [[ ! $pick2_key =~ [Nn] ]];then if [[ ! $pick2_key =~ [Nn] ]];then
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config
echo "密钥登录:开启" echo "密钥登录:开启"
else else
sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config
echo "密钥登录:关闭" echo "密钥登录:关闭"
fi fi
sudo systemctl restart sshd.service sudo systemctl restart sshd.service
;; ;;
5) 5)
read -p "请输入需要修改的端口号(默认22): " port_number read -p "请输入需要修改的端口号(默认22): " port_number
if [[ -z $port_number ]];then if [[ -z $port_number ]];then
port_number=22 port_number=22
fi fi
if ! [[ $port_number =~ ^[0-9]+$ ]] || ! ((port_number > 0 && port_number < 65535)); then if ! [[ $port_number =~ ^[0-9]+$ ]] || ! ((port_number > 0 && port_number < 65535)); then
echo "端口不合法" echo "端口不合法"
exit exit
fi fi
if sudo lsof -i :$port_number -t >/dev/null; then if sudo lsof -i :$port_number -t >/dev/null; then
echo "$port_number 端口已被占用" echo "$port_number 端口已被占用"
exit exit
fi fi
sudo sed -i "s/^#\?Port.*/Port $port_number/g" /etc/ssh/sshd_config sudo sed -i "s/^#\?Port.*/Port $port_number/g" /etc/ssh/sshd_config
sudo systemctl restart sshd.service sudo systemctl restart sshd.service
echo "端口已经修改为$port_number,记得防火墙放行" echo "端口已经修改为$port_number,记得防火墙放行"
;; ;;
*) *)
clear clear
esac esac

View File

@ -1,19 +1,56 @@
declare pick declare pick
echo "========Other========" echo "========Other========"
echo "1.开启BBR" echo "1.开启BBR"
echo "2.更换系统语言"
echo "输入其他任意返回主页" echo "输入其他任意返回主页"
echo "========Other========" echo "========Other========"
read -p "请输入:" pick read -p "请输入:" pick
case "$pick" in case "$pick" in
'1') '1')
declare version=$(uname -r | awk -F "." '{print $1}') declare version=$(uname -r | awk -F "." '{print $1}')
if ! [[ $version -ge 5 ]];then if ! [[ $version -ge 5 ]];then
echo "系统内核版本过低" echo "系统内核版本过低"
exit exit
fi fi
grep -q "net.core.default_qdisc=fq" "/etc/sysctl.conf" || echo 'net.core.default_qdisc=fq' | sudo tee -a "/etc/sysctl.conf" grep -q "net.core.default_qdisc=fq" "/etc/sysctl.conf" || echo 'net.core.default_qdisc=fq' | sudo tee -a "/etc/sysctl.conf"
grep -q "net.ipv4.tcp_congestion_control=bbr" "/etc/sysctl.conf" || echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a "/etc/sysctl.conf" grep -q "net.ipv4.tcp_congestion_control=bbr" "/etc/sysctl.conf" || echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a "/etc/sysctl.conf"
sudo sysctl -p || echo "bbr 开启失败" sudo sysctl -p || echo "bbr 开启失败"
sysctl net.ipv4.tcp_available_congestion_control | grep bbr && echo "bbr 开启成功" sysctl net.ipv4.tcp_available_congestion_control | grep bbr && echo "bbr 开启成功"
;;
'2')
declare lang
echo "1.中文"
echo "2.英文"
read -p "请输入:" lang
if [[ -f "/usr/bin/apt-get" ]];then
sudo apt-get install -y locales
sudo apt-get install -y language-pack-zh-hans
elif [[ -f "/usr/bin/apt" ]];then
sudo apt install -y locales
sudo apt install -y language-pack-zh-hans
else
echo "暂不支持该系统一键更换语言"
exit
fi
case $lang in
'1')
sudo sed -i 's/.*zh_CN.UTF-8.*/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
sudo sed -i "s/^LANG.*/LANG=zh_CN.UTF-8/g" /etc/default/locale
sudo sed -i "s/^LC_ALL.*/LC_ALL=zh_CN.UTF-8/g" /etc/default/locale
source /etc/default/locale
sudo locale-gen
update-locale
echo "中文语言更换成功"
;;
'2')
sudo sed -i 's/.*en_US.UTF-8.*/en_US.UTF-8 UTF-8/g' /etc/locale.gen
sudo sed -i "s/^LANG.*/LANG=en_US.UTF-8/g" /etc/default/locale
sudo sed -i "s/^LC_ALL.*/LC_ALL=en_US.UTF-8/g" /etc/default/locale
source /etc/default/locale
sudo locale-gen
update-locale
echo "英文语言更换成功"
;;
esac
esac esac

View File

@ -1,16 +1,17 @@
#!/bin/bash #!/bin/bash
declare install_str 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'
;; declare pkg
*) if [[ -f "/usr/bin/apt-get" ]];then
echo "暂不支持该系统一键安装常用软件" pkg='apt-get'
exit elif [[ -f "/usr/bin/apt" ]];then
esac pkg='apt'
else
echo "暂不支持该系统一键安装常用软件"
exit
fi
declare pick declare pick
declare -a soft_array declare -a soft_array
@ -62,7 +63,7 @@ if [[ ! $pick_docker =~ [Nn] ]];then
read -p "请输入需要选择的镜像站:" docker_img_number_pick read -p "请输入需要选择的镜像站:" docker_img_number_pick
declare docker_img declare docker_img
if [[ ! $docker_img_number_pick =~ [1-${#docker_imgs[@]}] ]];then if [[ ! $docker_img_number_pick =~ [1-${#docker_imgs[@]}] ]];then
docker_img='https://mirrors.ustc.edu.cn/docker-ce' docker_img='https://mirrors.sustc.edu.cn/docker-ce'
else else
docker_img_number_pick=${docker_img_number[$docker_img_number_pick]} docker_img_number_pick=${docker_img_number[$docker_img_number_pick]}
docker_img=${docker_imgs[$docker_img_number_pick]} docker_img=${docker_imgs[$docker_img_number_pick]}
@ -76,7 +77,7 @@ if [[ ! $pick_x =~ [Nn] ]];then
fi fi
eval "$install_str -y" eval "sudo ${pkg} install -y ${install_str}"
if [[ ! $pick_x =~ [Nn] ]];then if [[ ! $pick_x =~ [Nn] ]];then
eval "$(curl https://get.x-cmd.com)" eval "$(curl https://get.x-cmd.com)"
fi fi
@ -93,9 +94,9 @@ fi
if [[ ! $pick_docker =~ [Nn] ]];then if [[ ! $pick_docker =~ [Nn] ]];then
if [[ $version == 'debian' ]];then if [[ ${pkg} == 'apt' || ${pkg} == 'apt-get' ]];then
sudo apt-get update sudo ${pkg} update
sudo apt-get install ca-certificates curl -y sudo ${pkg} install ca-certificates curl -y
sudo install -m 0755 -d /etc/apt/keyrings sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc sudo curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
@ -103,8 +104,8 @@ if [[ ! $pick_docker =~ [Nn] ]];then
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] ${docker_img}/linux/${version} \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] ${docker_img}/linux/${version} \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update sudo ${pkg} update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y sudo ${pkg} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
fi fi
fi fi

View File

@ -48,6 +48,7 @@ deb ${url}/debian/ bookworm main contrib non-free non-free-firmware
deb ${url}/debian/ bookworm-updates main contrib non-free non-free-firmware deb ${url}/debian/ bookworm-updates main contrib non-free non-free-firmware
deb ${url}/debian/ bookworm-backports main contrib non-free non-free-firmware deb ${url}/debian/ bookworm-backports main contrib non-free non-free-firmware
EOF EOF
sudo apt update
sudo apt-get update sudo apt-get update
;; ;;
*) *)