This commit is contained in:
Meliox 2025-08-07 11:30:44 +02:00
parent 4187de4b05
commit b9902b9f80

View File

@ -277,10 +277,7 @@ function install_mod {
# Provide sensor configuration # Provide sensor configuration
configure configure
perform_backup
# Make backup directory and perform backup
makeBackupDirectory
performBackup
if [ $SENSORS_DETECTED = true ]; then if [ $SENSORS_DETECTED = true ]; then
local sensorsCmd local sensorsCmd
@ -924,7 +921,7 @@ Ext.define('PVE.mod.TempHelper', {\n\
# Function to uninstall the modification # Function to uninstall the modification
function uninstall_mod { function uninstall_mod {
setBackupDirectory set_backup_directory
msg "\nRestoring modified files..." msg "\nRestoring modified files..."
@ -991,22 +988,23 @@ function save_sensors_data {
fi fi
} }
function setBackupDirectory { function set_backup_directory {
# Check if the BACKUP_DIR variable is set, if not, use the default backup # Check if the BACKUP_DIR variable is set, if not, use the default backup
if [[ -z "$BACKUP_DIR" ]]; then if [[ -z "$BACKUP_DIR" ]]; then
# If not set, use the default backup directory, which is based on the home directory and PVE-MODS # If not set, use the default backup directory, which is based on the home directory and PVE-MODS
local DEFAULT_BACKUP_DIR="$HOME/PVE-MODS" BACKUP_DIR="$HOME/PVE-MODS"
msg "Backup directory not set. Using default: $DEFAULT_BACKUP_DIR" msg "Using default backup directory: $BACKUP_DIR"
BACKUP_DIR="$DEFAULT_BACKUP_DIR" else
# If set, ensure it is a valid directory
if [[ ! -d "$BACKUP_DIR" ]]; then
err "The specified backup directory does not exist: $BACKUP_DIR"
fi
msg "Using custom backup directory: $BACKUP_DIR"
fi fi
# Ensure the BACKUP_DIR variable is an absolute path
BACKUP_DIR=$(realpath "$BACKUP_DIR")
msg "Using backup directory: $BACKUP_DIR"
} }
function makeBackupDirectory { function create_backup_directory {
setBackupDirectory set_backup_directory
# Create the backup directory if it does not exist # Create the backup directory if it does not exist
if [[ ! -d "$BACKUP_DIR" ]]; then if [[ ! -d "$BACKUP_DIR" ]]; then
@ -1019,28 +1017,34 @@ function makeBackupDirectory {
fi fi
} }
function performBackup { function create_file_backup() {
local timestamp=$(date +%Y%m%d_%H%M%S) local source_file="$1"
local timestamp="$2"
local filename
filename=$(basename "$source_file")
local backup_file="$BACKUP_DIR/${filename}.$timestamp"
[[ -f "$source_file" ]] || err "Source file does not exist: $source_file"
[[ -r "$source_file" ]] || err "Cannot read source file: $source_file"
cp "$source_file" "$backup_file" || err "Failed to create backup: $backup_file"
# Verify backup integrity
if ! cmp -s "$source_file" "$backup_file"; then
err "Backup verification failed for: $backup_file"
fi
msg "Created backup: $backup_file"
}
# Create backup of original file function perform_backup {
cp "$NODES_PM_FILE" "$BACKUP_DIR/Nodes.pm.$timestamp" local timestamp
cp "$NODES_PM_FILE" "$BACKUP_DIR/Nodes.pm.$timestamp" || { timestamp=$(date +%Y%m%d_%H%M%S)
err "Failed to create backup file: \"$BACKUP_DIR/Nodes.pm.$timestamp\""
} create_backup_directory
if [[ $(md5sum "$NODES_PM_FILE" | awk '{ print $1 }') != $(md5sum "$BACKUP_DIR/Nodes.pm.$timestamp" | awk '{ print $1 }') ]]; then create_file_backup "$NODES_PM_FILE" "$timestamp"
err "Backup is not identical to original: \"$BACKUP_DIR/Nodes.pm.$timestamp\"" create_file_backup "$PVE_MANAGER_LIB_JS_FILE" "$timestamp"
fi
msg "Backup of \"$NODES_PM_FILE\" saved to \"$BACKUP_DIR/Nodes.pm.$timestamp\"."
# Create backup of original file
cp "$PVE_MANAGER_LIB_JS_FILE" "$BACKUP_DIR/pvemanagerlib.js.$timestamp"
cp "$PVE_MANAGER_LIB_JS_FILE" "$BACKUP_DIR/pvemanagerlib.js.$timestamp" || {
err "Failed to create backup file: \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\""
}
if [[ $(md5sum "$PVE_MANAGER_LIB_JS_FILE" | awk '{ print $1 }') != $(md5sum "$BACKUP_DIR/pvemanagerlib.js.$timestamp" | awk '{ print $1 }') ]]; then
err "Backup is not identical to original: \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\""
fi
msg "Backup of \"$PVE_MANAGER_LIB_JS_FILE\" saved to \"$BACKUP_DIR/pvemanagerlib.js.$timestamp\"."
} }
# Process the arguments using a while loop and a case statement # Process the arguments using a while loop and a case statement