From 170d5dd6e8c1c3c93c8c5c0187966a304ec0efd0 Mon Sep 17 00:00:00 2001 From: stirelshka8 Date: Sun, 9 Feb 2025 17:30:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D1=83?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install_backup.sh | 113 ++++++++-------------------------------------- 1 file changed, 19 insertions(+), 94 deletions(-) diff --git a/install_backup.sh b/install_backup.sh index d749906..6f7d825 100755 --- a/install_backup.sh +++ b/install_backup.sh @@ -33,6 +33,21 @@ BACKUP_CONFIG="$WORK_DIR/backup.ini" SCRIPT_URL="http://files.adminlabs.space/scripts/backup.sh" CONFIG_URL="http://files.adminlabs.space/scripts/backup.ini" +# Проверка наличия необходимых утилит +REQUIRED_PACKAGES=(lftp jq) +for PACKAGE in "${REQUIRED_PACKAGES[@]}"; do + if ! command -v "$PACKAGE" &> /dev/null; then + read -p "$PACKAGE is not installed. Install it? [y/n] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + apt install -y "$PACKAGE" + else + echo "Error: $PACKAGE is not installed." + exit 1 + fi + fi +done + # Создание рабочей директории, если она не существует if [ ! -d "$WORK_DIR" ]; then mkdir -p "$WORK_DIR" || { echo "Error: Failed to create directory $WORK_DIR"; exit 1; } @@ -50,99 +65,9 @@ download_file() { curl -o "$dest" "$url" || { echo "Error: Failed to download $url"; exit 1; } } -# Проверка и копирование скрипта -if [[ -f "$BACKUP_SCRIPT" ]]; then - cp "$BACKUP_SCRIPT" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_SCRIPT to $WORK_DIR"; exit 1; } -else - download_file "$SCRIPT_URL" "$BACKUP_SCRIPT" -fi +download_file "$SCRIPT_URL" "$BACKUP_SCRIPT" +download_file "$CONFIG_URL" "$BACKUP_CONFIG" -# Проверка и копирование конфигурационного файла -if [[ -f "$BACKUP_CONFIG" ]]; then - cp "$BACKUP_CONFIG" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_CONFIG to $WORK_DIR"; exit 1; } -else - download_file "$CONFIG_URL" "$BACKUP_CONFIG" -fi - -# Функция для редактирования файла backup.ini -edit_backup_config() { - clear - echo "Editing backup.ini..." - - # Временный файл для редактирования - TEMP_FILE=$(mktemp) - - # Чтение конфигурационного файла и отображение его содержимого - echo -e "\033[1;33m************************ Backup.ini ****************************\033[0m" - cat "$BACKUP_CONFIG" - echo -e "\n\033[1;33m************************ Backup.ini ****************************\033[0m" - - echo -e "\n\n" - - # Запрос на редактирование каждой секции - while true; do - echo -e "\033[1;34mWhich section would you like to edit? (B - Backup, F - FTP, S - SENT, Q - exit)\033[0m" - read -rp "Enter section >>> " section - - case $section in - B) - echo "Editing [Backup] section:" - echo "Current settings:" - grep -A 5 "[Backup]" "$BACKUP_CONFIG" - echo "Enter new values (or press Enter to keep current):" - read -p "ENABLE_DIRS (true/false): " ENABLE_DIRS - read -p "ENABLE_FILES (true/false): " ENABLE_FILES - read -p "SKIP_FILES: " SKIP_FILES - read -p "SKIP_DIRS: " SKIP_DIRS - read -p "DIRS (comma separated): " DIRS - read -p "FILES (comma separated): " FILES - - # Запись изменений во временный файл - sed "/[Backup]/,/^[/{s/ENABLE_DIRS=.*/ENABLE_DIRS=${ENABLE_DIRS:-true}/; s/ENABLE_FILES=.*/ENABLE_FILES=${ENABLE_FILES:-false}/; s/SKIP_FILES=.*/SKIP_FILES=${SKIP_FILES:-}/; s/SKIP_DIRS=.*/SKIP_DIRS=${SKIP_DIRS:-}/; s/DIRS=.*/DIRS=${DIRS:-/etc,/var/log}/; s/FILES=.*/FILES=${FILES:-/home/user/BashProject/backup.sh,/home/user/jet/restore.sh}/}" "$BACKUP_CONFIG" > "$TEMP_FILE" - mv "$TEMP_FILE" "$BACKUP_CONFIG" - ;; - F) - echo "Editing [FTP] section:" - echo "Current settings:" - grep -A 4 "[FTP]" "$BACKUP_CONFIG" - read -p "FTP_SERVER: " FTP_SERVER - read -p "FTP_USER: " FTP_USER - read -p "FTP_PASS: " FTP_PASS - - sed "/[FTP]/,/^[/{s/FTP_SERVER=.*/FTP_SERVER=${FTP_SERVER:-127.0.0.1}/; s/FTP_USER=.*/FTP_USER=${FTP_USER:-user}/; s/FTP_PASS=.*/FTP_PASS=${FTP_PASS:-password}/}" "$BACKUP_CONFIG" > "$TEMP_FILE" - mv "$TEMP_FILE" "$BACKUP_CONFIG" - ;; - S) - echo "Editing [SENT] section:" - echo "Current settings:" - grep -A 6 "[SENT]" "$BACKUP_CONFIG" - read -p "ENABLE_SENT (true/false): " ENABLE_SENT - read -p "ENABLE_SENT_GOTIFY (true/false): " ENABLE_SENT_GOTIFY - read -p "ENABLE_SENT_TELEGRAM (true/false): " ENABLE_SENT_TELEGRAM - read -p "GOTIFY_URL: " GOTIFY_URL - read -p "GOTIFY_APP_TOKEN: " GOTIFY_APP_TOKEN - read -p "TELEGRAM_TOKEN: " TELEGRAM_TOKEN - read -p "CHAT_ID: " CHAT_ID - read -p 'TEXT_FINISH_MESSAGE: ' TEXT_FINISH_MESSAGE - - sed "/[SENT]/,/^[/{s/ENABLE_SENT=.*/ENABLE_SENT=${ENABLE_SENT:-true}/; s/ENABLE_SENT_GOTIFY=.*/ENABLE_SENT_GOTIFY=${ENABLE_SENT_GOTIFY:-true}/; s/ENABLE_SENT_TELEGRAM=.*/ENABLE_SENT_TELEGRAM=${ENABLE_SENT_TELEGRAM:-true}/; s/GOTIFY_URL=.*/GOTIFY_URL=${GOTIFY_URL:-http://ваш_gotify_сервер}/; s/GOTIFY_APP_TOKEN=.*/GOTIFY_APP_TOKEN=${GOTIFY_APP_TOKEN:-0000000}/; s/TELEGRAM_TOKEN=.*/TELEGRAM_TOKEN=${TELEGRAM_TOKEN:-00000000}/; s/CHAT_ID=.*/CHAT_ID=${CHAT_ID:-00000000}/; s/TEXT_FINISH_MESSAGE=.*/TEXT_FINISH_MESSAGE="${TEXT_FINISH_MESSAGE:-Backup finished}"/" "$BACKUP_CONFIG" > "$TEMP_FILE" - mv "$TEMP_FILE" "$BACKUP_CONFIG" - ;; - Q) - echo "Exiting configuration editor." - exit 0 - ;; - *) - echo "Invalid section. Please choose one of the following: Backup, FTP, SENT, END or exit." - ;; - esac - done - - rm -f "$TEMP_FILE" -} - -# Запуск функции редактирования конфигурации -edit_backup_config - -echo "Installation complete." +chmod +x "$BACKUP_SCRIPT" +echo "Installation complete. Please edit the backup.ini file to configure the backup." \ No newline at end of file