diff options
Diffstat (limited to 'bin/nextcloud-download')
-rwxr-xr-x | bin/nextcloud-download | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/nextcloud-download b/bin/nextcloud-download new file mode 100755 index 0000000..ae9c824 --- /dev/null +++ b/bin/nextcloud-download @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +[ -z "$1" ] && printf 'Usage: %b VERSION\n' "$(basename "$0")" >&2 && exit 101 +# shellcheck disable=SC1091 +source /etc/lirion/nextcloud.conf || exit 102 +# shellcheck disable=SC1091 +source /usr/lib/lirion/ln-initfunctions || exit 103 + +NCFILES=( + "nextcloud-${1}.tar.bz2.asc" + "nextcloud-${1}.tar.bz2.sha512" + "nextcloud-${1}.tar.bz2" +) + +#NCDLTMP="$(/usr/bin/sudo '-u' "$NCUSER" /usr/bin/mktemp '-d' '-p' '/tmp' 'ncupdate.XXXXXX')" || exit 110 +/usr/bin/sudo -u "$NCUSER" /usr/bin/install -d -v -m '0700' "$NCDLTMP" || exit 110 + +/usr/bin/sudo -u "$NCUSER" /usr/bin/rm -vf "${NCDLTMP}/nextcloud-${1}".{asc,sha512} || exit 111 +for tgtfile in "${NCFILES[@]}"; do + url="https://download.nextcloud.com/server/releases/${tgtfile}" + curlcont=( '/usr/bin/sudo' '-u' "$NCUSER" '/usr/bin/curl' '-#RL' '-C' '-' '-o' "${NCDLTMP}/${tgtfile}" "$url" ) + curlfull=( '/usr/bin/sudo' '-u' "$NCUSER" '/usr/bin/curl' '-#RL' '-o' "${NCDLTMP}/${tgtfile}" "$url" ) + # we cannot simply [ -e FILE ] here as we may not have access to the directory: + if /usr/bin/sudo -u "$NCUSER" /usr/bin/stat -c '%f' "${NCDLTMP}/${tgtfile}" >/dev/null 2>&1; then + printf 'File %b existing, continuing download:\n' "$tgtfile" + "${curlcont[@]}"; crval="$?" + case "$crval" in + 7|18|26|27|28|35|55|56|58|59|60|63|66|67|77|80|83|89|90|91|92|94|96) + sleep 3.14159 + if ! "${curlcont[@]}"; then + exit 112 + fi + ;; + 130) + exit "$crval" + ;; + 0) ;; + *) + /usr/bin/sudo '-u' "$NCUSER" /usr/bin/rm -vf "${NCDLTMP}/${tgtfile}" + "${curlfull[@]}" || exit 113 + ;; + esac + else + printf 'Downloading %b:\n' "$tgtfile" + "${curlfull[@]}" || exit 114 + fi +done +lnbegin "Verifying download" +lnprog 'GPG' +if ! /usr/bin/sudo -u "$NCUSER" /usr/bin/gpg --no-default-keyring --keyring /var/www/keyrings/nextcloud-security.gpg \ + --quiet --verify "${NCDLTMP}/nextcloud-${1}.tar.bz2.asc" "${NCDLTMP}/nextcloud-${1}.tar.bz2" 2>/dev/null +then + lnfail 'GPG failed' + exit 116 +fi +lnok +for tgtfile in "${NCFILES[@]}"; do + /usr/bin/sudo -u "$NCUSER" /usr/bin/cp -vp "${NCDLTMP}/${tgtfile}" "${NCDLTGT}/${tgtfile}" || exit 115 +done +#rm -rf "${NCDLTMP}/" || exit 115 |