Update simpleupdated
Reduce to check date every 30 seconds to ensure every minute is captured Added logging last 100 lines to /tmp/simpleupdate.log Configuration Validation: Ensures that only one update frequency setting is active and correctly defined, avoiding misconfigurations.
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define the configuration and directories
|
||||
# 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"
|
||||
@@ -17,9 +20,32 @@ else
|
||||
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 "Checking 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"
|
||||
@@ -40,13 +66,13 @@ check_for_updates() {
|
||||
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
|
||||
sleep 60 # Check every 60 seconds
|
||||
local current_time=$(date "+%H:%M")
|
||||
local current_day=$(date "+%a")
|
||||
local current_date=$(date "+%d")
|
||||
@@ -72,6 +98,8 @@ wait_to_update() {
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
sleep 30 # Sleep for 30 seconds for more granular checks
|
||||
trim_log_file
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user