3 set -e; .
/usr
/local
/lib
/bash-bear
; set +e
7 m
() { printf "$pre %s\n" "$*"; "$@"; }
8 e
() { printf "$pre %s\n" "$*"; }
9 err
() { printf "$pre %s\n" "$*" >&2; exit 1; }
11 local tmp tmpdir dest
="$1"
12 local base
="${dest##*/}"
13 local dir
="${dest%/*}"
14 if [[ $dir != "$base" ]]; then
15 # dest has a directory component
21 tmp
=$
(rsync
-ic $tmpdir/"$base" "$dest")
24 # shellcheck disable=SC2034
26 if [[ $dest == /etc
/systemd
/system
/* ]]; then
27 touch /var
/local
/mail-setup-reload
34 key
="$1" value
="$2" section
="$3"
35 file="/etc/radicale/config"
36 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
40 # ignore services that dont exist
41 if systemctl
cat $service &>/dev
/null
; then
42 m systemctl disable
--now $service
48 m systemctl restart
$service
49 m systemctl
enable $service;
58 domain
=boardfiles.fsf.org
60 apt-get
-y install php-zip apache2 php-fpm
62 fpm
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.4-fpm
63 phpver
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
65 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
66 # /etc/apache2/conf-enabled/php7.3-fpm.conf
68 # ERROR: Module php8.1 does not exist. just allow it to fail
69 m a2dismod php
$phpver ||
:
71 # php with fpm doesnt work without this
76 m web-conf
- apache2
$domain <<EOF
77 ### begin nextcloud settings
78 Alias /nextcloud "$ncdir/"
82 Options FollowSymLinks MultiViews
90 # based on install checker, links to
91 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
92 # their example was a bit wrong, I figured it out by adding
93 # LogLevel warn rewrite:trace5
94 # then watching the apache logs
97 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
98 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
99 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
100 ### end nextcloud settings
104 i
/etc
/php
/$phpver/cli
/conf.d
/30-local.ini
<<'EOF'
109 i
/etc
/php
/$phpver/fpm
/conf.d
/30-local.ini
<<'EOF'
110 date.timezone = "America/New_York"
112 upload_max_filesize = 2000M
113 post_max_size = 2000M
114 # install checker, nextcloud/settings/admin/overview
118 m systemctl restart
$fpm
120 # some of these are based on errors later on.
121 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
123 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
124 cat >/etc
/php
/$phpver/fpm
/pool.d
/localwww.conf
<<'EOF'
131 nextcloud_admin_pass
=casHiosidZyFraycs
134 if [[ ! -e $ncdir/index.php
]]; then
135 # if we wanted to only install a specific version, use something like
138 m wget
-nv -N https
://download.nextcloud.com
/server
/releases
/$file
142 m chown
-R www-data.www-data nextcloud
143 m
mv nextcloud
$ncdir
146 if [[ ! -e $myncdir/done-install
]]; then
148 m sudo
-u www-data php occ maintenance
:install --database sqlite
--admin-user iank
--admin-pass $nextcloud_admin_pass
149 m
touch $myncdir/done-install
152 # note, strange this happend where updater did not increment the version var,
153 # mine was stuck on 20. I manually updated it.
155 if [[ ! -e $myncdir/config.php-orig
]]; then
156 m
cp -a config.php
$myncdir/config.php-orig
158 cat $myncdir/config.php-orig
- >$myncdir/tmp.php
<<EOF
159 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
160 \$CONFIG["mail_smtpmode"] = "sendmail";
161 \$CONFIG["mail_smtphost"] = "127.0.0.1";
162 \$CONFIG["mail_smtpport"] = 25;
163 \$CONFIG["mail_smtptimeout"] = 10;
164 \$CONFIG["mail_smtpsecure"] = "";
165 \$CONFIG["mail_smtpauth"] = false;
166 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
167 \$CONFIG["mail_smtpname"] = "";
168 \$CONFIG["mail_smtppassword"] = "";
169 \$CONFIG["mail_domain"] = "$domain";
172 # based on installer check
173 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
174 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
176 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
177 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
178 \$CONFIG['trusted_domains'] = array (
182 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
183 var_export(\$CONFIG);
184 fwrite(STDOUT, ";\n");
186 e running php
$myncdir/tmp.php
187 # note: we leave it around place for debugging
188 php
$myncdir/tmp.php
>config.php
190 m sudo
-u www-data php occ maintenance
:update
:htaccess
191 i
/etc
/systemd
/system
/$ncbase.service
<<EOF
193 Description=ncup $ncbase
194 After=multi-user.target
198 ExecStart=/usr/local/bin/ncup $ncbase
200 IOSchedulingClass=idle
201 CPUSchedulingPolicy=idle
203 i
/etc
/systemd
/system
/$ncbase.timer
<<EOF
205 Description=ncup $ncbase timer
211 WantedBy=timers.target
213 systemctl
enable --now $ncbase.timer
214 i
/usr
/local
/bin
/ncup
<<'EOFOUTER'
217 set -e; . /usr/local/lib/bash-bear; set +e
219 m() { printf "%s\n" "$*"; "$@"; }
221 echo failed nextcloud update for $ncbase >&2
222 # -odf or else systemd will kill the background delivery process
223 # and the message will sit in the queue until the next queue run.
225 To: alerts@iankelling.org
226 From: www-data@$(hostname -f)
227 Subject: failed nextcloud update for $ncbase
229 For logs, run: jr -u $ncbase
233 if [[ $(id -u -n) != www-data ]]; then
234 echo error: running as wrong user: $(id -u -n), expected www-data
239 echo error: expected an arg, nextcloud relative base dir
245 # https://docs.nextcloud.com/server/22/admin_manual/maintenance/update.html?highlight=updater+phar
246 m php /var/www/$ncbase/updater/updater.phar -n
248 chmod +x
/usr
/local
/bin
/ncup
250 mkdir
-p /var
/www
/cron-errors
251 chown www-data.www-data
/var
/www
/cron-errors
252 i
/etc
/cron.d
/$ncbase <<EOF
253 PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/local/bin
255 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
256 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
260 m systemctl daemon-reload