From 33ee5f56af40ce4eb7d32021a4a8f43e09146c76 Mon Sep 17 00:00:00 2001 From: Tomi Eckert Date: Wed, 10 Sep 2025 11:57:06 +0200 Subject: [PATCH] update installer --- clean.sh | 29 +++++++++ install.sh | 177 +++++++++++++++++++++++++++------------------------- packages.sh | 14 +++++ 3 files changed, 134 insertions(+), 86 deletions(-) create mode 100644 clean.sh create mode 100644 packages.sh diff --git a/clean.sh b/clean.sh new file mode 100644 index 0000000..4caf937 --- /dev/null +++ b/clean.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Check if any arguments were provided +if [ "$#" -eq 0 ]; then + echo "Usage: $0 : [: ...]" + exit 1 +fi + +# Loop through each argument provided +for ARG in "$@"; do + # Split the argument at the first colon + IFS=':' read -r RETENTION_DAYS TARGET_DIR <<< "$ARG" + + # Validate that both a retention period and a path were provided + if [ -z "$RETENTION_DAYS" ] || [ -z "$TARGET_DIR" ]; then + echo "Invalid format for argument: $ARG. Please use the format :" + continue + fi + + echo "Starting cleanup of files older than $RETENTION_DAYS days in $TARGET_DIR..." + + # Use find to locate and delete files, handling potential errors + find "$TARGET_DIR" -type f -mtime +"$RETENTION_DAYS" -delete -print || echo "Could not process $TARGET_DIR. Check permissions." + + echo "Cleanup complete for $TARGET_DIR." + echo "--------------------------------------------------" +done + +echo "All cleanup tasks finished." \ No newline at end of file diff --git a/install.sh b/install.sh index fa3c22c..4d1db1d 100644 --- a/install.sh +++ b/install.sh @@ -1,22 +1,27 @@ #!/bin/bash -# --- Configuration --- -# Define script packages. The key is the name that will appear in the menu. -# The value is a space-separated string of all the URLs to download for that package. -declare -A SCRIPT_PACKAGES - -SCRIPT_PACKAGES["Aurora Suite"]="https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.conf" -SCRIPT_PACKAGES["Backup Suite"]="https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.conf" -SCRIPT_PACKAGES["Key Manager"]="https://git.technopunk.space/tomi/Scripts/raw/branch/main/hdb_keymanager.sh" -# Example: To add another single script later, just add a new line: -# SCRIPT_PACKAGES["My Other Script"]="https://path/to/my-other-script.sh" - - # --- Main Script --- +# Generate a unique temporary filename with a timestamp +conf_file="packages.conf.$(date +%Y%m%d%H%M%S)" + +# Set up a trap to delete the temporary file on exit, regardless of how the script ends +trap 'rm -f "${conf_file}"' EXIT + +# Download the configuration file before sourcing it. +echo "🔄 Downloading configuration file '${conf_file}'..." +if ! curl -fsSL -o "${conf_file}" "https://git.technopunk.space/tomi/Scripts/raw/branch/main/packages.conf"; then + echo "❌ Error: Failed to download packages.conf. Exiting." + exit 1 +fi +echo "✅ Configuration file downloaded successfully." + +# Source the configuration file to load the SCRIPT_PACKAGES array. +source "${conf_file}" + # Welcome message echo "-------------------------------------" -echo " Script Downloader " +echo "        Script Downloader            " echo "-------------------------------------" # Create an array of options from the package names (the keys of our map) @@ -28,79 +33,79 @@ PS3="Please enter the number of the script/package you want to download: " # Display the menu and handle user input select choice in "${options[@]}"; do - case "${choice}" in - "Quit") - echo "👋 Exiting." - break - ;; - *) - # Check if the user's choice is a valid package name - if [[ -n "${SCRIPT_PACKAGES[$choice]}" ]]; then - echo - echo "⬇️ Downloading package: '${choice}'..." - - # Get the space-separated list of URLs for the chosen package - urls_to_download="${SCRIPT_PACKAGES[$choice]}" +    case "${choice}" in +        "Quit") +            echo "👋 Exiting." +            break +            ;; +        *) +            # Check if the user's choice is a valid package name +            if [[ -n "${SCRIPT_PACKAGES[$choice]}" ]]; then +                echo +                echo "⬇️  Downloading package: '${choice}'..." +                 +                # Get the space-separated list of URLs for the chosen package +                urls_to_download="${SCRIPT_PACKAGES[$choice]}" - # Loop through each URL in the list and download the file - for url in $urls_to_download; do - filename=$(basename "${url}") - # If it's a .conf file AND it already exists, ask to overwrite. - if [[ "${filename}" == *.conf && -f "${filename}" ]]; then - echo " -> Found existing config file: '${filename}'." - # Create a temporary file to download the new version for comparison - tmp_file=$(mktemp) +                # Loop through each URL in the list and download the file +                for url in $urls_to_download; do +                    filename=$(basename "${url}") +                    # If it's a .conf file AND it already exists, ask to overwrite. +                    if [[ "${filename}" == *.conf && -f "${filename}" ]]; then +                        echo "   -> Found existing config file: '${filename}'." +                        # Create a temporary file to download the new version for comparison +                        tmp_file=$(mktemp) - # Download the new version silently to the temp file - if curl -fsSL -o "${tmp_file}" "${url}"; then - echo " 🔎 Comparing versions..." - echo "-------------------- DIFF START --------------------" - # Show a colorized diff if 'colordiff' is available, otherwise use regular 'diff' - if command -v colordiff &> /dev/null; then - colordiff -u "${filename}" "${tmp_file}" - else - diff --color=always -u "${filename}" "${tmp_file}" - fi - echo "--------------------- DIFF END ---------------------" - - # Ask the user for confirmation before overwriting - read -p "Do you want to overwrite '${filename}'? (y/N) " -n 1 -r REPLY - echo # Move to a new line for cleaner output +                        # Download the new version silently to the temp file +                        if curl -fsSL -o "${tmp_file}" "${url}"; then +                            echo "   🔎 Comparing versions..." +                            echo "-------------------- DIFF START --------------------" +                            # Show a colorized diff if 'colordiff' is available, otherwise use regular 'diff' +                            if command -v colordiff &> /dev/null; then +                                colordiff -u "${filename}" "${tmp_file}" +                            else +                                diff --color=always -u "${filename}" "${tmp_file}" +                            fi +                            echo "--------------------- DIFF END ---------------------" +                             +                            # Ask the user for confirmation before overwriting +                            read -p "Do you want to overwrite '${filename}'? (y/N) " -n 1 -r REPLY +                            echo # Move to a new line for cleaner output - if [[ $REPLY =~ ^[Yy]$ ]]; then - mv "${tmp_file}" "${filename}" - echo " ✅ Updated '${filename}'." - else - rm "${tmp_file}" - echo " 🤷 Kept existing version of '${filename}'." - fi - else - echo " ❌ Error: Failed to download new version of '${filename}' for comparison." - # Clean up the temp file on failure - rm -f "${tmp_file}" - fi - else - # Original download logic for all other files (or new .conf files) - echo " -> Downloading '${filename}'..." - if curl -fsSL -o "${filename}" "${url}"; then - echo " ✅ Successfully downloaded '${filename}'." - # If the downloaded file is a shell script, make it executable - if [[ "${filename}" == *.sh ]]; then - chmod +x "${filename}" - echo " 🤖 Made '${filename}' executable." - fi - else - echo " ❌ Error: Failed to download '${filename}'." - fi - fi - done - echo - echo "📦 Package download complete." - break - else - # The user entered an invalid number - echo "Invalid selection. Please try again." - fi - ;; - esac -done \ No newline at end of file +                            if [[ $REPLY =~ ^[Yy]$ ]]; then +                                mv "${tmp_file}" "${filename}" +                                echo "   ✅ Updated '${filename}'." +                            else +                                rm "${tmp_file}" +                                echo "   🤷 Kept existing version of '${filename}'." +                            fi +                        else +                            echo "   ❌ Error: Failed to download new version of '${filename}' for comparison." +                            # Clean up the temp file on failure +                            rm -f "${tmp_file}" +                        fi +                    else +                        # Original download logic for all other files (or new .conf files) +                        echo "   -> Downloading '${filename}'..." +                        if curl -fsSL -o "${filename}" "${url}"; then +                            echo "   ✅ Successfully downloaded '${filename}'." +                            # If the downloaded file is a shell script, make it executable +                            if [[ "${filename}" == *.sh ]]; then +                                chmod +x "${filename}" +                                echo "   🤖 Made '${filename}' executable." +                            fi +                        else +                            echo "   ❌ Error: Failed to download '${filename}'." +                        fi +                    fi +                done +                echo +                echo "📦 Package download complete." +                break +            else +                # The user entered an invalid number +                echo "Invalid selection. Please try again." +            fi +            ;; +    esac +done diff --git a/packages.sh b/packages.sh new file mode 100644 index 0000000..bf7a8e3 --- /dev/null +++ b/packages.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# This file contains the configuration for the script downloader. +# The `SCRIPT_PACKAGES` associative array maps a package name to a +# space-separated list of URLs to download. + +declare -A SCRIPT_PACKAGES + +SCRIPT_PACKAGES["Aurora Suite"]="https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.conf" +SCRIPT_PACKAGES["Backup Suite"]="https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.conf" +SCRIPT_PACKAGES["Key Manager"]="https://git.technopunk.space/tomi/Scripts/raw/branch/main/hdb_keymanager.sh" +SCRIPT_PACKAGES["File Cleaner"]="https://git.technopunk.space/tomi/Scripts/raw/branch/main/clean.sh" +# Example: To add another single script later, just add a new line: +# SCRIPT_PACKAGES["My Other Script"]="https://path/to/my-other-script.sh"