git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/bin/nextcloud-download
blob: ae9c824cc1f6fee6e79ce2f50834161a058079c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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