Исправлен скрипт установки

This commit is contained in:
stirelshka8 2025-02-09 17:30:31 +03:00
parent 38e6b73bd1
commit 170d5dd6e8

View File

@ -33,6 +33,21 @@ BACKUP_CONFIG="$WORK_DIR/backup.ini"
SCRIPT_URL="http://files.adminlabs.space/scripts/backup.sh" SCRIPT_URL="http://files.adminlabs.space/scripts/backup.sh"
CONFIG_URL="http://files.adminlabs.space/scripts/backup.ini" 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 if [ ! -d "$WORK_DIR" ]; then
mkdir -p "$WORK_DIR" || { echo "Error: Failed to create directory $WORK_DIR"; exit 1; } 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; } curl -o "$dest" "$url" || { echo "Error: Failed to download $url"; exit 1; }
} }
# Проверка и копирование скрипта download_file "$SCRIPT_URL" "$BACKUP_SCRIPT"
if [[ -f "$BACKUP_SCRIPT" ]]; then download_file "$CONFIG_URL" "$BACKUP_CONFIG"
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
# Проверка и копирование конфигурационного файла chmod +x "$BACKUP_SCRIPT"
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."
echo "Installation complete. Please edit the backup.ini file to configure the backup."