diff --git a/Menus/Automation.sh b/Menus/Automation.sh index e69de29..471a70b 100644 --- a/Menus/Automation.sh +++ b/Menus/Automation.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +declare pick +echo "========Automation========" +echo "1.自动备份" +echo "2.自动更新软件" +echo "3.自动Docker compose应用" +echo "4.自动更新ssh证书" +echo "输入其他任意返回主页" +echo "========Automation========" +read -p "请输入:" pick + +if [[ ${pick} -lt 1 || ${pick} -gt 4 ]];then + exit +fi + +read -p "请输入脚本存放路径(默认:/var/script):" path + +if [[ -z $path ]];then + path='/var/script' +fi +mkdir -p "$path" + + +case $pick in + '1') + bash Config/Automation/backup.sh "$path" + ;; + '2') + bash Config/Automation/update.sh "$path" + ;; + '3') + if ! command -v docker &> /dev/null; then + echo "docker未安装" + exit + fi + if [[ -f "${path}/up-docker_compose.sh" ]];then + echo "该路径文件已经存在" + exit + fi + declare web_path + read -p "请输入数据目录,默认 /var/www :" web_path + if [[ -z ${web_path} ]];then + web_path='/var/www' + fi + cat > "${path}/up-docker_compose.sh" << EOF +#!/bin/bash +docker_path="${web_path}" +for dir in "web_path"/*/; do + cd "\$dir" || exit + sudo docker compose pull + sudo docker compose up -d +done +EOF + chmod +x "${path}/up-docker_compose.sh" + sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败" + ;; + '4') + echo "国内忘写了" +esac +echo "配置完成" \ No newline at end of file diff --git a/Menus/Docker.sh b/Menus/Docker.sh index 921767b..1d684b2 100644 --- a/Menus/Docker.sh +++ b/Menus/Docker.sh @@ -52,7 +52,7 @@ if [[ $pick == '1' ]];then exit fi sudo echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json" - sudo systemctl restart docker + sudo systemctl restart docker 2>> /dev/null|| echo "docker 重启失败" echo "换源成功" elif [[ $pick == '2' ]];then diff --git a/Menus/Login.sh b/Menus/Login.sh index 785d7ea..f4615b7 100644 --- a/Menus/Login.sh +++ b/Menus/Login.sh @@ -1,4 +1,4 @@ -#!bin/bash +#!/bin/bash declare pick echo "========Login========" echo "1.修改root密码" diff --git a/Menus/Software.sh b/Menus/Software.sh index f82c546..62da977 100644 --- a/Menus/Software.sh +++ b/Menus/Software.sh @@ -21,7 +21,7 @@ soft_array[3]='curl' soft_array[4]='git' soft_array[5]='ssh' soft_array[6]='zsh' - +soft_array[7]='zip' echo "======一键安装常用软件======" for i in "${soft_array[@]}" diff --git a/Menus/Sources.sh b/Menus/Sources.sh index 8a916b6..26a7add 100644 --- a/Menus/Sources.sh +++ b/Menus/Sources.sh @@ -29,11 +29,11 @@ echo "========Sources========" read -p "请输入:" pick -if [[ ${pick} -le 0 || ${pick} -gt ${#sources_dick[*]} ]];then - echo "输入错误" - exit -elif [[ -z $pick ]];then +if [[ -z $pick ]];then declare url='http://mirrors.ustc.edu.cn' +elif [[ ${pick} -le 0 || ${pick} -gt ${#sources_dick[*]} ]];then + echo "输入错误" + exit else pick=${pcik_array[$pick]} declare url=${sources_dick[$pick]} @@ -43,11 +43,16 @@ fi case "$version" in 'bookworm') - { - echo "deb ${url}/debian/ bookworm main contrib non-free non-free-firmware" - echo "deb ${url}/debian/ bookworm-updates main contrib non-free non-free-firmware" - echo "deb ${url}/debian/ bookworm-backports main contrib non-free non-free-firmware" - } > /etc/apt/sources.list + cat > "/etc/apt/sources.list" << EOF +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-backports main contrib non-free non-free-firmware +EOF sudo apt-get update ;; -esac \ No newline at end of file + *) + echo "暂不支持该系统配置自动更新软件" + exit +esac + +echo "换源成功" \ No newline at end of file