#!/bin/bash # Проверка на выполнение скрипта с правами суперпользователя if [ "$EUID" -ne 0 ]; then echo "Error: the script must be run with superuser rights (sudo)." exit 1 fi WORK_DIR="/opt/adminlabs_backup" BACKUP_SCRIPT="$WORK_DIR/backup.sh" BACKUP_CONFIG="$WORK_DIR/backup.ini" SCRIPT_URL="http://files.adminlabs.space/scripts/backup.sh" CONFIG_URL="http://files.adminlabs.space/scripts/backup.ini" # Создание рабочей директории, если она не существует if [ ! -d "$WORK_DIR" ]; then mkdir -p "$WORK_DIR" || { echo "Error: Failed to create directory $WORK_DIR"; exit 1; } echo "Created directory $WORK_DIR." else echo "Directory $WORK_DIR already exists." fi # Функция для скачивания файла download_file() { local url="$1" local dest="$2" echo "Downloading $url..." curl -o "$dest" "$url" || { echo "Error: Failed to download $url"; exit 1; } } # Проверка и копирование скрипта if [[ -f "$BACKUP_SCRIPT" ]]; then mv "$BACKUP_SCRIPT" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_SCRIPT to $WORK_DIR"; exit 1; } else download_file "$SCRIPT_URL" "$BACKUP_SCRIPT" mv "$BACKUP_SCRIPT" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_SCRIPT to $WORK_DIR"; exit 1; } fi # Проверка и копирование конфигурационного файла if [[ -f "$BACKUP_CONFIG" ]]; then mv "$BACKUP_CONFIG" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_CONFIG to $WORK_DIR"; exit 1; } else download_file "$CONFIG_URL" "$BACKUP_CONFIG" mv "$BACKUP_CONFIG" "$WORK_DIR" || { echo "Error: Failed to move $BACKUP_CONFIG to $WORK_DIR"; exit 1; } fi echo "Installation complete."