3 if [[ -s /usr
/local
/lib
/err
]]; then
4 source /usr
/local
/lib
/err
11 m
() { printf "$pre %s\n" "$*"; "$@"; }
12 e
() { printf "$pre %s\n" "$*"; }
13 err
() { printf "$pre %s\n" "$*" >&2; exit 1; }
15 local tmp tmpdir dest
="$1"
16 local base
="${dest##*/}"
17 local dir
="${dest%/*}"
18 if [[ $dir != "$base" ]]; then
19 # dest has a directory component
25 tmp
=$
(rsync
-ic $tmpdir/"$base" "$dest")
29 if [[ $dest == /etc
/systemd
/system
/* ]]; then
30 touch /var
/local
/mail-setup-reload
37 key
="$1" value
="$2" section
="$3"
38 file="/etc/radicale/config"
39 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
43 # ignore services that dont exist
44 if systemctl
cat $service &>/dev
/null
; then
45 m systemctl disable
--now $service
51 m systemctl restart
$service
52 m systemctl
enable $service;
61 domain
=boardfiles.fsf.org
63 apt-get
-y install php-zip apache2 php-fpm
65 fpm
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.4-fpm
66 phpver
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
68 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
69 # /etc/apache2/conf-enabled/php7.3-fpm.conf
71 # ERROR: Module php8.1 does not exist. just allow it to fail
72 m a2dismod php
$phpver ||
:
74 # php with fpm doesnt work without this
79 m web-conf
- apache2
$domain <<EOF
80 ### begin nextcloud settings
81 Alias /nextcloud "$ncdir/"
85 Options FollowSymLinks MultiViews
93 # based on install checker, links to
94 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
95 # their example was a bit wrong, I figured it out by adding
96 # LogLevel warn rewrite:trace5
97 # then watching the apache logs
100 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
101 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
102 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
103 ### end nextcloud settings
107 i
/etc
/php
/$phpver/cli
/conf.d
/30-local.ini
<<'EOF'
112 i
/etc
/php
/$phpver/fpm
/conf.d
/30-local.ini
<<'EOF'
113 date.timezone = "America/New_York"
115 upload_max_filesize = 2000M
116 post_max_size = 2000M
117 # install checker, nextcloud/settings/admin/overview
121 m systemctl restart
$fpm
123 # some of these are based on errors later on.
124 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
126 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
127 cat >/etc
/php
/$phpver/fpm
/pool.d
/localwww.conf
<<'EOF'
134 nextcloud_admin_pass
=casHiosidZyFraycs
137 if [[ ! -e $ncdir/index.php
]]; then
138 # if we wanted to only install a specific version, use something like
141 m wget
-nv -N https
://download.nextcloud.com
/server
/releases
/$file
145 m chown
-R www-data.www-data nextcloud
146 m
mv nextcloud
$ncdir
149 if [[ ! -e $myncdir/done-install
]]; then
151 m sudo
-u www-data php occ maintenance
:install --database sqlite
--admin-user iank
--admin-pass $nextcloud_admin_pass
152 m
touch $myncdir/done-install
155 # note, strange this happend where updater did not increment the version var,
156 # mine was stuck on 20. I manually updated it.
158 if [[ ! -e $myncdir/config.php-orig
]]; then
159 m
cp -a config.php
$myncdir/config.php-orig
161 cat $myncdir/config.php-orig
- >$myncdir/tmp.php
<<EOF
162 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
163 \$CONFIG["mail_smtpmode"] = "sendmail";
164 \$CONFIG["mail_smtphost"] = "127.0.0.1";
165 \$CONFIG["mail_smtpport"] = 25;
166 \$CONFIG["mail_smtptimeout"] = 10;
167 \$CONFIG["mail_smtpsecure"] = "";
168 \$CONFIG["mail_smtpauth"] = false;
169 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
170 \$CONFIG["mail_smtpname"] = "";
171 \$CONFIG["mail_smtppassword"] = "";
172 \$CONFIG["mail_domain"] = "$domain";
175 # based on installer check
176 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
177 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
179 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
180 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
181 \$CONFIG['trusted_domains'] = array (
185 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
186 var_export(\$CONFIG);
187 fwrite(STDOUT, ";\n");
189 e running php
$myncdir/tmp.php
190 # note: we leave it around place for debugging
191 php
$myncdir/tmp.php
>config.php
193 m sudo
-u www-data php occ maintenance
:update
:htaccess
194 i
/etc
/systemd
/system
/$ncbase.service
<<EOF
196 Description=ncup $ncbase
197 After=multi-user.target
201 ExecStart=/usr/local/bin/ncup $ncbase
203 IOSchedulingClass=idle
204 CPUSchedulingPolicy=idle
206 i
/etc
/systemd
/system
/$ncbase.timer
<<EOF
208 Description=ncup $ncbase timer
214 WantedBy=timers.target
216 systemctl
enable --now $ncbase.timer
217 i
/usr
/local
/bin
/ncup
<<'EOFOUTER'
220 source /usr/local/lib/err
222 m() { printf "%s\n" "$*"; "$@"; }
224 echo failed nextcloud update for $ncbase >&2
225 # -odf or else systemd will kill the background delivery process
226 # and the message will sit in the queue until the next queue run.
228 To: alerts@iankelling.org
229 From: www-data@$(hostname -f)
230 Subject: failed nextcloud update for $ncbase
232 For logs, run: jr -u $ncbase
236 if [[ $(id -u -n) != www-data ]]; then
237 echo error: running as wrong user: $(id -u -n), expected www-data
242 echo error: expected an arg, nextcloud relative base dir
248 # https://docs.nextcloud.com/server/22/admin_manual/maintenance/update.html?highlight=updater+phar
249 m php /var/www/$ncbase/updater/updater.phar -n
251 chmod +x
/usr
/local
/bin
/ncup
253 mkdir
-p /var
/www
/cron-errors
254 chown www-data.www-data
/var
/www
/cron-errors
255 i
/etc
/cron.d
/$ncbase <<EOF
256 PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/local/bin
258 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
259 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
263 m systemctl daemon-reload