From 565b9464a4c1a63dd650b89d5ec97fcf5c2e2f99 Mon Sep 17 00:00:00 2001 From: haydn Date: Mon, 21 Apr 2025 14:36:19 +0930 Subject: [PATCH] Added slackupdr_checker --- bash/slackupdr_checker | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 bash/slackupdr_checker diff --git a/bash/slackupdr_checker b/bash/slackupdr_checker new file mode 100755 index 0000000..52976b0 --- /dev/null +++ b/bash/slackupdr_checker @@ -0,0 +1,52 @@ +#!/bin/bash +#/usr/local/bin/slackupdr_checker +# Check for .new config files and then (k)eep, (o)verwrite or (r)emove + +# Ensure the script is executed with sudo +if [ "$EUID" -ne 0 ]; then + echo "This script must be run with sudo." + exec sudo "$0" "$@" +fi + +CONFIG_DIR="/etc" # Modify this path if necessary +NEW_FILES=$(find "$CONFIG_DIR" -name "*.new") + +for NEW_FILE in $NEW_FILES; do + OLD_FILE="${NEW_FILE%.new}" + + echo -e "\nProcessing: $NEW_FILE" + + if [ -f "$OLD_FILE" ]; then + echo "Diff between $OLD_FILE and $NEW_FILE:" + diff -u "$OLD_FILE" "$NEW_FILE" | less -X # Pipe to 'less' for better readability + else + echo "New config file found: $NEW_FILE (no existing counterpart)" + fi + + echo -e "\nChoose an action:" + echo " (K)eep the old file and the new file" + echo " (O)verwrite old file with new (.orig backup)" + echo " (R)emove the .new file" + echo -n "Your choice: " + read -n 1 -r CHOICE # single keypress + echo # newline after keypress + + case "$CHOICE" in + K|k) echo "Keeping $OLD_FILE and $NEW_FILE" ;; + O|o) + mv "$OLD_FILE" "$OLD_FILE.orig" + mv "$NEW_FILE" "$OLD_FILE" + echo "Overwritten $OLD_FILE with $NEW_FILE (backup saved as .orig)" + ;; + R|r) + rm "$NEW_FILE" + echo "Removed $NEW_FILE" + ;; + *) + echo "Invalid choice, skipping..." + ;; + esac +done + +echo "Processing complete!" +