From 99716d722c440a87ce2c0651bba21d19cf434eb6 Mon Sep 17 00:00:00 2001 From: Cameron Thompson <50184035+iamromulan@users.noreply.github.com> Date: Wed, 10 Apr 2024 00:50:12 -0400 Subject: [PATCH] Delete simpleupdated --- simpleupdates/simpleupdated | 116 ------------------------------------ 1 file changed, 116 deletions(-) delete mode 100644 simpleupdates/simpleupdated diff --git a/simpleupdates/simpleupdated b/simpleupdates/simpleupdated deleted file mode 100644 index d745564..0000000 --- a/simpleupdates/simpleupdated +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash - -# Configuration and directories -CONFIG_FILE="/usrdata/simpleupdate/simpleupdate.conf" -GITUSER="iamromulan" -GITTREE="main" -DIRECTORIES=("simpleadmin" "socat-at-bridge" "simplefirewall" "tailscale" "ttyd") -BASE_URL="https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE" - -LOG_FILE="/tmp/simpleupdate.log" - -# Wait for the system to fully start -sleep 60 - -# Load configuration -if [[ -f "$CONFIG_FILE" ]]; then - source "$CONFIG_FILE" -else - echo "Configuration file not found." - exit 1 -fi - -# Redirect stdout and stderr to the log file -exec > >(tee -a "$LOG_FILE") 2>&1 - -# Function to trim the log file to the last 100 lines -trim_log_file() { - tail -n 100 "$LOG_FILE" > "$LOG_FILE.tmp" - mv "$LOG_FILE.tmp" "$LOG_FILE" -} - -# Validate only one update frequency is defined -frequency_count=0 -[[ "$UPDATE_FREQUENCY" == "daily" ]] && ((frequency_count++)) -[[ "$UPDATE_FREQUENCY" == "weekly" ]] && ((frequency_count++)) -[[ "$UPDATE_FREQUENCY" == "monthly" ]] && ((frequency_count++)) - -if [[ $frequency_count -gt 1 ]]; then - echo "Error: More than one update frequency is defined. Exiting." - exit 1 -elif [[ $frequency_count -eq 0 && "$UPDATE_FREQUENCY" != "none" ]]; then - echo "Error: No valid update frequency defined. Exiting." - exit 1 -fi - -# Function to check for updates -check_for_updates() { - echo "$(date): Checking for updates..." - for dir in "${DIRECTORIES[@]}"; do - local remote_rev=$(wget -qO- "$BASE_URL/$dir/.rev") - local local_rev_file="/usrdata/$dir/.rev" - - if [[ ! -f "$local_rev_file" ]]; then - echo "No local revision file found for $dir, skipping." - continue - fi - - local local_rev=$(cat "$local_rev_file") - - if [[ "$remote_rev" -gt "$local_rev" ]]; then - echo "Update available for $dir, updating..." - wget -qO "/tmp/update_${dir}.sh" "$BASE_URL/simpleupdates/scripts/update_${dir}.sh" - chmod +x "/tmp/update_${dir}.sh" - "/tmp/update_${dir}.sh" - else - echo "$dir is up to date." - fi - done - trim_log_file -} - -# Function to wait and trigger updates based on scheduling -wait_to_update() { - echo "Waiting for the next update check according to schedule..." - while true; do - local current_time=$(date "+%H:%M") - local current_day=$(date "+%a") - local current_date=$(date "+%d") - - case $UPDATE_FREQUENCY in - daily) - if [[ "$current_time" == "$SCHEDULED_TIME" ]]; then - check_for_updates - fi - ;; - weekly) - if [[ "$current_day" == "$WEEKLY_DAY" && "$current_time" == "$SCHEDULED_TIME" ]]; then - check_for_updates - fi - ;; - monthly) - if [[ "$current_date" == "$MONTHLY_DATE" && "$current_time" == "$SCHEDULED_TIME" ]]; then - check_for_updates - fi - ;; - none) - echo "Update checking is disabled by frequency setting." - exit 0 - ;; - esac - sleep 30 # Sleep for 30 seconds for more granular checks - trim_log_file - done -} - -# Main logic -if [[ "$CONF_ENABLED" == "no" ]]; then - echo "Updates are disabled in the configuration." - exit 0 -fi - -if [[ "$CHECK_AT_BOOT" == "yes" ]]; then - check_for_updates -else - wait_to_update -fi