From 974cb98bc229e52961ffc39fe5058ee4e74b0334 Mon Sep 17 00:00:00 2001 From: wukongdaily <2666180@gmail.com> Date: Tue, 2 Jul 2024 13:26:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=82=E5=90=881panel?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1panel/backup.sh | 14 +++++++++ 1panel/restore.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 1panel/backup.sh create mode 100644 1panel/restore.sh diff --git a/1panel/backup.sh b/1panel/backup.sh new file mode 100644 index 0000000..6036288 --- /dev/null +++ b/1panel/backup.sh @@ -0,0 +1,14 @@ +#!/bin/sh +backup() { + # 检查是否传入自定义路径 + current_date=$(date "+%Y-%m-%d_%H-%M") + echo "备份时间:$current_date" + local backup_path=${1:-/tmp/upload} + mkdir -p "$backup_path/${current_date}" + cd "$backup_path/${current_date}" || exit + tar --strip-components=1 -czvf backup.tar.gz -C /ahost overlay + echo "系统备份文件已保存至 $backup_path/${current_date}/backup.tar.gz" + echo "请及时下载保存到电脑 供恢复时使用" +} + +backup "$1" diff --git a/1panel/restore.sh b/1panel/restore.sh new file mode 100644 index 0000000..a458a57 --- /dev/null +++ b/1panel/restore.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# 定义颜色输出函数 +red() { echo -e "\033[31m\033[01m[WARNING] $1\033[0m"; } +green() { echo -e "\033[32m\033[01m[INFO] $1\033[0m"; } +yellow() { echo -e "\033[33m\033[01m[NOTICE] $1\033[0m"; } +blue() { echo -e "\033[34m\033[01m[MESSAGE] $1\033[0m"; } +light_magenta() { echo -e "\033[95m\033[01m[NOTICE] $1\033[0m"; } +light_yellow() { echo -e "\033[93m\033[01m[NOTICE] $1\033[0m"; } + +# 检查文件传输是否已安装 +check_istoreos_style_installed() { + # 检查luci-app-filetransfer的一些关键文件是否存在 + CHECK_FILES="/usr/lib/lua/luci/controller/filetransfer.lua +/usr/lib/lua/luci/view/filetransfer +/usr/lib/lua/luci/model/cbi/filetransfer" + + # 设置一个标记,用来表示文件是否找到 + FOUND=0 + + for FILE in $CHECK_FILES; do + if [ -e "$FILE" ]; then + FOUND=1 + break + fi + done + + if [ $FOUND -eq 1 ]; then + echo "luci-app-filetransfer is installed." + else + # 先恢复到一键iStoreOS风格化 + wget -O /tmp/restore.sh https://gitee.com/wukongdaily/gl_onescript/raw/master/restore.sh && sh /tmp/restore.sh + fi +} + +# 恢复标准的iStoreOS +normal_restore() { + # 提示用户输入要恢复的文件路径 + read -p "请输入要恢复的文件路径(默认: /tmp/upload/backup.tar.gz): " file_path + + # 如果用户没有输入,使用默认路径 + if [ -z "$file_path" ]; then + file_path="/tmp/upload/backup.tar.gz" + fi + + # 检查文件是否存在 + if [ -f "$file_path" ]; then + # 恢复overlay + tar -xzvf "$file_path" -C / + green "恢复已完成, 系统正在重启....." + reboot + else + red "文件不存在,请确保文件路径正确并重试。" + exit 1 + fi + +} + +restore() { + model_info=$(cat /tmp/sysinfo/model) + green "型号:$model_info" + case "$model_info" in + *2500* | *3000* | *6000*) + check_istoreos_style_installed + normal_restore + ;; + *) + echo "Router name does not contain '3000', '6000', or '2500'." + normal_restore + ;; + esac +} + +restore \ No newline at end of file