git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/bin/nextcloud-pharupdate
blob: b05404df1b2f2b2e60b7dbfb0897b4915d8f791e (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash

# This will not be maintained anymore. It's an older script entirely relying
# on updater.phar - and I'm not happy with the latter, so I've integrated this
# into my conf file construct, also for cutover to the new scripts, and then
# be abandoned once production can 100% rely on the new scripts.

# shellcheck disable=SC1091
source /etc/lirion/nextcloud.conf || exit 1

COREUP=0
APPSUP=0
NCSTATUS=0
UPDCHECK=0
[ -n "$COLUMNS" ] && MYCOLS="$COLUMNS"
[ -z "$MYCOLS" ] && MYCOLS="$(tput cols 2>/dev/null)"
[ -z "$MYCOLS" ] && MYCOLS="32"
function dashprint {
	printf "\\033[;1m"
	for (( i=0; i<MYCOLS; ++i ));do
		printf "-"
	done
	printf "\\033[0m\\n"
}
function hayulp {
	printf "USAGE: %b [-a] [-c] [-s] [-u]\\n" "$(basename "$0")"
	(
		printf -- "-a:;Update all apps\\n"
		printf -- "-c:;Update the Nextcloud core\\n"
		printf -- "-s:;Status including version\\n"
		printf -- "-u:;Status including update check\\n"
		printf -- "-h:;This help text\\n"
	)|column -ts \;
}
while getopts :cahsu SHOPT;do
	# shellcheck disable=SC2220
	case "$SHOPT" in
		c) COREUP=1;;
		a) APPSUP=1;;
		s) NCSTATUS=1;;
		u) UPDCHECK=1;;
		h)hayulp;exit 0;;
	esac
done
if [ "$COREUP" -eq 1 ] || [ "$APPSUP" -eq 1 ];then
	sudo stat -tL "${NCAPPLDIR}" >/dev/null 2>&1 || exit 101
fi
if [ "$NCSTATUS" -eq 1 ];then
	sudo -u "${NCUSER}" "$NCPHPBIN" "${NCAPPLDIR}/occ" status
	MYRET="$?"
	[ "$MYRET" -ne 0 ] && exit "$MYRET"
	if [ "$UPDCHECK" -eq 1 ];then
		sudo -u "${NCUSER}" "$NCPHPBIN" "${NCAPPLDIR}/occ" update:check
	fi
	if [ "$COREUP" -eq 1 ] || [ "$APPSUP" -eq 1 ];then
		printf "\\nYou selected the status action, not proceeding with updates.\\n"
		exit 255
	fi
	exit "$MYRET"
fi
if [ "$UPDCHECK" -eq 1 ];then
	sudo -u "${NCUSER}" "$NCPHPBIN" "${NCAPPLDIR}/occ" update:check
fi
if [ "$COREUP" -eq 1 ];then
	dashprint
	printf "\\033[1mupdater/updater.phar\\033[0m\\n"
	sudo -u "${NCUSER}" "$NCPHPBIN" "${NCAPPLDIR}/updater/updater.phar" || exit 1
	dashprint
fi
if [ "$APPSUP" -eq 1 ];then
	printf "\\033[1mocc app:update --all\\033[0m\\n"
	sudo -u "${NCUSER}" "$NCPHPBIN" "${NCAPPLDIR}/occ" app:update --all || exit 2
	# NC 29+: Now there's a message if no updates could be found. Commenting out the following:
	# printf "\\033[96mDone.\\033[0m\\n"
	dashprint
fi
if [ "$COREUP" -eq 1 ] || [ "$APPSUP" -eq 1 ];then
	printf "\\033[1mocc db:add-missing-primary-keys\\033[0m\\n"
	sudo -u "${NCUSER}" "$NCPHPBIN" "${NCAPPLDIR}/occ" db:add-missing-primary-keys || exit 3
	dashprint
	printf "\\033[1mocc db:add-missing-columns\\033[0m\\n"
	sudo -u "${NCUSER}" "$NCPHPBIN" "${NCAPPLDIR}/occ" db:add-missing-columns || exit 4
	printf "\\033[1m-------------------------------\\033[0m\\n"
	printf "\\033[1mocc db:add-missing-indices\\033[0m\\n"
	sudo -u "${NCUSER}" "$NCPHPBIN" "${NCAPPLDIR}/occ" db:add-missing-indices || exit 5
	printf "\\033[96mDone.\\033[0m\\n"
	dashprint
	printf "\\033[1mcron.php\\033[0m\\n"
	sudo -u "${NCUSER}" "$NCPHPBIN" -f "${NCAPPLDIR}/cron.php" || exit 6
	printf "\\033[96mDone.\\033[0m\\n"
	dashprint
fi
if [ "$COREUP" -eq 0 ] && [ "$APPSUP" -eq 0 ] && [ "$NCSTATUS" -eq 0 ] && [ "$UPDCHECK" -eq 0 ];then
	hayulp
	printf "\\nNo option specified.\\n" >&2
	exit 101
fi