-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcheck_manual_updates.sh
executable file
·144 lines (117 loc) · 5.72 KB
/
check_manual_updates.sh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
apps=""
if [ -f /etc/debian_version ]; then
if apt-cache policy nginx | grep -q 'http://nginx.org'; then
nginx_installed=$(aptitude versions nginx | grep '^i' | awk '{print $2}')
if [ -n "$nginx_installed" ] ; then
apps="$apps nginx"
nginx_installed_major=$(echo "$nginx_installed" | cut -f1,2 -d'.')
nginx_latest=$(aptitude versions nginx | awk '{print $2}' | grep "^$nginx_installed_major" | tail -n 1)
if [ -n "$nginx_latest" ] && [[ "$nginx_latest" > "$nginx_installed" ]]; then
echo "WARNING : Nginx $nginx_installed is installed, but $nginx_latest is available."
exit 1
fi
fi
fi
fi
if [ -f /usr/local/ispconfig/server/lib/config.inc.php ]; then
apps="$apps ispconfig"
ispconfig_installed=$(php -r "require_once '/usr/local/ispconfig/server/lib/config.inc.php'; print(ISPC_APP_VERSION);")
if ispconfig_latest=$(curl -s https://www.ispconfig.org/downloads/ispconfig3_version.txt); then
if [[ "$ispconfig_latest" > "$ispconfig_installed" ]]; then
echo "WARNING : ISPConfig $ispconfig_installed is installed, but $ispconfig_latest is available."
exit 1
fi
else
echo "UNKNOWN : Unable to retrieve ISPConfig latest version."
exit 3
fi
fi
gitea_exe=$(pgrep -a gitea | cut -d ' ' -f 2)
if [ -f "$gitea_exe" ]; then
apps="$apps gitea"
gitea_installed=$($gitea_exe -v | awk '{print $3}')
gitea_latest=$(curl -sL https://dl.gitea.io/gitea/version.json | jq -r '.latest.version')
if [[ "$gitea_latest" > "$gitea_installed" ]]; then
echo "WARNING : Gitea $gitea_installed is installed, but $gitea_latest is available."
exit 1
fi
fi
gogs_exe=$(pgrep -a gogs | cut -d ' ' -f 2)
if [ -f "$gogs_exe" ]; then
echo "WARNING : Gogs found on $gogs_exe. Please upgrade to gitea."
exit 1
fi
if [ -f /srv/.nextcloud/version.php ]; then
apps="$apps nextcloud"
# :TODO:maethor:20230815: Do not hardcode php8.2
if [ -e "/usr/bin/php8.3" ] ; then
php="php8.3"
elif [ -e "/usr/bin/php8.2" ] ; then
php="php8.2"
else
echo "WARNING : Nextcloud needs at least php8.2."
exit 1
fi
#if ! nextcloud_domain="$(grep url /srv/.nextcloud/config/config.php | cut -d "'" -f 4 | cut -d '/' -f 3)"; then
nextcloud_domain=$($php -r "require_once '/srv/.nextcloud/config/config.php'; print(\$CONFIG['trusted_domains']['0']);")
if [ -z "$nextcloud_domain" ]; then
echo "WARNING : Could not find nextcloud domain in config.php."
exit 1
fi
# :COMMENT:maethor:20230815: We do not have nextcloud on apache
if ! nextcloud_vhost="$(grep -Rl "server_name .*$nextcloud_domain" /etc/nginx/sites-enabled)"; then
echo "WARNING : Could not find nextcloud $nextcloud_domain vhost config."
exit 1
fi
if ! nextcloud_php="$(grep -Eo 'php[0-9]\.[0-9]-fpm' "$nextcloud_vhost")"; then
echo "WARNING : Could not find nextcloud PHP version in $nextcloud_vhost."
exit 1
fi
if [ "$nextcloud_php" != "php8.2-fpm" ] && [ "$nextcloud_php" != "php8.3-fpm" ]; then
echo "WARNING : Nextcloud running on $nextcloud_php instead of php8.2-fpm or php8.3-fpm."
exit 1
fi
nextcloud_installed=$(/usr/bin/$php -r "require_once '/srv/.nextcloud/version.php'; print(\$OC_VersionString);")
php_full_version=$(/usr/bin/$php -v | head -1 | awk '{print $2}' | sed 's/\./x/g')
nextcloud_call_updater=$(curl -s -A "Nextcloud Updater" https://updates.nextcloud.com/updater_server/?version="${nextcloud_installed//\./x}"x1xxxstablexx2022-04-21T15:41:38+00:00%203d4015ae4dc079d1a2be0d3a573edef20264d701x"$php_full_version")
nextcloud_latest=$(echo "$nextcloud_call_updater" | grep "<version>" | sed 's/..version.//g' | awk -F '.' '{print $1,".",$2,".",$3}' | sed 's/ //g')
if [[ "$nextcloud_latest" > "$nextcloud_installed" ]]; then
echo "WARNING : Nextcloud $nextcloud_installed is installed, but $nextcloud_latest is available."
exit 1
fi
fi
if [ -f /srv/.snappymail/data/VERSION ]; then
apps="$apps snappymail"
snappymail_installed="v$(cat /srv/.snappymail/data/VERSION)"
snappymail_latest=$(curl https://api.github.com/repos/the-djmaze/snappymail/releases/latest -s | jq .name -r)
if [[ "$snappymail_latest" > "$snappymail_installed" ]]; then
echo "WARNING : Snappymail $snappymail_installed is installed, but $snappymail_latest is available."
exit 1
fi
fi
if repmgr_installed=$(sudo -u postgres repmgr --version 2>&1); then
repmgr_running=$(sudo -u postgres psql -A -t -d repmgr -c "select extversion from pg_extension where extname='repmgr';")
if [ -n "$repmgr_running" ]; then
repmgr_installed=$(echo "$repmgr_installed" | cut -d ' ' -f 2 | cut -d '.' -f 1-2)
if [ "$repmgr_running" != "$repmgr_installed" ]; then
echo "WARNING : Repmgr extension $repmgr_running is loaded, but $repmgr_installed is installed."
echo "Please run \`sudo -u postgres psql repmgr -c 'ALTER EXTENSION repmgr UPDATE'\`"
exit 1
fi
fi
fi
if [ -f "/srv/metabase/metabase.jar" ]; then
apps="$apps metabase"
metabase_installed=$(sudo -u metabase unzip -p /srv/metabase/metabase.jar version.properties | grep 'tag=' | cut -d '=' -f 2)
metabase_latest=$(curl https://api.github.com/repos/metabase/metabase/releases/latest -s | jq .tag_name -r)
if [[ "$metabase_latest" > "$metabase_installed" ]]; then
echo "WARNING : Metabase $metabase_installed is installed, but $metabase_latest is available."
exit 1
fi
fi
if [ -n "$apps" ]; then
echo "OK : Everything is up to date ($apps)"
else
echo "OK : No manual updated app detected"
fi