diff --git a/Config/Automation/acme.sh b/Config/Automation/acme.sh new file mode 100644 index 0000000..818fa31 --- /dev/null +++ b/Config/Automation/acme.sh @@ -0,0 +1,11 @@ +declare path="$1" + +if [[ -f "${path}/acme.sh" ]];then + echo "该路径文件已经存在" +fi + +cat > "${path}/acme.sh" << EOF +#!/bin/bash +${HOME}/.acme.sh/acme.sh --upgrade +${HOME}/.acme.sh/acme.sh --renew-all +EOF \ No newline at end of file diff --git a/Config/Automation/backup.sh b/Config/Automation/backup.sh index bf4f4f1..cd5274d 100644 --- a/Config/Automation/backup.sh +++ b/Config/Automation/backup.sh @@ -1,12 +1,10 @@ #!/bin/bash declare path="$1" -declare cron="$2" declare web_path declare local_pick declare baidu_pick declare aliyun_pick -declare cron declare ignore=1 @@ -103,12 +101,6 @@ for item in "$web_path"/*; do rm "\${item_name}_\${date_time}.tar.gz" done EOF -chmod +x "$path/backup.sh" - -declare cron_job="${cron} ${path}/backup.sh" -(crontab -l 2>/dev/null | grep -v "backup.sh") | sudo crontab - - -sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败" if [[ $local_pick == [Yy] ]];then echo "本地备份路径:${web_path}/年份/目录名称" diff --git a/Config/Automation/up-docker_compose.sh b/Config/Automation/up-docker_compose.sh new file mode 100644 index 0000000..906fabe --- /dev/null +++ b/Config/Automation/up-docker_compose.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +declare path="$1" +if ! command -v docker &> /dev/null; then + echo "docker未安装" + exit +fi +if [[ -f "${path}/up-docker_compose.sh" ]];then + echo "该路径文件已经存在" +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 +for dir in "${web_path}"/*/; do + cd "\$dir" || exit + sudo docker compose pull + sudo docker compose up -d +done +EOF \ No newline at end of file diff --git a/Config/Automation/update.sh b/Config/Automation/update.sh index a3f81b4..ed864d0 100644 --- a/Config/Automation/update.sh +++ b/Config/Automation/update.sh @@ -1,5 +1,4 @@ declare path="$1" -declare cron="$2" if [[ -f "${path}/update.sh" ]];then echo "该路径文件已经存在" @@ -20,11 +19,3 @@ else echo "暂不支持该系统配置自动更新软件" exit fi - -chmod +x "${path}/update.sh" - -declare cron_job="${cron} ${path}/update.sh" -(crontab -l 2>/dev/null | grep -v "update.sh") | sudo crontab - -(crontab -l 2>/dev/null; echo "$cron_job") | sudo crontab - - -sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败" \ No newline at end of file diff --git a/Menus/Automation.sh b/Menus/Automation.sh index 41ac7a6..7a7f67e 100644 --- a/Menus/Automation.sh +++ b/Menus/Automation.sh @@ -3,15 +3,18 @@ declare path_script=$1 declare pick echo "========Automation========" -echo "1.自动备份" -echo "2.自动更新软件" -echo "3.自动Docker compose应用" -echo "4.自动更新ssh证书" +declare print_number=0 +declare -a print_array +for i in "${path_script}/Config/Automation"/*;do + print_number=$((print_number + 1)) + print_array[$print_number]=$(awk -F '.' '{print $1}' <<< "$(basename $i)") + echo "${print_number}.${print_array[$print_number]}" +done echo "输入其他任意返回主页" echo "========Automation========" read -p "请输入:" pick -if [[ ${pick} -lt 1 || ${pick} -gt 4 ]];then +if [[ ! ${pick} =~ [1-$print_number] ]];then exit fi @@ -46,44 +49,13 @@ if [[ "$cron" == '* * * * * ' ]];then exit fi +bash "${path_script}/Config/Automation/${print_array[pick]}.sh" "$path" -case $pick in - '1') - bash "${path_script}/Config/Automation/backup.sh" "$path" "$cron" - ;; - '2') - bash "${path_script}/Config/Automation/update.sh" "$path" "$cron" - ;; - '3') - if ! command -v docker &> /dev/null; then - echo "docker未安装" - exit - fi - if [[ -f "${path}/up-docker_compose.sh" ]];then - echo "该路径文件已经存在" - 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 -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" +chmod +x "${path}/${print_array[pick]}" +declare cron_job="${cron} ${path}/${print_array[pick]}" +(crontab -l 2>/dev/null | grep -v "${print_array[pick]}") | sudo crontab - +(crontab -l 2>/dev/null; echo "$cron_job") | sudo crontab - - declare cron_job="${cron} ${path}/up-docker_compose.sh" - (crontab -l 2>/dev/null | grep -v "up-docker_compose.sh") | sudo crontab - - (crontab -l 2>/dev/null; echo "$cron_job") | sudo crontab - +sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败" - sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败" - ;; - '4') - echo "糟糕忘写了" -esac echo "配置完成" \ No newline at end of file