2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
24 set -e; .
/usr
/local
/lib
/bash-bear
; set +e
28 m
() { printf "$pre %s\n" "$*"; "$@"; }
29 e
() { printf "$pre %s\n" "$*"; }
30 err
() { printf "$pre %s\n" "$*" >&2; exit 1; }
32 local tmp tmpdir dest
="$1"
33 local base
="${dest##*/}"
34 local dir
="${dest%/*}"
35 if [[ $dir != "$base" ]]; then
36 # dest has a directory component
42 tmp
=$
(rsync
-ic $tmpdir/"$base" "$dest")
45 # shellcheck disable=SC2034
47 if [[ $dest == /etc
/systemd
/system
/* ]]; then
48 touch /var
/local
/mail-setup-reload
55 key
="$1" value
="$2" section
="$3"
56 file="/etc/radicale/config"
57 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
61 # ignore services that dont exist
62 if systemctl
cat $service &>/dev
/null
; then
63 m systemctl disable
--now $service
69 m systemctl restart
$service
70 m systemctl
enable $service;
79 domain
=boardfiles.fsf.org
81 apt-get
-y install php-zip apache2 php-fpm
83 fpm
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.4-fpm
84 phpver
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
86 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
87 # /etc/apache2/conf-enabled/php7.3-fpm.conf
89 # ERROR: Module php8.1 does not exist. just allow it to fail
90 m a2dismod php
$phpver ||
:
92 # php with fpm doesnt work without this
97 m web-conf
- apache2
$domain <<EOF
98 ### begin nextcloud settings
99 Alias /nextcloud "$ncdir/"
103 Options FollowSymLinks MultiViews
111 # based on install checker, links to
112 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
113 # their example was a bit wrong, I figured it out by adding
114 # LogLevel warn rewrite:trace5
115 # then watching the apache logs
118 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
119 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
120 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
121 ### end nextcloud settings
125 i
/etc
/php
/$phpver/cli
/conf.d
/30-local.ini
<<'EOF'
130 i
/etc
/php
/$phpver/fpm
/conf.d
/30-local.ini
<<'EOF'
131 date.timezone = "America/New_York"
133 upload_max_filesize = 2000M
134 post_max_size = 2000M
135 # install checker, nextcloud/settings/admin/overview
139 m systemctl restart
$fpm
141 # some of these are based on errors later on.
142 m apt-get
-y install php-curl php-bz2 php-gmp php-bcmath php-imagick php-apcu php-mbstring php-xml php-gd sqlite3 php-sqlite3
144 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
145 cat >/etc
/php
/$phpver/fpm
/pool.d
/localwww.conf
<<'EOF'
152 nextcloud_admin_pass
=casHiosidZyFraycs
155 if [[ ! -e $ncdir/index.php
]]; then
156 # if we wanted to only install a specific version, use something like
159 m wget
-nv -N https
://download.nextcloud.com
/server
/releases
/$file
163 m chown
-R www-data.www-data nextcloud
164 m
mv nextcloud
$ncdir
167 if [[ ! -e $myncdir/done-install
]]; then
169 m sudo
-u www-data php occ maintenance
:install --database sqlite
--admin-user iank
--admin-pass $nextcloud_admin_pass
170 m
touch $myncdir/done-install
173 # note, strange this happend where updater did not increment the version var,
174 # mine was stuck on 20. I manually updated it.
176 if [[ ! -e $myncdir/config.php-orig
]]; then
177 m
cp -a config.php
$myncdir/config.php-orig
179 cat $myncdir/config.php-orig
- >$myncdir/tmp.php
<<EOF
180 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
181 \$CONFIG["mail_smtpmode"] = "sendmail";
182 \$CONFIG["mail_smtphost"] = "127.0.0.1";
183 \$CONFIG["mail_smtpport"] = 25;
184 \$CONFIG["mail_smtptimeout"] = 10;
185 \$CONFIG["mail_smtpsecure"] = "";
186 \$CONFIG["mail_smtpauth"] = false;
187 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
188 \$CONFIG["mail_smtpname"] = "";
189 \$CONFIG["mail_smtppassword"] = "";
190 \$CONFIG["mail_domain"] = "$domain";
193 # based on installer check
194 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
195 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
197 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
198 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
199 \$CONFIG['trusted_domains'] = array (
203 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
204 var_export(\$CONFIG);
205 fwrite(STDOUT, ";\n");
207 e running php
$myncdir/tmp.php
208 # note: we leave it around place for debugging
209 php
$myncdir/tmp.php
>config.php
211 m sudo
-u www-data php occ maintenance
:update
:htaccess
212 i
/etc
/systemd
/system
/$ncbase.service
<<EOF
214 Description=ncup $ncbase
215 After=multi-user.target
219 ExecStart=/usr/local/bin/ncup $ncbase
221 IOSchedulingClass=idle
222 CPUSchedulingPolicy=idle
224 i
/etc
/systemd
/system
/$ncbase.timer
<<EOF
226 Description=ncup $ncbase timer
232 WantedBy=timers.target
234 systemctl
enable --now $ncbase.timer
235 i
/usr
/local
/bin
/ncup
<<'EOFOUTER'
238 set -e; . /usr/local/lib/bash-bear; set +e
240 m() { printf "%s\n" "$*"; "$@"; }
242 echo failed nextcloud update for $ncbase >&2
243 # -odf or else systemd will kill the background delivery process
244 # and the message will sit in the queue until the next queue run.
246 To: alerts@iankelling.org
247 From: www-data@$(hostname -f)
248 Subject: failed nextcloud update for $ncbase
250 For logs, run: jr -u $ncbase
254 if [[ $(id -u -n) != www-data ]]; then
255 echo error: running as wrong user: $(id -u -n), expected www-data
260 echo error: expected an arg, nextcloud relative base dir
266 # https://docs.nextcloud.com/server/22/admin_manual/maintenance/update.html?highlight=updater+phar
267 m php /var/www/$ncbase/updater/updater.phar -n
269 chmod +x
/usr
/local
/bin
/ncup
271 mkdir
-p /var
/www
/cron-errors
272 chown www-data.www-data
/var
/www
/cron-errors
273 i
/etc
/cron.d
/$ncbase <<EOF
274 PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/local/bin
276 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
277 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
281 m systemctl daemon-reload