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")
25 if [[ $dest == /etc
/systemd
/system
/* ]]; then
26 touch /var
/local
/mail-setup-reload
33 key
="$1" value
="$2" section
="$3"
34 file="/etc/radicale/config"
35 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
39 # ignore services that dont exist
40 if systemctl
cat $service &>/dev
/null
; then
41 m systemctl disable
--now $service
47 m systemctl restart
$service
48 m systemctl
enable $service;
57 domain
=boardfiles.fsf.org
59 apt-get
-y install php-zip apache2 php-fpm
61 fpm
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.4-fpm
62 phpver
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
64 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
65 # /etc/apache2/conf-enabled/php7.3-fpm.conf
67 # ERROR: Module php8.1 does not exist. just allow it to fail
68 m a2dismod php
$phpver ||
:
70 # php with fpm doesnt work without this
75 m web-conf
- apache2
$domain <<EOF
76 ### begin nextcloud settings
77 Alias /nextcloud "$ncdir/"
81 Options FollowSymLinks MultiViews
89 # based on install checker, links to
90 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
91 # their example was a bit wrong, I figured it out by adding
92 # LogLevel warn rewrite:trace5
93 # then watching the apache logs
96 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
97 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
98 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
99 ### end nextcloud settings
103 i
/etc
/php
/$phpver/cli
/conf.d
/30-local.ini
<<'EOF'
108 i
/etc
/php
/$phpver/fpm
/conf.d
/30-local.ini
<<'EOF'
109 date.timezone = "America/New_York"
111 upload_max_filesize = 2000M
112 post_max_size = 2000M
113 # install checker, nextcloud/settings/admin/overview
117 m systemctl restart
$fpm
119 # some of these are based on errors later on.
120 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
122 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
123 cat >/etc
/php
/$phpver/fpm
/pool.d
/localwww.conf
<<'EOF'
130 nextcloud_admin_pass
=casHiosidZyFraycs
133 if [[ ! -e $ncdir/index.php
]]; then
134 # if we wanted to only install a specific version, use something like
137 m wget
-nv -N https
://download.nextcloud.com
/server
/releases
/$file
141 m chown
-R www-data.www-data nextcloud
142 m
mv nextcloud
$ncdir
145 if [[ ! -e $myncdir/done-install
]]; then
147 m sudo
-u www-data php occ maintenance
:install --database sqlite
--admin-user iank
--admin-pass $nextcloud_admin_pass
148 m
touch $myncdir/done-install
151 # note, strange this happend where updater did not increment the version var,
152 # mine was stuck on 20. I manually updated it.
154 if [[ ! -e $myncdir/config.php-orig
]]; then
155 m
cp -a config.php
$myncdir/config.php-orig
157 cat $myncdir/config.php-orig
- >$myncdir/tmp.php
<<EOF
158 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
159 \$CONFIG["mail_smtpmode"] = "sendmail";
160 \$CONFIG["mail_smtphost"] = "127.0.0.1";
161 \$CONFIG["mail_smtpport"] = 25;
162 \$CONFIG["mail_smtptimeout"] = 10;
163 \$CONFIG["mail_smtpsecure"] = "";
164 \$CONFIG["mail_smtpauth"] = false;
165 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
166 \$CONFIG["mail_smtpname"] = "";
167 \$CONFIG["mail_smtppassword"] = "";
168 \$CONFIG["mail_domain"] = "$domain";
171 # based on installer check
172 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
173 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
175 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
176 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
177 \$CONFIG['trusted_domains'] = array (
181 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
182 var_export(\$CONFIG);
183 fwrite(STDOUT, ";\n");
185 e running php
$myncdir/tmp.php
186 # note: we leave it around place for debugging
187 php
$myncdir/tmp.php
>config.php
189 m sudo
-u www-data php occ maintenance
:update
:htaccess
190 i
/etc
/systemd
/system
/$ncbase.service
<<EOF
192 Description=ncup $ncbase
193 After=multi-user.target
197 ExecStart=/usr/local/bin/ncup $ncbase
199 IOSchedulingClass=idle
200 CPUSchedulingPolicy=idle
202 i
/etc
/systemd
/system
/$ncbase.timer
<<EOF
204 Description=ncup $ncbase timer
210 WantedBy=timers.target
212 systemctl
enable --now $ncbase.timer
213 i
/usr
/local
/bin
/ncup
<<'EOFOUTER'
216 set -e; . /usr/local/lib/bash-bear; set +e
218 m() { printf "%s\n" "$*"; "$@"; }
220 echo failed nextcloud update for $ncbase >&2
221 # -odf or else systemd will kill the background delivery process
222 # and the message will sit in the queue until the next queue run.
224 To: alerts@iankelling.org
225 From: www-data@$(hostname -f)
226 Subject: failed nextcloud update for $ncbase
228 For logs, run: jr -u $ncbase
232 if [[ $(id -u -n) != www-data ]]; then
233 echo error: running as wrong user: $(id -u -n), expected www-data
238 echo error: expected an arg, nextcloud relative base dir
244 # https://docs.nextcloud.com/server/22/admin_manual/maintenance/update.html?highlight=updater+phar
245 m php /var/www/$ncbase/updater/updater.phar -n
247 chmod +x
/usr
/local
/bin
/ncup
249 mkdir
-p /var
/www
/cron-errors
250 chown www-data.www-data
/var
/www
/cron-errors
251 i
/etc
/cron.d
/$ncbase <<EOF
252 PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/local/bin
254 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
255 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
259 m systemctl daemon-reload