diff options
author | mail_redacted_for_web | 2025-04-21 10:48:06 +0200 |
---|---|---|
committer | mail_redacted_for_web | 2025-04-21 10:48:06 +0200 |
commit | a1d30099aba6275fcfc81730debb4e903d1ae00d (patch) | |
tree | 3351a9beb433e2d23700d0c51a5d420d9f4ab404 /bin | |
parent | dee58e5561db333989aac950ef3ee1510d49ed14 (diff) | |
download | nextcloud-update-a1d30099aba6275fcfc81730debb4e903d1ae00d.tar.bz2 |
+ licence as markdown
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/nextcloud-update | 162 | ||||
-rwxr-xr-x | bin/nextcloud-upgrade | 2 |
2 files changed, 142 insertions, 22 deletions
diff --git a/bin/nextcloud-update b/bin/nextcloud-update index 47c0b7e..c01f75e 100755 --- a/bin/nextcloud-update +++ b/bin/nextcloud-update @@ -40,29 +40,149 @@ source /usr/lib/lirion/ln-initfunctions || exit 2 # called /usr/local/bin/nextcloud-*). # TODO: make update check decide on whether to update + +# Define help function +function hayulp { + printf 'USAGE: %b [-a|--app-update] [-c|--core-update] [-s|--status] [-u|--update-check]\n\n' "$(basename "$0")" + ( + printf -- '-a,\n' + printf -- '--app-update;Update all apps\n' + printf -- '-c,\n' + printf -- '--core-update;Update the Nextcloud core (including apps update)\n' + printf -- '-s,\n' + printf -- '--status;Status including version\n' + printf -- '-u,\n' + printf -- '--update-check;Status including update check\n' + printf -- '-h,\n' + printf -- '--help;This help text\n' + )|column -ts \; + printf '\n' +} + +# User variables: imperatives whether to do app/core updates, print status, print update check. +# See "PARSE: COMMAND LINE PARAMETERS" below. +NC_APPSUPD=0; NC_COREUPD=0; NC_STATDSP=0; NC_UPCHECK=0 +# Script-only variables: update available for apps/core? +NC_UA_APPS=0; NC_UA_CORE=0 +# doc/decl only: we have a variable called UPDVER for the available core update version +declare UPDVER + +##### PARSE: COMMAND LINE PARAMETERS ##### +while [[ $# -gt 0 ]]; do + case "$1" in + "-h"|"--help") + hayulp + exit 0 + # shift meaningless here: we exit + ;; + "-a"|"--app-update") + NC_APPSUPD=1 + shift + ;; + "-c"|"--core-update") + NC_COREUPD=1 + shift # past argument + # VALUE="$2" + # shift # past value + ;; + "-s"|"--status") + NC_STATDSP=1 + shift + ;; + "-u"|"--update-check") + NC_UPCHECK=1 + shift + ;; + "-"*) + hayulp + printf '\033[93mUnknown option: %b\033[0m\n' "$1" >&2 + exit 101 + ;; + esac +done + +if [[ "$NC_STATDSP" -eq 0 && "$NC_APPSUPD" -eq 0 && "$NC_COREUPD" -eq 0 && "$NC_UPCHECK" -eq 0 ]]; then + hayulp + printf '\033[93mNo action chosen, please read the help text above.\033[0m\n' >&2 + exit 255 +fi + sudo whoami > /dev/null || exit 2 -lnbegin "Checking for update" -# THis script always returns 0 - php yokerel, tee hee - so we need to parse. RC!=0 = script failed -# unexpectedly. -if ! UPDSTR="$(/usr/bin/sudo -u "$NCUSER" "$NCPHPBIN" "${NCAPPLDIR}/occ" update:check 2>&1)"; then - lnfail 'update check failed' - exit 10 + +##### EXEC: STATUS ##### +if [ "$NC_STATDSP" -eq 1 ]; then + printf '\033[1mStatus + version:\033[0m\n' + if [ -x "/usr/bin/jq" ]; then + /usr/bin/jq < <(/usr/bin/sudo -u "$NCUSER" "$NCPHPBIN" "${NCAPPLDIR}/occ" status --output='json') + else + /usr/bin/sudo -u "$NCUSER" "$NCPHPBIN" "${NCAPPLDIR}/occ" status --output='json_pretty' + fi fi -if ! /usr/bin/printf '%b' "$UPDSTR" | grep -P '^Nextcloud [0-9]+\..*is available' > /dev/null; then - lnok 'none available' +if [[ "$NC_APPSUPD" -eq 0 && "$NC_COREUPD" -eq 0 && "$NC_UPCHECK" -eq 0 ]]; then exit 0 -else - UPDVER="$(/usr/bin/printf '%b' "$UPDSTR" | grep -P '^Nextcloud [0-9]+\..*is available')" - UPDVER="$(printf '%b' "$UPDVER" | sed 's/.*extcloud[\ \t-]\([^\ \t]\+\).*/\1/')" - lnok "available: $UPDVER" fi -if [ "$(printf '%b' "$UPDVER" | wc -l)" -gt 0 ]; then - printf 'Not a single line: %b\n' "$NCVER" >&2 - exit 14 -elif [ "$(printf '%b' "$UPDVER" | wc -w)" -ne 1 ]; then - printf 'Not a single word: %b\n' "$NCVER" >&2 - exit 15 + +##### EXEC: UPDATE CHECK ##### +lnbegin "Performing update check" +if ! UPDSTR="$(/usr/bin/sudo -u "$NCUSER" "$NCPHPBIN" "${NCAPPLDIR}/occ" update:check --no-interaction 2>&1)"; then + # This script always returns 0 - php yokerel, tee hee - so we need to parse. RC!=0 = script failed + # unexpectedly. + # Yes, there is --format=json - and no, it does not work for update:check nor does it exist for something + # like update:check :-( + lnfail + exit 10 +fi +lnok +if [ "$NC_UPCHECK" -eq 1 ]; then + printf '%b\n' "$UPDSTR" +fi + +##### PARSE: CORE UPDATE AVAILABLE? ##### +# See "Performing update check" above... +if [ "$NC_COREUPD" -eq 1 ]; then + lnbegin "Parse: core update" + if ! /usr/bin/printf '%b' "$UPDSTR" | grep -P '^Nextcloud [0-9]+\..*is available' > /dev/null; then + lnok 'none available' + else + UPDVER="$(/usr/bin/printf '%b' "$UPDSTR" | grep -P '^Nextcloud [0-9]+\..*is available')" + UPDVER="$(printf '%b' "$UPDVER" | sed 's/.*extcloud[\ \t-]\([^\ \t]\+\).*/\1/')" + if [ "$(printf '%b' "$UPDVER" | wc -l)" -gt 0 ]; then + printf 'Not a single line: %b\n' "$NCVER" >&2 + exit 14 + elif [ "$(printf '%b' "$UPDVER" | wc -w)" -ne 1 ]; then + printf 'Not a single word: %b\n' "$NCVER" >&2 + exit 15 + fi + lnok "available: $UPDVER" + NC_UA_CORE=1 + fi +fi + +##### PARSE: APP UPDATE(S) AVAILABLE? ##### +# See "Performing update check" above... +if [ "$NC_APPSUPD" -eq 1 ]; then + lnbegin "Parse: apps updates" + # TODO: look at update:check again and see what to grep(!) for (again, the script doesn't deliver + # return codes, nor does the crappy output at least have a json flag + lnwarn "not yet implemented" +fi + + +##### NEXTCLOUD CORE DOWNLOAD ##### +if [[ "$NC_COREUPD" -eq 1 && "$NC_UA_CORE" -eq 1 ]]; then + /usr/local/bin/nextcloud-download "$UPDVER" || exit "$?" +fi +##### NEXTCLOUD INSTANCE BACKUP ##### +# This is the separate backup of DB and files mentioned at the top of the file. +if [[ "$NC_COREUPD" -eq 1 && "$NC_UA_CORE" -eq 1 ]]; then + /usr/bin/sudo /usr/local/bin/nextcloud-backup || exit "$?" +fi + +##### NEXTCLOUD UPDATES ##### +if [[ "$NC_COREUPD" -eq 1 || "$NC_APPSUPD" -eq 1 ]]; then + UPDCALL=( '/usr/local/bin/nextcloud-upgrade' ) + if [[ "$NC_COREUPD" -eq 1 && "$NC_UA_CORE" -eq 1 ]]; then + UPDCALL=( '-c' "$UPDVER" + fi fi -/usr/local/bin/nextcloud-download "$UPDVER" || exit "$?" -/usr/bin/sudo /usr/local/bin/nextcloud-backup || exit "$?" -/usr/local/bin/nextcloud-upgrade "$UPDVER" || exit "$?" +# /usr/local/bin/nextcloud-upgrade "$UPDVER" || exit "$?" diff --git a/bin/nextcloud-upgrade b/bin/nextcloud-upgrade index b805afd..c77182b 100755 --- a/bin/nextcloud-upgrade +++ b/bin/nextcloud-upgrade @@ -141,7 +141,7 @@ if ! /usr/bin/sudo -u "$NCUSER" "$NCPHPBIN" "${NCAPPLDIR}/occ" upgrade -q >/dev/ lnfail exit 146 fi -lnprog "occ app:update" +lnprog "occ app:update --all" if ! /usr/bin/sudo -u "$NCUSER" "$NCPHPBIN" "${NCAPPLDIR}/occ" app:update -q --all >/dev/null 2>&1; then lnfail "occ app:update" exit 147 |