From 2b1bdb2e5ac94ee2962219c4241b80eb3b60a27e Mon Sep 17 00:00:00 2001 From: Rufus King Date: Tue, 18 Aug 2026 00:40:45 -0400 Subject: [PATCH] Updated the nextcloud update script to correct for not updating issues --- Stocks/WebService/StocksWebservice URL | 1 + nextcloud/nextcloud_update_check.sh | 129 +++++++++++++++---------- 2 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 Stocks/WebService/StocksWebservice URL diff --git a/Stocks/WebService/StocksWebservice URL b/Stocks/WebService/StocksWebservice URL new file mode 100644 index 0000000..537d4d1 --- /dev/null +++ b/Stocks/WebService/StocksWebservice URL @@ -0,0 +1 @@ +http://localhost:5005/historical?ticker=SMERY&date=2025-07-31&key=90c2528e9b5221c110f7c2c9cd6c65dc diff --git a/nextcloud/nextcloud_update_check.sh b/nextcloud/nextcloud_update_check.sh index 9f0850a..06d7573 100644 --- a/nextcloud/nextcloud_update_check.sh +++ b/nextcloud/nextcloud_update_check.sh @@ -8,26 +8,16 @@ # Schedule: Daily (recommended 7:00 AM) # Install: /usr/scripts/omv/nextcloud_update_check.sh # Log: /var/log/nextcloud-updates/ -# -# 2026-07-24 fix: previously only checked `occ app:update --all -# --showonly`, which reports APP updates only. It never checked -# for a Nextcloud CORE/server version update, so a core release -# (e.g. Nextcloud 34.0.2) was silently missed and the report -# said "up to date" even when it wasn't. Added a separate core -# check via `occ update:check`. # ============================================================= # --- Config -------------------------------------------------- CONTAINER="nextcloud" OCC="sudo docker exec -u www-data ${CONTAINER} php occ" -# OMV Compose project location — NOT ~/docker/nextcloud. Confirmed via: -# docker inspect nextcloud --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}' -# Directory is root-only (drwx------ root root), so compose commands -# must run under sudo. OMV names its compose files ".yml" + -# "compose.override.yml" — NOT the default "docker-compose.yml" — so -# both -f flags are required or `docker compose` won't find them. NEXTCLOUD_COMPOSE_DIR="/kingdezignsnas/Docker/Compose/nextcloud" NEXTCLOUD_COMPOSE_FILES="-f nextcloud.yml -f compose.override.yml" +NEXTCLOUD_FFMPEG_BUILD_DIR="/kingdezignsnas/Docker/Compose/nextcloud-ffmpeg-build" +NEXTCLOUD_FFMPEG_BUILD_FILES="-f nextcloud-ffmpeg-build.yml --env-file nextcloud-ffmpeg-build.env" +NEXTCLOUD_PULL_SERVICES="db onlyoffice autoheal" SMTP_SERVER="smtppro.zoho.com" SMTP_PORT="465" SMTP_USER="rufus.king@kingdezigns.com" @@ -47,6 +37,30 @@ LOGFILE="$LOG_DIR/update-check-${DATESTAMP}.log" log() { echo "[$(date +"%H:%M:%S")] $*" | tee -a "$LOGFILE"; } +# Returns 0 when $1 is strictly newer than $2 (e.g. 34.0.3 > 34.0.2). +version_gt() { + local ver1=$1 ver2=$2 + [[ -n "$ver1" && -n "$ver2" ]] || return 1 + local IFS=. + local -a v1=($ver1) v2=($ver2) + local i n1 n2 + for ((i=0; i<${#v1[@]} || i<${#v2[@]}; i++)); do + n1=$((10#${v1[i]:-0})) + n2=$((10#${v2[i]:-0})) + if (( n1 > n2 )); then return 0; fi + if (( n1 < n2 )); then return 1; fi + done + return 1 +} + +# Adjusted to strip any "v" prefix or extra spaces cleanly +fetch_latest_github_release() { + curl -sf --max-time 20 "https://api.github.com/repos/nextcloud/server/releases/latest" \ + | grep -oE '"tag_name"[[:space:]]*:[[:space:]]*"v[0-9]+\.[0-9]+\.[0-9]+"' \ + | head -1 \ + | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' +} + # --- Load SMTP password -------------------------------------- if [[ ! -f "$SMTP_PASS_FILE" ]]; then log "ERROR: SMTP password file not found at $SMTP_PASS_FILE" @@ -57,7 +71,6 @@ SMTP_PASS=$(cat "$SMTP_PASS_FILE") # --- Check container is running ------------------------------ if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then log "ERROR: Container '${CONTAINER}' is not running." - # Send critical alert STATUS_COLOR="#b91c1c" STATUS_LABEL="CRITICAL" STATUS_MSG="⛔  Nextcloud container is not running" @@ -76,34 +89,54 @@ else log "Nextcloud version: $NC_VERSION | maintenance: $MAINTENANCE | needsDbUpgrade: $NEEDS_UPGRADE" # --- Check for CORE (server) update ------------------------- - # occ app:update only reports app updates, never core/server - # releases. occ update:check is the command that actually - # checks the updater channel for a new Nextcloud version. - log "Checking core (server) update..." + log "Checking core (server) update via occ update:check..." CORE_CHECK_RAW=$($OCC update:check 2>/dev/null | grep -v '^{') + log "occ update:check raw output:" + while IFS= read -r line; do + [[ -n "$line" ]] && log " $line" + done <<< "$CORE_CHECK_RAW" + CORE_UPDATE_AVAILABLE=false CORE_NEW_VERSION="" - if echo "$CORE_CHECK_RAW" | grep -qi "is available"; then + CORE_UPDATE_SOURCE="" + + if echo "$CORE_CHECK_RAW" | grep -qiE 'Nextcloud [0-9]+\.[0-9]+\.[0-9]+ is available'; then CORE_UPDATE_AVAILABLE=true - CORE_NEW_VERSION=$(echo "$CORE_CHECK_RAW" | grep -oE 'Nextcloud [0-9]+\.[0-9]+\.[0-9]+' | head -1 | awk '{print $2}') - log "Core update available: Nextcloud ${CORE_NEW_VERSION}" + CORE_NEW_VERSION=$(echo "$CORE_CHECK_RAW" | grep -oiE 'Nextcloud [0-9]+\.[0-9]+\.[0-9]+ is available' | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') + CORE_UPDATE_SOURCE="occ update:check" + log "Core update available (occ): Nextcloud ${CORE_NEW_VERSION}" + fi + + log "Checking core update via GitHub latest release fallback..." + GITHUB_LATEST=$(fetch_latest_github_release) + if [[ -n "$GITHUB_LATEST" ]]; then + log "GitHub latest stable release: ${GITHUB_LATEST} (installed: ${NC_VERSION})" + if version_gt "$GITHUB_LATEST" "$NC_VERSION"; then + if [[ "$CORE_UPDATE_AVAILABLE" != "true" ]] || version_gt "$GITHUB_LATEST" "$CORE_NEW_VERSION"; then + CORE_UPDATE_AVAILABLE=true + CORE_NEW_VERSION="$GITHUB_LATEST" + if [[ -z "$CORE_UPDATE_SOURCE" ]]; then + CORE_UPDATE_SOURCE="GitHub latest release (occ update:check lagged)" + else + CORE_UPDATE_SOURCE="${CORE_UPDATE_SOURCE} + GitHub latest release" + fi + log "Core update available (GitHub fallback): ${NC_VERSION} → ${CORE_NEW_VERSION}" + fi + fi else - log "Core is up to date." + log "WARN: Could not fetch GitHub latest release for fallback compare." fi # --- Check for app updates -------------------------------- log "Checking app updates..." - # Filter out admin_audit JSON log lines that appear when admin_audit app is enabled APP_UPDATE_RAW=$($OCC app:update --all --showonly 2>/dev/null | grep -v '^{' ) - # Parse apps with available updates - # Format from occ app:update --showonly: "appname new version available: X.Y.Z" UPDATABLE_APPS=() while IFS= read -r line; do if echo "$line" | grep -q "new version available"; then APP_NAME=$(echo "$line" | awk '{print $1}') NEW_VER=$(echo "$line" | awk '{print $NF}') - UPDATABLE_APPS+=("${APP_NAME}|||${NEW_VER}") + UPDATABLE_APPS+=("${APP_NAME}|${NEW_VER}") log "Update available: $APP_NAME → $NEW_VER" fi done <<< "$APP_UPDATE_RAW" @@ -152,7 +185,6 @@ else STATUS_MSG="✅  Nextcloud is fully up to date" fi - # --- Maintenance mode color (was previously unset/unused) -- if [[ "$MAINTENANCE" == "true" ]]; then MAINTENANCE_COLOR="#b91c1c" else @@ -164,7 +196,7 @@ else if [[ $APP_COUNT -gt 0 ]]; then for entry in "${UPDATABLE_APPS[@]}"; do APP_NAME=$(echo "$entry" | cut -d'|' -f1) - NEW_VER=$(echo "$entry" | cut -d'|' -f4) + NEW_VER=$(echo "$entry" | cut -d'|' -f2) APP_ROWS+=" ${APP_NAME} ${NEW_VER} @@ -181,25 +213,19 @@ else done # --- Build copy-paste command block ----------------------- - # NOTE: must use $'...' (ANSI-C quoting) below, not "...". Plain - # double quotes do NOT interpret \n as a newline in bash — they - # insert the two literal characters \ and n, which is why the - # previous version of this script emailed out commands with - # literal "\n" text instead of real line breaks. CMD_LINES="" if [[ "$MAINTENANCE" == "true" ]]; then CMD_LINES+=$'# Disable maintenance mode\nsudo docker exec -u www-data nextcloud php occ maintenance:mode --off\n\n' fi if [[ "$CORE_UPDATE_AVAILABLE" == "true" ]]; then - # The nextcloud image's own entrypoint auto-detects the version - # bump and runs the upgrade itself on container start — it does - # NOT need `occ upgrade` run manually. Running `occ upgrade` - # immediately after `up -d` can race the container's own startup - # and falsely report "No upgrade required" if checked too early. - # The 30s sleep gives the entrypoint's internal upgrade time to - # finish before the confirming `occ status` call. + # Corrected step to target the actual service container for your custom image CMD_LINES+="# Update Nextcloud CORE to ${CORE_NEW_VERSION} (do this before app updates)"$'\n' - CMD_LINES+="sudo bash -c \"cd ${NEXTCLOUD_COMPOSE_DIR} && docker compose ${NEXTCLOUD_COMPOSE_FILES} pull && docker compose ${NEXTCLOUD_COMPOSE_FILES} up -d\""$'\n\n' + CMD_LINES+="# Step 1: Rebuild nextcloud-ffmpeg from a fresh nextcloud:latest base"$'\n' + CMD_LINES+="sudo bash -c \"cd ${NEXTCLOUD_FFMPEG_BUILD_DIR} && docker compose ${NEXTCLOUD_FFMPEG_BUILD_FILES} build --no-cache --pull\""$'\n\n' + CMD_LINES+="# Step 2: Pull supporting services only (skip nextcloud/cron — local image)"$'\n' + CMD_LINES+="sudo bash -c \"cd ${NEXTCLOUD_COMPOSE_DIR} && docker compose ${NEXTCLOUD_COMPOSE_FILES} pull ${NEXTCLOUD_PULL_SERVICES}\""$'\n\n' + CMD_LINES+="# Step 3: Recreate containers to pick up the rebuilt image"$'\n' + CMD_LINES+="sudo bash -c \"cd ${NEXTCLOUD_COMPOSE_DIR} && docker compose ${NEXTCLOUD_COMPOSE_FILES} up -d\""$'\n\n' CMD_LINES+="# Give the container's built-in upgrade entrypoint time to finish,"$'\n' CMD_LINES+="# then confirm the new version is active (watch for versionstring: ${CORE_NEW_VERSION})"$'\n' CMD_LINES+="sleep 30"$'\n' @@ -221,7 +247,6 @@ else
${CMD_LINES}
" - # --- Maintenance/upgrade block ---------------------------- MAINT_BLOCK="" if [[ -n "$WARN_HTML" ]]; then MAINT_BLOCK="
@@ -230,9 +255,15 @@ else
" fi - # --- Core update block -------------------------------------- CORE_BLOCK="" if [[ "$CORE_UPDATE_AVAILABLE" == "true" ]]; then + CORE_SOURCE_NOTE="" + if [[ -n "$CORE_UPDATE_SOURCE" ]]; then + CORE_SOURCE_NOTE=" + Detected Via + ${CORE_UPDATE_SOURCE} + " + fi CORE_BLOCK="
🆙 Core Update Available
@@ -244,11 +275,12 @@ else + ${CORE_SOURCE_NOTE}
New Version ${CORE_NEW_VERSION}
+
This install uses a custom nextcloud-ffmpeg:latest image. The emailed commands rebuild that image first — do not run a plain docker compose pull in the main project.
" fi - # --- App update table ------------------------------------- APP_TABLE="" if [[ $APP_COUNT -gt 0 ]]; then APP_TABLE="
@@ -271,7 +303,6 @@ else BODY_HTML="${MAINT_BLOCK} -
Nextcloud Version ${NC_VERSION} @@ -284,7 +315,6 @@ else ${CMD_BLOCK}" fi -# --- Determine email subject --------------------------------- if [[ "$NEEDS_ACTION" == "true" ]]; then SUBJECT="[NAS08] Nextcloud — ${STATUS_LABEL} — Action Required" else @@ -293,7 +323,6 @@ fi log "Composing email: $SUBJECT" -# --- Build full HTML email ----------------------------------- HTML_EMAIL=$(cat < @@ -323,12 +352,12 @@ HTML_EMAIL=$(cat < - + ${BODY_HTML} - + Nextcloud Update Check  |  ${HOSTNAME_LABEL}  |  KingDezigns Infrastructure @@ -340,7 +369,6 @@ HTML_EMAIL=$(cat <