From 9b9052843e093a6641cf6971510591c7a3a615eb Mon Sep 17 00:00:00 2001 From: Cameron Thompson <50184035+iamromulan@users.noreply.github.com> Date: Mon, 1 Apr 2024 00:36:06 -0400 Subject: [PATCH] Begin work on creating simpleupdates -New update system to handle automatic updates -work in progress --- simpleadmin/.rev | 1 + simplefirewall/.rev | 1 + simpleupdates/simpleupdated | 88 +++++++++++++++++++++ simpleupdates/systemd/simpleupdated.service | 10 +++ socat-at-bridge/.rev | 1 + tailscale/.rev | 1 + ttyd/.rev | 1 + 7 files changed, 103 insertions(+) create mode 100644 simpleadmin/.rev create mode 100644 simplefirewall/.rev create mode 100644 simpleupdates/simpleupdated create mode 100644 simpleupdates/systemd/simpleupdated.service create mode 100644 socat-at-bridge/.rev create mode 100644 tailscale/.rev create mode 100644 ttyd/.rev diff --git a/simpleadmin/.rev b/simpleadmin/.rev new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/simpleadmin/.rev @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/simplefirewall/.rev b/simplefirewall/.rev new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/simplefirewall/.rev @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/simpleupdates/simpleupdated b/simpleupdates/simpleupdated new file mode 100644 index 0000000..1359edc --- /dev/null +++ b/simpleupdates/simpleupdated @@ -0,0 +1,88 @@ +#!/bin/bash + +# Define the 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" + +# 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 + +# Function to check for updates +check_for_updates() { + echo "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 +} + +# 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") + + 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 + 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 diff --git a/simpleupdates/systemd/simpleupdated.service b/simpleupdates/systemd/simpleupdated.service new file mode 100644 index 0000000..0385975 --- /dev/null +++ b/simpleupdates/systemd/simpleupdated.service @@ -0,0 +1,10 @@ +[Unit] +Description=Simple Update Daemon +After=network.target + +[Service] +Type=simple +ExecStart=/usrdata/simpleupdates/simpleupdated + +[Install] +WantedBy=multi-user.target diff --git a/socat-at-bridge/.rev b/socat-at-bridge/.rev new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/socat-at-bridge/.rev @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/tailscale/.rev b/tailscale/.rev new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/tailscale/.rev @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/ttyd/.rev b/ttyd/.rev new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/ttyd/.rev @@ -0,0 +1 @@ +1 \ No newline at end of file