805b51282a32f6e30c868d9fc806d010b79de6da
[distro-setup] / distro-end
1 #!/bin/bash
2
3 # Program to setup Ian's computers
4 # Copyright (C) 2024 Ian Kelling
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 # SPDX-License-Identifier: GPL-3.0-or-later
20
21 # shellcheck source=/a/bin/ds/.bashrc
22 export LC_USEBASHRC=t; if [[ -s ~/.bashrc ]]; then . ~/.bashrc; fi
23
24 ### setup
25 source /a/bin/bash-bear-trap/bash-bear
26 src="$(readlink -f -- "${BASH_SOURCE[0]}")"; src=${src%/*} # directory of this file
27
28 if [[ $EUID == 0 ]]; then
29 echo "$0: error: run as regular user" >&2
30 exit 1
31 fi
32
33 err-cleanup() {
34 echo 1 >~/.local/distro-end
35 }
36
37 # shellcheck source=./pkgs
38 source $src/pkgs
39
40 echo "$0: $(date) starting now)"
41 # see example of usage to understand.
42 end_msg() {
43 local y
44 IFS= read -r -d '' y ||:
45 end_msg_var+="$y"
46 }
47 end() {
48 e "$end_msg_var"
49 echo 0 >~/.local/distro-end
50 if $pending_reboot; then
51 echo "$0: pending reboot and then finished. doing it now."
52 echo "exiting with status 0"
53 sudo reboot now
54 else
55 echo "$0: $(date): ending now)"
56 echo "exiting with status 0"
57 fi
58 exit 0
59 }
60 pre="${0##*/}:"
61 sudo() {
62 printf "$pre sudo %s\n" "$*"
63 SUDOD="$PWD" command sudo "$@";
64 }
65 m() { printf "$pre %s\n" "$*"; "$@"; }
66 e() { printf "$pre %s\n" "$*"; }
67 distro=$(distro-name)
68 codename=$(debian-codename)
69 codename_compat=$(debian-codename-compat)
70 pending_reboot=false
71 sed="sed --follow-symlinks"
72
73 # when we schroot, it will fail if we are in a directory that doesnt exist in the chroot
74 cd /
75
76 ## template:
77 # case $distro in
78 # esac
79
80 case $HOSTNAME in
81 li|bk|je) : ;;
82 *)
83 # get sudo pass cached right away
84 if ! sudo -nv 2>/dev/null; then
85 sudo -v
86 fi
87 ;;
88 esac
89
90 # old repo. remove when all machines updated
91 sudo rm -fv /etc/apt/sources.list.d/wireguard-ubuntu-wireguard-bionic.list
92 # remove old file
93 sudo rm -fv /etc/apt/preferences.d/minetest
94
95 #### initial packages
96 pup
97 if isdeb; then
98 pi aptitude
99 fi
100
101 # avoid prompts
102 sudo debconf-set-selections <<EOF
103 popularity-contest popularity-contest/participate boolean true
104 EOF
105
106 ########### begin section including vps ################
107 pi ${p2[@]}
108
109 conflink
110
111 sudo rm -fv
112
113 # no equivalent in other distros:
114 if isdeb && pcheck apt-file; then
115 # this condition is just a speed optimization
116 pi apt-file
117 sudo apt-file update
118 fi
119
120
121 # disable motd junk.
122 case $distro in
123 debian)
124 # allows me to pipe with ssh -t, and gets rid of spam
125 # http://forums.debian.net/viewtopic.php?f=5&t=85822
126 # i'd rather disable the service than comment the init file
127 # this says disabling the service, it will still get restarted
128 # but this script doesn't do anything on restart, so it should be fine
129 sudo truncate -s0 /var/run/motd.dynamic
130 ;;
131 trisquel|ubuntu)
132 # this isn't a complete solution. It still shows me when updates are available,
133 # but it's no big deal.
134 sudo rm -fv /etc/update-motd.d/10-help-text /etc/update-motd.d/00-header
135 ;;
136 esac
137
138
139
140
141
142 pi debootstrap
143 ######### begin universal pinned packages ######
144 case $(debian-codename) in
145 etiona|flidas|nabia|aramo)
146 sudo rm -fv /etc/apt/preferences.d/etiona-buster
147 sd /etc/apt/preferences.d/trisquel-debian <<EOF
148 Explanation: Debian* includes Debian + Debian Backports
149 Package: *
150 Pin: release o=Debian*
151 Pin-Priority: -100
152
153 Explanation: ubuntu's version is outdated
154 Package: debian-archive-keyring
155 Pin: release o=Debian*
156 Pin-Priority: 1000
157 EOF
158 ;;&
159
160 aramo|nabia|etiona)
161 # for ziva
162 #p install --no-install-recommends minetest/buster libleveldb1d/buster libncursesw6/buster libtinfo6/buster
163 doupdate=false
164 # shellcheck disable=SC2043 # in case we want more than 1 in the loop later.
165 for n in bookworm; do
166 f=/etc/apt/sources.list.d/$n.list
167 t=$(mktemp)
168 case $n in
169 bookworm)
170 cat >$t <<'EOF'
171 EOF
172 cat >$t <<EOF
173 deb http://deb.debian.org/debian bookworm main
174 deb-src http://deb.debian.org/debian bookworm main
175
176 deb http://deb.debian.org/debian-security/ bookworm-security main
177 deb-src http://deb.debian.org/debian-security/ bookworm-security main
178
179 deb http://deb.debian.org/debian bookworm-updates main
180 deb-src http://deb.debian.org/debian bookworm-updates main
181
182 deb http://http.debian.net/debian bookworm-backports main
183 deb-src http://http.debian.net/debian bookworm-backports main
184 EOF
185 ;;
186 esac
187
188 if ! diff -q $t $f; then
189 doupdate=true
190 s cp $t $f
191 s chmod 644 $f
192 fi
193 done
194 if $doupdate; then
195 tmpdir=$(mktemp -d)
196 cd $tmpdir
197 p download debian-archive-keyring
198 s dpkg -i debian-archive-keyring
199 p update
200 cd -
201 rm -rf $tmpdir
202 fi
203
204 if [[ ! -e /usr/share/debootstrap/scripts/bookworm ]]; then
205 t=$(mktemp -d)
206 cd $t
207 m aptitude download debootstrap/bookworm
208 m ex ./*
209 sudo cp ./usr/share/debootstrap/scripts/* /usr/share/debootstrap/scripts
210 fi
211
212 ;;&
213 etiona)
214 sd /etc/apt/preferences.d/focal <<'EOF'
215 Package: *
216 Pin: release n=focal,o=Ubuntu
217 Pin-Priority: -100
218 EOF
219
220 sd /etc/apt/preferences.d/spamassassin <<'EOF'
221 Package: spamassassin sa-compile spamc
222 Pin: release n=focal,o=Ubuntu
223 Pin-Priority: 500
224 EOF
225 sd /etc/apt/preferences.d/spamassassin <<'EOF'
226 Package: spamassassin sa-compile spamc
227 Pin: release n=focal,o=Ubuntu
228 Pin-Priority: 500
229 EOF
230 sd /etc/apt/preferences.d/psd <<'EOF'
231 Package: profile-sync-daemon
232 Pin: release n=focal,o=Ubuntu
233 Pin-Priority: 500
234 EOF
235
236 f=/etc/apt/sources.list.d/focal.list
237 t=$(mktemp)
238 cat >$t <<'EOF'
239 deb http://us.archive.ubuntu.com/ubuntu/ focal main universe
240 deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main universe
241 deb http://us.archive.ubuntu.com/ubuntu/ focal-security main universe
242 EOF
243 if ! diff -q $t $f; then
244 sudo dd if=$t of=$f status=none
245 p update
246 fi
247
248
249
250 sd /etc/apt/preferences.d/nabia-etiona <<'EOF'
251 Package: *
252 Pin: release n=nabia*,o=Trisquel
253 Pin-Priority: -100
254 EOF
255
256 f=/etc/apt/sources.list.d/nabia.list
257 t=$(mktemp)
258 cat >$t <<'EOF'
259 deb http://mirror.fsf.org/trisquel/ nabia main
260 deb-src http://mirror.fsf.org/trisquel/ nabia main
261
262 deb http://mirror.fsf.org/trisquel/ nabia-updates main
263 deb-src http://mirror.fsf.org/trisquel/ nabia-updates main
264
265 deb http://archive.trisquel.info/trisquel/ nabia-security main
266 deb-src http://archive.trisquel.info/trisquel/ nabia-security main
267
268 # Uncomment this lines to enable the backports optional repository
269 deb http://mirror.fsf.org/trisquel/ nabia-backports main
270 deb-src http://mirror.fsf.org/trisquel/ nabia-backports main
271 EOF
272 if ! diff -q $t $f; then
273 sudo dd if=$t of=$f status=none
274 p update
275 fi
276
277 # duplicated in fai. Pin for bionic + ubuntu so that ppas dont get
278 # matched.
279 sd /etc/apt/preferences.d/etiona-bionic <<'EOF'
280 Package: *
281 Pin: release n=bionic,o=Ubuntu
282 Pin-Priority: -100
283 Package: firefox
284 Pin: release n=bionic,o=Ubuntu
285 Pin-Priority: 500
286 EOF
287
288 sd /etc/apt/preferences.d/etiona-sa <<'EOF'
289 Package: *
290 Pin: release n=bionic,o=Ubuntu
291 Pin-Priority: -100
292 EOF
293
294 ;;&
295 nabia)
296 sd /etc/apt/preferences.d/aramo-nabia <<'EOF'
297 Package: *
298 Pin: release n=aramo*,o=Trisquel
299 Pin-Priority: -100
300 EOF
301 f=/etc/apt/sources.list.d/aramo.list
302 t=$(mktemp)
303 cat >$t <<'EOF'
304 deb http://mirror.fsf.org/trisquel/ aramo main
305 deb-src http://mirror.fsf.org/trisquel/ aramo main
306
307 deb http://mirror.fsf.org/trisquel/ aramo-updates main
308 deb-src http://mirror.fsf.org/trisquel/ aramo-updates main
309
310 deb http://archive.trisquel.info/trisquel/ aramo-security main
311 deb-src http://archive.trisquel.info/trisquel/ aramo-security main
312
313 # Uncomment this lines to enable the backports optional repository
314 deb http://mirror.fsf.org/trisquel/ aramo-backports main
315 deb-src http://mirror.fsf.org/trisquel/ aramo-backports main
316 EOF
317 if ! diff -q $t $f; then
318 sudo dd if=$t of=$f status=none
319 p update
320 fi
321
322 ;;&
323 *)
324 if isdeb; then
325 pi debian-goodies shellcheck
326 fi
327 ;;
328 esac
329
330 case $codename_compat in
331 jammy)
332 s systemctl enable --now ssh-agent-iank
333 ;;
334 esac
335
336 case $codename_compat in
337 focal)
338 sd /etc/apt/preferences.d/nabia-btrfs-progs <<'EOF'
339 Package: btrfs-progs
340 Pin: release a=buster-backports
341 Pin-Priority: 500
342 EOF
343 p install btrfs-progs
344 ;;
345 esac
346
347
348 # 2020-03-03 old file
349 s rm -fv /etc/apt/preferences.d/radicale
350 ######### end universal pinned packages ######
351
352
353 case $codename in
354 etiona)
355 sd /etc/apt/preferences.d/obs <<EOF
356 Package: libfdk-aac1
357 Pin: release n=bionic
358 Pin-Priority: 500
359 EOF
360 sd /etc/apt/preferences.d/chromium <<EOF
361 Package: chromium-*
362 Pin: release n=bionic
363 Pin-Priority: 500
364 EOF
365 ;;
366 nabia)
367 # note, to get the latest, it would be n=bullseye*
368 # but that has conflicting package versions, so this does the old one.
369 # I only use it for special rare purposes. Just keep in mind it is an
370 # outdated insecure version.
371 sd /etc/apt/preferences.d/chromium-bullseye <<EOF
372 Package: chromium chromium-* libicu67 libjpeg62-turbo libjsoncpp24 libre2-9 libwebpmux3
373 Pin: release o=Debian*,n=bullseye
374 Pin-Priority: 500
375 EOF
376 ;;
377 aramo)
378 # obs dependency not in trisquel
379 sd /etc/apt/preferences.d/obs <<EOF
380 Package: libfdk-aac2
381 Pin: release n=jammy,o=Ubuntu
382 Pin-Priority: 500
383 EOF
384 ;;
385 esac
386
387
388
389 ##### begin automatic upgrades (after checkrestart has been installed) ####
390 # if apt-config-auto-update is installed,
391 # it also has similar config, in a file 10something,
392 # but i think this overrides it since its higher number.
393 # This file was part of the automatic-updates package,
394 # and it has a config option to not get new package lists,
395 # which seems pretty stupid to me, you cant actually upgrade
396 # anything if you dont have the new package list.
397 sd /etc/apt/apt.conf.d/20auto-upgrades <<'EOF'
398 # note: man apt.conf says
399 # /usr/share/doc/apt/examples/configure-index.gz is a configuration file showing
400 # example values for all possible options.
401 # but that is a incorrect.
402 # Periodic and other options are only documented in
403 # /usr/lib/apt/apt.systemd.daily
404 # That filename can be found through poking around in apt daily cronjob.
405 APT::Periodic::Update-Package-Lists "1";
406 APT::Periodic::Download-Upgradeable-Packages "1";
407 # 0 means disabled. I used to set this to 7, however, trisquel doesn't
408 # have an archive of old package versions, so I want to
409 # keep around old versions so I can easily downgrade.
410 APT::Periodic::AutocleanInterval "0";
411 # daily expire old files /var/cache/apt if it gets above this MB
412 APT::Periodic::MaxSize "50000";
413 APT::Periodic::Unattended-Upgrade "1";
414 EOF
415
416 # fyi: default file has comments about available options,
417 # you may want to read that, do pkx unattended-upgrades
418 # default is just security updates. this list found from reading
419 # match_whitelist_string() in $(which unattended-upgrades)
420 sd /etc/apt/apt.conf.d/50unattended-upgrades <<EOF
421 Unattended-Upgrade::Mail "root";
422 Unattended-Upgrade::MailOnlyOnError "true";
423 Unattended-Upgrade::Remove-Unused-Dependencies "true";
424 Unattended-Upgrade::Origins-Pattern {
425 "o=*,l=*,a=*,c=*,site=*,n=*";
426 };
427 EOF
428
429 # old files
430 sudo rm -f /etc/cron.d/unattended-upgrade-reboot /usr/local/bin/zelous-unattended-reboot /etc/cron.d/myupgrade
431
432 # myupgrade cron exists in /etc/cron.d/ian
433
434 ##### end automatic upgrades ####
435
436
437 # commented in case i want to use this sometime later
438 # sd /etc/apt/preferences.d/buster-backports <<EOF
439 # Package: *
440 # Pin: release a=buster-backports
441 # Pin-Priority: 500
442 # EOF
443
444
445 ###### begin website setup
446 case $HOSTNAME in
447 li|bk|je)
448 pi bind9
449 f=/var/lib/bind/db.b8.nz
450 if [[ ! -e $f ]]; then
451 dnsb8
452 fi
453
454 sudo /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter -l 127.0.0.1
455
456 # ex for exporter
457 web-conf -p 9101 -f 9100 - apache2 ${HOSTNAME}ex.b8.nz <<'EOF'
458 <Location "/">
459 AuthType Basic
460 AuthName "basic_auth"
461 # created with
462 # htpasswd -c prometheus-export-htpasswd USERNAME
463 AuthUserFile "/etc/prometheus-export-htpasswd"
464 Require valid-user
465 </Location>
466 EOF
467 ;;&
468
469 bk)
470 sgo wg-quick@wgmail
471
472 # i just dont feel like setting up a special purpose ssh key to do this automatically.
473 end_msg <<'EOF'
474 # run this once for bk on local machine:
475 # only used for old openvpn setup
476 /a/exe/vpn-mk-client-cert -c bk.b8.nz -b expertpath -n mail li.iankelling.org
477 EOF
478 end
479 ;;
480 je)
481 end
482 ;;
483 li)
484
485 p build-dep eggdrop
486 if [[ ! -L ~/eggdrop/eggdrop ]]; then
487 cd
488 git clone https://github.com/eggheads/eggdrop eggdrop-src
489 cd eggdrop-src
490 ./configure
491 make config
492 make
493 make install
494 fi
495
496 # dunno if this is really needed. it was part of the documented eggdrop systemd install script
497 sudo loginctl enable-linger
498 systemctl --user enable fsysbot
499 systemctl --user start fsysbot
500
501 m /a/h/setup.sh iankelling.org
502
503 # start mumble only when im going to use it, since i dont use it much
504 pi-nostart mumble-server
505 sudo $sed -ri "s/^ *(serverpassword=).*/\1$(< /a/bin/bash_unpublished/mumble_pass)/" /etc/mumble-server.ini
506
507 # do certificate to avoid warning about unsigned cert,
508 # which is overkill for my use, but hey, I'm cool, I know
509 # how to do this.
510 m web-conf apache2 mumble.iankelling.org
511 sudo rm -fv /etc/apache2/sites-enabled/mumble.iankelling.org
512
513 # general vpn for as needed use
514 vpn-server-setup -d -r -4 10.5.5 -p 443 -n hole
515
516 # todo: consider if this should exist for the
517 # other vpn server
518 teeu /etc/openvpn/server/hole.conf <<'EOF'
519 client-to-client
520 EOF
521
522
523 ngset
524 files=(/etc/openvpn/client-config-hole/*)
525 if (( ${#files[@]} >= 1 )); then
526 rm -f ${files[@]}
527 fi
528 ngreset
529 for host in ${!vpn_ips[@]}; do
530 sd /etc/openvpn/client-config-hole/$host <<EOF
531 ifconfig-push 10.5.5.${vpn_ips[$host]} 255.255.255.0
532 EOF
533 done
534
535
536 # for adding cert to system with /p
537 #
538 # host=frodo
539 #mkc /p/c/machine_specific/$host/filesystem/etc/openvpn/client
540 #vpn-mk-client-cert -b $host -n hole -r iankelling.org
541 #s chown -R iank:iank .
542 #
543 # example of adding to remote system 107,
544 # vpn-mk-client-cert -n hole -c 10.2.0.107 -b hd8 iankelling.org
545 #
546 # for wireguard hole vpn, use function:
547 # wghole
548 # eg:
549 # wghole bo 28
550 # if it is going to want to connect to transmission-daemon on ok
551 # wghole bo 28 10.174.2.2/32
552
553 # requested from linode via a support ticket.
554 # https://www.linode.com/docs/networking/an-overview-of-ipv6-on-linode/
555 # ipv6 stuff pieced together
556 # via slightly wrong information from
557 # https://github.com/angristan/openvpn-install/blob/master/openvpn-install.sh
558 # https://community.openvpn.net/openvpn/wiki/IPv6
559 # and man openvpn.
560 #
561 # This uses a public /64, but afaik, that is not needed for my
562 # current use case, since I'm doing ipv6 nat, they could be private
563 # and nat to a public address. I'm doing ipv6 nat in order to have 2
564 # vpn clients that externally share the same ip when sending so they
565 # share ip reputation. Note, the eth0 and tunx needed to be
566 # different subnets. On the same, I saw some neighbor packet go
567 # unanswered, tcpdump showed packets getting lost. I tried splitting the
568 # /64, it didn't work but I didn't investigate closely.
569
570
571 # not starting as i intend to replace it
572 m vpn-server-setup -s -i tunmail -n mail -d -6 2600:3c00:e002:3800::/64 2600:3c00:e002:3800::1/64
573 sudo tee /etc/openvpn/client-config-mail/mailclient <<'EOF'
574 ifconfig-push 10.8.0.4 255.255.255.0
575 ifconfig-ipv6-push 2600:3c00:e002:3800::4/64
576 EOF
577 sudo tee /etc/openvpn/client-config-mail/expertpath <<'EOF'
578 ifconfig-push 10.8.0.5 255.255.255.0
579 ifconfig-ipv6-push 2600:3c00:e002:3800::5/64
580 EOF
581
582
583 sudo dd of=/etc/systemd/system/vpn-mail-forward.service <<'EOF'
584 [Unit]
585 Description=Turns on iptables mail nat
586 BindsTo=openvpn-server@mail.service
587
588 [Service]
589 Type=oneshot
590 RemainAfterExit=yes
591 ExecStart=/a/bin/distro-setup/vpn-mail-forward tunmail start
592 ExecStop=/a/bin/distro-setup/vpn-mail-forward tunmail stop
593
594 [Install]
595 RequiredBy=openvpn-server@mail.service
596 EOF
597 ser daemon-reload
598
599
600 # needed for li's local mail delivery.
601 tu /etc/hosts <<<"10.8.0.4 mx.iankelling.org"
602
603 # wgmail handles this.
604 #sgo vpn-mail-forward.service
605 # old:
606 #sgo openvpn-server@mail
607 sgo wg-quick@wgmail
608
609 # setup let's encrypt cert
610 m web-conf apache2 mail.iankelling.org
611 # TODO, i expanded the above cert manually to mx.iankelling.org, this should be captured
612 # in the automation here. We use mail.iankelling.org as our ehlo name when sending mail
613 # but our mx record is mx.iankelling.org. Initially I was just using mail.iankelling.org,
614 # but the problem is I want multiple ips to be able to identify as mail.iankelling.org,
615 # but a subset to be mx.iankelling.org. Afaik, there is no problem with having
616 # our mail cert be for mail.iankelling.org, and have people connect to mx.ian...,
617 # but it doesn't make logical sense to do this.
618 sudo rm -fv /etc/apache2/sites-enabled/mail.iankelling.org{,-redir}.conf
619 ser reload apache2
620
621 a2enmod -q proxy proxy_http
622 domain=cal.iankelling.org
623 web-conf -f 10.8.0.4:5232 - apache2 $domain <<'EOF'
624 # https://radicale.org/2.1.html
625 #https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype
626 # https://stackoverflow.com/questions/5011102/apache-reverse-proxy-with-basic-authentication
627
628 # this doesn't exactly fit with the documentation.
629 # We need location / to do an auth, it cant be done outside,
630 # in order to pass on X-Remote-User. And we need
631 # the other location in order to remove the /radicale/ for
632 # requests which have it. This could be done with a rewrite,
633 # but i just get something working and call it a day.
634
635 <Location "/">
636 AllowOverride None
637 AuthType Basic
638 AuthName "Authentication Required"
639 # setup one time, with root:www-data, 640
640 AuthUserFile "/etc/caldav-htpasswd"
641 Require valid-user
642 RequestHeader set X-Remote-User expr=%{REMOTE_USER}
643 </Location>
644 <Location "/radicale/">
645 Options +FollowSymLinks +Multiviews -Indexes
646 RequestHeader set X-Script-Name /radicale/
647 RequestHeader set X-Remote-User expr=%{REMOTE_USER}
648 ProxyPass "http://10.8.0.4:5232/" retry=0
649 ProxyPassReverse "http://10.8.0.4:5232/"
650 </Location>
651 EOF
652 # nginx version of above would be:
653 # auth_basic "Not currently available";
654 # auth_basic_user_file /etc/nginx/caldav/htpasswd;
655
656
657
658 ###### begin znc setup #####
659 pi znc
660
661 # https://wiki.znc.in/FAQ seems to imply that znc doesn\'t need restart after cert change.
662 # to get into the web interface,
663 # then use non-main browser or else it doebsn't allow it based on ocsp stapling from my main site.
664 # https://iankelling.org:12533/
665 # login as ian, pass is in pass store, the part after :
666
667 # znc config generated by doing
668 # znc --makeconf
669 # selected port is also used in erc config
670 # comma separated channel list worked.
671 # while figuring things out, running znc -D for debug in foreground.
672 # to exit and save config:
673 # /msg *status shutdown
674 # configed auth on freenode by following
675 # https://wiki.znc.in/Sasl:
676 # /query *sasl
677 # RequireAuth yes
678 # Mechanism PLAIN
679 # Set MyNickservName pa$$w0rd
680 # created the system service after, and had to do
681 # mv /home/iank/.znc/* /var/lib/znc
682 # sed -i 's,/home/iank/.znc/,/var/lib/znc,' /var/lib/znc/config/znc.conf
683 # and made a copy of the config files into /p/c
684 # /msg *status LoadMod --type=global log -sanitize
685 # todo: in config file AllowWeb = true should be false. better security if that is off unless we need it.
686 # /msg *status LoadMod --type=network perform
687 # /query *perform add PRIVMSG ChanServ :invite #fsf-office
688 # /msg *perform add JOIN #fsf-office
689 # /msg *status LoadMod NickServ
690 #
691 # i set Buffer = 500
692 # also ran /znc LoadMod clearbufferonmsg
693 # it would be nice if erc supported erc query buffers by doing
694 # /msg *status clearbuffer <name of the query/receiver
695 # on killing the,
696 # an example seems to be here: https://github.com/zenspider/elisp/blob/master/rwd-irc.el
697 # if that was the case i could remove the module clearbufferonmsg
698 # also would be nice if erc supported
699 # https://wiki.znc.in/self-message
700 # https://wiki.znc.in/Query_buffers \
701 #
702 # for geekshed, there was no sasl support as far as I can tell,
703 # so I set to msg nickserv to identify upon connect.
704 if ! getent passwd znc > /dev/null; then
705 sudo useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
706 fi
707 sudo chmod 700 /var/lib/znc
708 sudo chown -R znc:znc /var/lib/znc
709 # Avoid restarting if possible, reconnecting to irc is annoying.
710 # The unit file was made active with conflink.
711 # Note, avoid using ser here because we wrap sudo to prints the command first.
712 if [[ $(systemctl is-active znc) != active ]]; then
713 sgo znc
714 fi
715 ###### stop znc setup #####
716
717 end
718 ;;
719 esac
720
721 case $HOSTNAME in
722 bk)
723 pi icecast2
724 # todo, save the config
725 /etc/cron.daily/stream-cert
726 web-conf -c /etc/cert-live.fsf.org -p 443 -f 8000 apache2 live.fsf.org
727 ;;
728 esac
729
730 ###### end website setup
731
732 ########### end section including li/lj ###############
733
734
735 #### desktop stuff
736
737 ### system76 things ###
738 case $HOSTNAME in
739 bo) # sy| sy doesnt seem to really need this.
740 # note, i stored the initial popos packages at /a/bin/data/popos-pkgs
741 if [[ ! -e /etc/apt/sources.list.d/system76.list ]]; then
742 # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
743 sd /etc/apt/sources.list.d/system76.list <<EOF
744 deb http://ppa.launchpad.net/system76-dev/stable/ubuntu $codename_compat main
745 deb-src http://ppa.launchpad.net/system76-dev/stable/ubuntu $codename_compat main
746 EOF
747 # ubuntu keyserver is prone to intermittent failures
748 trysleep 4 15 s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 5D1F3A80254F6AFBA254FED5ACD442D1C8B7748B
749 p update
750 # https://support.system76.com/articles/install-ubuntu/
751 # but i'm hoping this is not needed
752 # sd /etc/apt/preferences.d/system76 <<'EOF'
753 # Package: *
754 # Pin: release o=LP-PPA-system76-dev-stable
755 # Pin-Priority: 1001
756 # EOF
757 #
758 # TODO: I had to uninstall linux-image-generic-hwe-20.04 because of a conflict
759 # about linux-firmware. Should probably install it to begin with in fai if
760 # i'm going to use.
761 pi system76-driver system76-firmware
762 # if you get a notice about a firmware update, the notifier on i3
763 # is too dumb to do anything when you click it. so to see
764 # a changelog, cd to
765 # /var/cache/system76-firmware-daemon
766 # extract the xz files there, one will contain a changelog.
767 # then to install an update:
768 # s system76-firmware-cli schedule
769 fi
770 ;;
771 esac
772 ### end system76 things ###
773
774 case $distro in
775 trisquel|ubuntu)
776
777
778 ## one time setup thing I did
779 # c /a/opt/obs-cmd/
780 # cargo build --release
781 # cp target/release/obs-cmd ../bin
782 #
783 ## in obs, tools -> websocket server settings -> generate/copy password
784 #
785 # note: obs-studio on gnu does not support webrtc, it seems mainly because
786 # libdatachannel is not packaged. If it was, it would just need to do
787 # apt source obs-studio, obs-studio-30.1.1/debian/rules set -DENABLE_WEBRTC=ON
788 #
789 # I did manage to build libdatachannel following its instructions, then make install,
790 # then obs failed due to nvidia. found those options to disable with
791 # rg 'option\(ENABLE' | gr nv, then build obs like so:
792 #
793 # cmake -DLINUX_PORTABLE=ON -DCMAKE_INSTALL_PREFIX="${HOME}/obs-studio-portable" -DENABLE_BROWSER=OFF -DENABLE_AJA=OFF -DENABLE_NEW_MPEGTS_OUTPUT=OFF -DENABLE_WEBRTC=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DENABLE_NVVFX=OFF -DENABLE_NVAFX=OFF -DENABLE_NATIVE_NVENC=OFF ..
794 #
795 #
796 #
797 # however, I didn't end up trying it out.
798 #
799 # note, in terminal source, i setup a transform so it would show the
800 # bottom 1080p section of the terminal instead of the top if the
801 # screen was bigger. click like 2 times in the preview so the red
802 # lines show up, right click, edit transform (or ctrl-e). bounding
803 # box type: scale to width of bounds. alignment in bounding box:
804 # bottom left. bounding box size 1920 x 1080.
805
806 # ppa:obsproject/obs-studio
807 if [[ ! -s /etc/apt/sources.list.d/obs.list ]]; then
808 # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html
809 sd /etc/apt/sources.list.d/obs.list <<EOF
810 deb http://ppa.launchpad.net/obsproject/obs-studio/ubuntu $codename_compat main
811 deb-src http://ppa.launchpad.net/obsproject/obs-studio/ubuntu $codename_compat main
812 EOF
813 trysleep 4 15 s apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BC7345F522079769F5BBE987EFC71127F425E228
814 p update
815 fi
816 ;;
817
818 esac
819
820 case $codename_compat in
821 xenial)
822 # mate-indicator-applet and beyond are msc things I noticed diffing a
823 # standard install with mine.
824 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras mate-indicator-applet anacron
825 ;;
826 stretch)
827 pi task-mate-desktop
828 ;;
829 buster)
830 # todo: figure out mate for buster
831 # pi task-gnome-desktop
832 ;;
833 bionic|focal)
834 # i had installing mate-indicator-applet, but im not sure why so i removed
835 pi xorg lightdm mate-desktop-environment mate-desktop-environment-extras anacron
836
837 # pi gnome-core
838 # # apt-get update periodically fails with an appstream error.
839 # # this removes gnome-core, but its just a package for dependencies
840 # p -y remove appstream
841
842
843 # by default, it sleeps when not logged in to x/wayland and on ac power.
844 # stop that.
845 if id -u gdm &>/dev/null; then
846 sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
847 fi
848 ;;&
849 focal)
850 # lightdm startup fails without this. on etiona, we got unity-greeter installed automatically,
851 # it would probably work on nabia too, but google just lead me to this and it works fine.
852 pi lightdm-gtk-greeter
853 # ok, this is really weird
854 # normally this file has
855 sd /etc/X11/Xsession.d/99x11-common_start <<'EOF'
856 # this is very odd.
857 # this file normally just has: exec $STARTUP
858 # but then ~/.xsession-errors
859 # says $STARTUP is not found, which appears to be the real
860 # error, but normal bash doesnt operate that way.
861 # https://bugs.launchpad.net/ubuntu/+source/im-config/+bug/1879352
862 eval exec $STARTUP
863 EOF
864 # also, gdm wayland was default, had to do
865 # dpkg-reconfigure gdm3
866 # and choose lightdm.
867 #
868 ;;
869 jammy)
870 # not yet bothering with mate
871 pi lightdm-gtk-greeter lightdm
872 ;;
873 esac
874
875
876 if [[ $codename_compat == flidas ]]; then
877 # doesnt exist in newer
878 pi gnupg-doc
879 fi
880
881
882 case $distro in
883 trisquel)
884 case $codename in
885 *)
886 # firefox would work here too, apt would select abrowser.
887 # and the update-alternatives thing i think is becuz firefox is
888 # generally available before abrowser and this helps fix things
889 # up when we have both.
890 pi abrowser
891 s update-alternatives --set x-www-browser /usr/bin/abrowser
892 ;;
893 esac
894 ;;
895 ubuntu)
896 pi firefox
897 ;;
898 debian)
899 pi firefox-esr
900 ;;
901 esac
902
903 # newer distros just use adb for package name it seems
904 case $codename_compat in
905 bionic|stretch)
906 pi android-tools-adbd
907 ;;
908 esac
909
910 case $codename_compat in
911 focal)
912 pi libext2fs-dev libzstd-dev
913 cd /a/opt/btrfs-progs
914 ;;
915 esac
916
917
918 case $codename_compat in
919 bionic)
920 pi python-vte
921 ;;
922 *)
923 pi reportbug-gtk
924 ;;
925 esac
926
927 # not packaged in newer distros it seems
928 case $codename_compat in
929 bionic|buster|stretch)
930 pi dtrx
931 ;;
932 esac
933
934
935 # TODO: some of the X programs can be removed from pall when using wayland
936
937 # depends gcc is a way to install suggests. this is apparently the only
938 # way to install suggests even if the main package is already
939 # installed. reinstall doesn't work, uninstalling can cause removing
940 # dependent packages.
941 # shellcheck disable=SC2046 # word splitting is intended
942 pi ${pall[@]} $(apt-cache search ruby[.0-9]+-doc| awk '{print $1}') $($src/distro-pkgs)
943
944 # schroot service will restart schroot sessions after reboot.
945 # I dont want that.
946 pi-nostart schroot
947
948 # fix systemd unit failure. i dont know of any actual impact
949 # other than systemd showing in degraded state. So, we dont bother
950 # fixing the current state, let it fix on the next reboot.
951 # https://gitlab.com/cjwatson/binfmt-support/-/commit/54f0e1af8a
952 tmp=$(systemctl cat binfmt-support.service | grep ^After=)
953 if [[ $tmp != *systemd-binfmt.service* ]]; then
954 s u /etc/systemd/system/binfmt-support.service.d/override.conf <<EOF
955 [Unit]
956 $tmp systemd-binfmt.service
957 EOF
958 fi
959
960
961 # commented, not worth the hassle i think.
962 #seru enable psd
963 #seru start psd
964
965
966 # old filename
967 sudo rm -fv /etc/systemd/resolved.conf.d/iank.conf
968
969 # website is dead june 14 2019. back in october, but meh
970 sudo rm -fv /etc/apt/sources.list.d/iridium-browser.list
971 # case $distro in
972 # debian)
973 # pi chromium ;;
974 # trisquel|ubuntu)
975 # wget -qO - https://downloads.iridiumbrowser.de/ubuntu/iridium-release-sign-01.pub|sudo apt-key add -
976 # t=$(mktemp)
977 # cat >$t <<EOF
978 # deb [arch=amd64] https://downloads.iridiumbrowser.de/deb/ stable main
979 # #deb-src https://downloads.iridiumbrowser.de/deb/ stable main
980 # EOF
981 # f=/etc/apt/sources.list.d/iridium-browser.list
982 # if ! diff -q $t $f; then
983 # s cp $t $f
984 # s chmod 644 $f
985 # p update
986 # fi
987 # pi iridium-browser
988 # ;;
989 # esac
990
991
992 ##### rss2email
993 if mountpoint /p &>/dev/null; then
994 # note, see bashrc for more documentation.
995 pi rss2email
996 sd /etc/systemd/system/rss2email.service <<'EOF'
997 [Unit]
998 Description=rss2email
999 After=multi-user.target
1000
1001 [Service]
1002 User=iank
1003 Type=oneshot
1004 # about 24 hours of failures
1005 # it copies over its files without respecting symlinks, so
1006 # we pass options to use different location.
1007 ExecStart=/usr/local/bin/sysd-mail-once -288 rss2email r2e -d /p/c/rss2email.json -c /p/c/rss2email.cfg run
1008 EOF
1009 sd /etc/systemd/system/rss2email.timer <<'EOF'
1010 [Unit]
1011 Description=rss2email
1012
1013 [Timer]
1014 # for initial run. required.
1015 OnActiveSec=30
1016 # for subsequent runs.
1017 OnUnitInactiveSec=300
1018
1019 [Install]
1020 WantedBy=timers.target
1021 EOF
1022 sudo systemctl daemon-reload
1023 fi
1024
1025
1026 ######### begin irc periodic backup #############
1027 if [[ $HOSTNAME == frodo ]]; then
1028 sd /etc/systemd/system/ircbackup.service <<'EOF'
1029 [Unit]
1030 Description=irc li backup
1031 After=multi-user.target
1032
1033 [Service]
1034 User=iank
1035 Type=oneshot
1036 ExecStart=/usr/local/bin/sysd-mail-once irc-backup rsync -rlptDhSAX root@iankelling.org:/var/lib/znc/moddata/log/iank/freenode/ /k/irclogs
1037 EOF
1038 sd /etc/systemd/system/ircbackup.timer <<'EOF'
1039 [Unit]
1040 Description=irc li backup hourly
1041
1042 [Timer]
1043 OnCalendar=hourly
1044
1045 [Install]
1046 WantedBy=timers.target
1047 EOF
1048 sudo systemctl daemon-reload
1049 sgo ircbackup.timer
1050 fi
1051
1052
1053 ######### end irc periodic backup #############
1054
1055
1056 pi-nostart openvpn
1057 # pi-nostart does not disable
1058 ser disable openvpn
1059
1060
1061 if [[ -e /p/c/gen-fsf-vpn ]]; then
1062 /p/c/gen-fsf-vpn
1063 fi
1064
1065 if [[ -e /p/c/machine_specific/$HOSTNAME/filesystem/etc/openvpn/client/hole.crt ]]; then
1066 sgo openvpn-client@hole
1067 fi
1068
1069 ############# begin syncthing setup ###########
1070 case $HOSTNAME in
1071 kd|frodo)
1072 f=/usr/share/keyrings/syncthing-archive-keyring.gpg
1073 if [[ ! -e $f ]]; then
1074 s curl -s -o $f https://syncthing.net/release-key.gpg
1075 fi
1076 s="deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable"
1077 if [[ $(cat /etc/apt/sources.list.d/syncthing.list) != "$s" ]]; then
1078 echo "$s" | sd /etc/apt/sources.list.d/syncthing.list
1079 p update
1080 fi
1081 pi syncthing
1082 ;;&
1083 frodo)
1084 m lnf -T /w/syncthing /home/iank/.config/syncthing
1085 ser daemon-reload # syncthing likely not properly packaged
1086 sgo syncthing@iank # runs as iank
1087 ;;
1088 kd)
1089
1090 # 1003 just happens to be what was on my system
1091 if ! getent passwd ziva; then
1092 s groupadd -g 1003 ziva
1093 # syncthing state / config / db are all in ~/.config/syncthing
1094 s useradd -g 1003 -u 1003 -d /d/ziva-home -c ziva -s /bin/bash ziva
1095 fi
1096 sgo syncthing@ziva
1097 ;;
1098 esac
1099
1100 # user for short term use dropping of privileges
1101
1102 if ! getent group zu &>/dev/null; then
1103 s groupadd -g 1023 zu
1104 fi
1105 if ! getent passwd zu &>/dev/null; then
1106 s useradd -g 1023 -u 1023 -c zu -s /bin/bash zu
1107 fi
1108
1109
1110 # these things persist in ~/.config/syncthing, which I save in
1111 # /w/syncthing (not in /p, because syncthing should continue to
1112 # run on home server even when using laptop as primary device)
1113 # open http://localhost:8384/
1114 # change listen address from default to tcp://:22001,
1115 # this is because we do port forward so it doesn\'t have to use
1116 # some external server, but the syncthing is broken for port forward,
1117 # you get a message, something "like connected to myself, this should not happen"
1118 # when connecting to other local devices, so I bump the port up by 1,
1119 # based on
1120 # https://forum.syncthing.net/t/connected-to-myself-should-not-happen/1763/19.
1121 # Without this, it was being stuck syncing at 0%.
1122 # Set gui username and password.
1123 #
1124 # install syncthing via f-droid,
1125 # folder setting, turn off send only.
1126 # on phone, add device, click bar code icon
1127 # on dekstop, top right, actions, device id
1128 # after adding, notification will appear on desktop to confirm
1129 #
1130 # syncing folder. from phone to desktop: select desktop in the
1131 # folder on phone\'s sync options, notification will appear in
1132 # desktop\'s web ui within a minute. For the reverse, the
1133 # notification will appear in android\'s notifications, you have to
1134 # swipe down and tap it to add the folder. It won\'t appear in the
1135 # syncthing ui, which would be intuitive, but don\'t wait for it
1136 # there. The notification may not work, instead open the web gui
1137 # from in the app, there should be a notification within there.
1138 #
1139 # On phone, set settings to run syncthing all the time, and
1140 # show no notification.
1141 #
1142 # Folder versioning would make sense if I didn\'t already use btrfs
1143 # for backups. I would choose staggered, or trash can for more space.
1144 #
1145 # if needed to install on a remote comp:
1146 # ssh -L 8384:localhost:8384 -N frodo
1147 # open http://localhost:8384/
1148 #
1149 # Note, the other thing i did was port forward port 22000,
1150 # per https://docs.syncthing.net/users/firewall.html
1151
1152 ############# end syncthing setup ###########
1153
1154
1155
1156 ####### begin misc packages ###########
1157
1158 # old location, 2023.
1159 sudo rm -fv /etc/systemd/system/profanity.service
1160 case $HOSTNAME in
1161 kd)
1162 ln -sfT /d/p/profanity ~/.local/share/profanity
1163 ln -sfT /d/p/profanity-config ~/.config/profanity
1164 source /a/bin/bash_unpublished/source-state
1165 if [[ $HOSTNAME == "$HOST2" || ! -e /p/profanity-here ]]; then
1166 systemctl --user --now enable profanity
1167 fi
1168 ;;
1169 *)
1170
1171 ln -sfT /p/profanity ~/.local/share/profanity
1172 ln -sfT /p/profanity-config ~/.config/profanity
1173 ;;
1174 esac
1175
1176 # template
1177 case $codename in
1178 flidas)
1179 :
1180 ;;
1181 esac
1182
1183 sudo update-alternatives --set pinentry /usr/bin/pinentry-gtk-2
1184
1185
1186 # sakura config is owned by ian
1187 m reset-sakura
1188 m reset-konsole
1189 m sudo -u user2 -i reset-konsole
1190 # user2 xscreensaver we don't want to reset
1191 m reset-xscreensaver
1192
1193
1194 # this would install from cabal for newer / consistent version across os, but it screws up xmonad, so disabled for now.
1195 # this is also in primary-setup
1196 # pi libxss-dev # dependency based on build failure
1197 # cabal update
1198 # cabal install --upgrade-dependencies --force-reinstalls arbtt
1199 # also, i assume syncing this between machines somehow messed up the data.
1200
1201 ## not using arbtt for now
1202 # if mountpoint /p &>/dev/null; then
1203 # case $codename in
1204 # etiona|nabia)
1205 # pi arbtt
1206 # # same as seru enable arbtt, but works over ssh when systemctl --user causes error:
1207 # # Failed to connect to bus: No such file or directory
1208 # lnf -T /a/bin/ds/subdir_files/.config/systemd/user/arbtt.service /home/iank/.config/systemd/user/default.target.wants/arbtt.service
1209 # # allow failure
1210 # seru start arbtt ||:
1211 # ;;
1212 # esac
1213 # fi
1214 rm -fv /home/iank/.config/systemd/user/default.target.wants/arbtt.service
1215
1216
1217 m primary-setup
1218
1219 if [[ ! -e ~/.linphonerc && -e /p/.linphonerc-initial ]]; then
1220 m cp /p/.linphonerc-initial ~/.linphonerc
1221 fi
1222
1223 # linphone in t10 wont do dns with systemd-resolved or something
1224 s teeu /etc/hosts <<'EOF'
1225 74.94.156.215 watson.fsf.org
1226 EOF
1227
1228
1229
1230 ### begin spd install
1231 if mountpoint /p &>/dev/null; then
1232 pi libswitch-perl libdigest-md5-file-perl libgnupg-interface-perl
1233 t=$(mktemp)
1234 m wget -O $t http://mirror.fsf.org/fsfsys-trisquel/fsfsys-trisquel/pool/main/s/spd-perl/spd-perl_0.2-1_amd64.deb
1235 sudo dpkg -i $t
1236 m rm $t
1237 # this guesses at the appropriate directory, adjust if needed
1238 perldir=(/usr/lib/x86_64-linux-gnu/perl/5.*)
1239 m sudo ln -sf ../../../perl/5.18.2/SPD/ ${perldir[0]}
1240 # newer distro had gpg2 as default, older one, flidas, need to make it that way
1241 gpgpath=$(which gpg2) ||:
1242 if [[ $gpgpath ]]; then
1243 sudo mkdir -p /usr/local/spdhackfix
1244 s lnf -T $gpgpath /usr/local/spdhackfix/gpg
1245 fi
1246 fi
1247 ### end spd install
1248
1249
1250 # nagstamon setting which were set through the ui
1251 # monitor url https://klaxon.fsf.org/cgi-bin
1252 # monitor url cgi https://klaxon.fsf.org/cgi-bin
1253 # in filters tab:
1254 # all unknown services
1255 # all warning services
1256 # acknowledged hosts & services
1257 # hosts & services down for maintenence
1258 # services on down hosts
1259 # services on hosts in maintenece
1260 # services on unreachable osts
1261 # hosts in soft state
1262 # services in soft state
1263 # in display tab: fullscreen
1264
1265 # these translate to these settings I think
1266 # filter_acknowledged_hosts_services = True
1267 # filter_all_unknown_services = True
1268 # filter_all_warning_services = True
1269 # filter_hosts_in_soft_state = True
1270 # filter_hosts_services_maintenance = True
1271 # filter_services_in_soft_state = True
1272 # filter_services_on_down_hosts = True
1273 # filter_services_on_hosts_in_maintenance = True
1274 # filter_services_on_unreachable_hosts = True
1275 # notify_if_up = False
1276 # statusbar_floating = False
1277 # fullscreen = True
1278 # but i'm just going to rely on the webpage plus sms for now.
1279
1280
1281 # it asks if it should make users in it's group capture packets without root,
1282 # which is arguably more secure than running wireshark as root. default is no,
1283 # which is what i prefer, since I plan to use tcpdump to input to wireshark.
1284 s DEBIAN_FRONTEND=noninteractive pi wireshark-gtk
1285
1286 # /run and /dev/shm are listed as required for pulseaudio. All 4 in the group
1287 # listed in the default config as suggested.
1288 # /run/usr/1000 i noticed was missing for pulseaudio
1289 # /run/user/0 just seemed like a not bad idea, given the above
1290 tu /etc/schroot/desktop/fstab <<'EOF'
1291 /p /p none rw,bind 0 0
1292 /a /a none rw,bind 0 0
1293 /run /run none rw,bind 0 0
1294 /run/lock /run/lock none rw,bind 0 0
1295 /dev/shm /dev/shm none rw,bind 0 0
1296 /run/shm /run/shm none rw,bind 0 0
1297 /run/user/1000 /run/user/1000 none rw,bind 0 0
1298 /run/user/1001 /run/user/1001 none rw,bind 0 0
1299 /run/user/0 /run/user/0 none rw,bind 0 0
1300 EOF
1301
1302 # todo: consider if this should use the new sysd-prom-fail
1303 sd /etc/systemd/system/schrootupdate.service <<'EOF'
1304 [Unit]
1305 Description=schrootupdate
1306 After=multi-user.target
1307
1308 [Service]
1309 Type=oneshot
1310 ExecStart=/usr/local/bin/sysd-mail-once schrootupdate /a/bin/distro-setup/schrootupdate
1311 EOF
1312 sd /etc/systemd/system/schrootupdate.timer <<'EOF'
1313 [Unit]
1314 Description=schrootupdate
1315
1316 [Timer]
1317 OnCalendar=*-*-* 04:20:00 America/New_York
1318
1319 [Install]
1320 WantedBy=timers.target
1321 EOF
1322 ser daemon-reload
1323 sgo schrootupdate.timer
1324
1325
1326
1327 # for my roommate
1328 case $distro in
1329 trisquel)
1330 m mkschroot -s /a/bin/fai/fai/config/files/etc/apt/sources.list.d/bookworm.list/BOOKWORM_FREE \
1331 debian bookworm firefox-esr pulseaudio chromium
1332 ;;
1333 debian)
1334 pi chromium
1335 ;;
1336 esac
1337
1338 sudo mkdir -p /nocow/user
1339 sudo chown $USER:$USER /nocow/user
1340 pi anki
1341
1342
1343 ####### begin transmission
1344
1345 case $HOSTNAME in
1346 frodo)
1347 tdir=/i/k
1348 ;;
1349 kd)
1350 tdir=/d/tor
1351 ;;
1352 *)
1353 tdir=/nocow/user/tor
1354 ;;
1355 esac
1356
1357 sudo mkdir -p $tdir
1358
1359 # adapted from /var/lib/dpkg/info/transmission-daemon.postinst
1360 # 450 seems likely to be unused. we need to specify one or else
1361 # it won't be stable across installs.
1362 if ! getent passwd debian-transmission > /dev/null; then
1363 sudo groupadd -g 450 debian-transmission
1364 sudo adduser --quiet \
1365 --gid 450 \
1366 --uid 450 \
1367 --system \
1368 --no-create-home \
1369 --disabled-password \
1370 --home /var/lib/transmission-daemon \
1371 debian-transmission
1372 fi
1373 # We want group writable stuff from transmission.
1374 # However, after setting this, I learn that transmission sets it's
1375 # own umask based on it's settings file. Well, no harm leaving this
1376 # so it's set right from the beginning.
1377 sudo chfn debian-transmission -o umask=0002
1378
1379 # note i had to do this, which is persistent:
1380 # cd /i/k
1381 # s chgrp debian-transmission torrents partial-torrents
1382
1383 # syslog says things like
1384 # 'Failed to set receive buffer: requested 4194304, got 425984'
1385 # google suggets giving it even more than that
1386 tu /etc/sysctl.conf<<'EOF'
1387 net.core.rmem_max = 67108864
1388 net.core.wmem_max = 16777216
1389 EOF
1390 sudo sysctl -p
1391
1392 # some reason it doesn\'t seem to start automatically anyways
1393 pi-nostart transmission-daemon
1394 # be extra sure its not started
1395 ser disable transmission-daemon
1396 ser stop transmission-daemon
1397
1398 # the folder was moved here after an install around 02/2017.
1399 # it contains runtime data,
1400 # plus a simple symlink to the config file which it\'s
1401 # not worth separating out.
1402 # between comps, the uid can change
1403
1404 f=$tdir/transmission-daemon
1405 for d in $tdir/partial-torrents $tdir/torrents $f; do
1406 if [[ ! -d $d ]]; then
1407 sudo mkdir -p $d
1408 fi
1409 sudo chown -R debian-transmission:user2 $d
1410 done
1411 s lnf -T $f /var/lib/transmission-daemon/.config/transmission-daemon
1412 s lnf -T /etc/transmission-daemon/settings.json $f/settings.json
1413 sudo chown -R debian-transmission:debian-transmission $f
1414 sudo chown -R debian-transmission:debian-transmission /var/lib/transmission-daemon
1415 #
1416 # config file documented here, and it\'s the same config
1417 # for daemon vs client, so it\'s documented in the gui.
1418 # https://trac.transmissionbt.com/wiki/EditConfigFiles#Options
1419 #
1420 # I originaly setup rpc-whitelist, but after using
1421 # routing to a network namespace, it doesn\'t see the
1422 # real source address, so it\'s disabled.
1423 #
1424 # Changed the cache-size to 256 mb, reduces disk use.
1425 # It is a read & write cache.
1426 #
1427 # just fyi: default rpc port is 9091
1428 if ! systemctl is-active transmission-daemon-nn &>/dev/null && \
1429 ! systemctl is-active transmission-daemon; then
1430 tmp=$(mktemp)
1431 command sudo ruby <<EOF >$tmp
1432 require 'json'
1433 p = '/etc/transmission-daemon/settings.json'
1434 s = {
1435 'rpc-whitelist-enabled' => false,
1436 'rpc-authentication-required' => false,
1437 'incomplete-dir' => '$tdir/partial-torrents',
1438 'incomplete-dir-enabled' => true,
1439 'download-dir' => '$tdir/torrents',
1440 "speed-limit-up" => 800,
1441 "speed-limit-up-enabled" => true,
1442 "peer-port" => 61486,
1443 "cache-size-mb" => 256,
1444 "ratio-limit" => 5.0,
1445 "ratio-limit-enabled" => false,
1446 }
1447 puts(JSON.pretty_generate(JSON.parse(File.read(p)).merge(s)))
1448 EOF
1449 cat $tmp | sudo dd of=/etc/transmission-daemon/settings.json
1450
1451 fi
1452
1453 ####### end transmission
1454
1455 case $HOSTNAME in
1456 kd)
1457 # to persist upload/dl metadata. initially, moved all the stuff
1458 # in /var/lib/transmission-daemon to /d/tor
1459 s usermod --home /d/tor debian-transmission
1460 sgo transmission-daemon-nn
1461
1462 ;;
1463 esac
1464
1465
1466 ######### begin transmission client setup ######
1467
1468 # to connect from a remote client, trans-remote-route in brc2
1469
1470
1471 if [[ -e /p/transmission-rpc-pass ]]; then
1472 # arch had a default config,
1473 # debian had nothing until you start it.
1474 # With a little trial an error, here is a minimal config
1475 # taken from the generated one, plus changes that the
1476 # settings ui does, without a bunch of ui crap settings.
1477 #
1478 # only settings I set were
1479 # hostname
1480 # auto-connect
1481 # password
1482
1483 # the password is randomly generated on first run, i copied it out
1484 # so it could be used by other hosts.
1485 sudo ruby <<'EOF'
1486 require 'json'
1487 p = '/etc/transmission-daemon/settings.json'
1488 s = JSON.parse(File.read(p))
1489 s["rpc-password"] = File.read("/p/transmission-rpc-pass").chomp
1490 # default is 0022 (18 in decimal)
1491 s["umask"] = 2
1492 File.write p, JSON.pretty_generate(s)
1493 EOF
1494
1495 rpc_pass=$(</p/transmission-rpc-pass)
1496 for f in /home/*; do
1497 u=${f##*/}
1498 uid=$(id -u $u 2>/dev/null) || continue
1499 if [[ ! $uid -ge 1000 ]]; then
1500 continue
1501 fi
1502 d=$f/.config/transmission-remote-gtk
1503 sudo -u $u mkdir -p $d
1504 # i tried setting hostname to transmission.b8.nz, so i could dynamically change where
1505 # this connects to, but it said some 421 denied error when I did that. Then it
1506 # froze X when i ran it under strace. Whatever.
1507 sudo -u $u dd of=$d/config.json <<EOF
1508 {
1509 "profiles" : [
1510 {
1511 "profile-name" : "Default",
1512 "hostname" : "10.174.2.2",
1513 "rpc-url-path" : "/transmission/rpc",
1514 "username" : "",
1515 "password" : "$rpc_pass",
1516 "auto-connect" : true,
1517 "ssl" : false,
1518 "timeout" : 40,
1519 "retries" : 3,
1520 "update-active-only" : false,
1521 "activeonly-fullsync-enabled" : false,
1522 "activeonly-fullsync-every" : 2,
1523 "update-interval" : 3,
1524 "min-update-interval" : 3,
1525 "session-update-interval" : 60,
1526 "exec-commands" : [],
1527 "destinations" : []
1528 }
1529 ],
1530 "profile-id" : 0,
1531 "add-options-dialog" : false
1532 }
1533 EOF
1534 done
1535 fi
1536 ######### end transmission client setup ######
1537
1538
1539 ### printer setup
1540 pi cups
1541
1542 sudo gpasswd -a $USER lpadmin # based on ubuntu wiki
1543 # goto http://127.0.0.1:631
1544 # administration tab, add new printer button.
1545 # In debian, I could use hte recommended driver,
1546 # in arch, I had to pick out the 6L driver.
1547
1548
1549 # bridge networking as user fails. google lead here, but it doesn\'t work:
1550 # oh well, I give up.
1551 # http://wiki.qemu.org/Features-Done/HelperNetworking
1552 # s mkdir /etc/qemu
1553 # f=/etc/qemu/bridge.conf
1554 # sd $f <<'EOF'
1555 # allow br0
1556 # EOF
1557 # #s chown root:qemu $f # debian has somethig like qemu-libvirt. equivalent?
1558 # s chmod 640 $f
1559
1560 # general known for debian/ubuntu, not for fedora
1561
1562 m /a/bin/buildscripts/go
1563 # only needed for rg. cargo takes up 11 gigs, filled up the disk on je.
1564 m /a/bin/buildscripts/rust
1565 m /a/bin/buildscripts/misc
1566 m /a/bin/buildscripts/pithosfly
1567 #m /a/bin/buildscripts/alacritty
1568 #m /a/bin/buildscripts/kitty
1569
1570 pi-nostart virtinst virt-manager
1571 soff libvirtd
1572 # i cant if this is whats causing it to start even though
1573 # its disabled. note: it leaves around dnsmasq instances even
1574 # if you stop it. what the hell systemd?
1575 soff libvirt-guests
1576 # allow user to run vms, from debian handbook. libvirt-qemu
1577 # based on https://www.whonix.org/wiki/KVM#First-time_User.3F
1578 for x in iank user2; do s usermod -a -G libvirt,kvm,libvirt-qemu $x; done
1579
1580
1581 pi --no-install-recommends kdeconnect
1582 ### kdeconnect for gnome. started in /a/bin/distro-setup/desktop-20-autostart.sh
1583 ### but gnome + xmonad not working in flidas, so i disabled it
1584 # pi libgtk-3-dev python3-requests-oauthlib valac cmake python-nautilus libappindicator3-dev
1585 # cd /a/opt/indicator-kdeconnect
1586 # mkdir -p build
1587 # cd build
1588 # cmake .. -DCMAKE_INSTALL_PREFIX=/usr
1589 # make
1590 # sudo make install
1591 # # we can start it manually with /usr/lib/x86_64-linux-gnu/libexec/kdeconnectd
1592 # # it seems, according to
1593 # # /etc/xdg/autostart/kdeconnectd.desktop
1594 # # I'm not seeing the icon, but the clipboard replication is working
1595
1596
1597 ### begin model 01 arduino support ###
1598 # https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux
1599 # also built latest arduino in /a/opt/Arduino, (just cd build; ant build; ant run )
1600 # set arduino var in bashrc,
1601 # have system config file setup too.
1602 sudo adduser $USER dialout
1603
1604 # as of 2022-05,
1605 # download arduino ide, extract in /a/opt, ignore the install script, run ./arduino,
1606 # toolbar, preferences, add board manager url:
1607 # https://raw.githubusercontent.com/keyboardio/boardsmanager/master/package_keyboardio_index.json
1608 # toolbar, board manager, add keyboardio
1609 # toolbar, select model01 board
1610 # toolbar, examples, model01, compile
1611
1612 ###
1613
1614 # this is for the mail command too. update-alternatives is kind of misleading
1615 # since at least it's main commands pretend mail does not exist.
1616 # bsd's mail got pulled in on some dumb dependency, i dunno how.
1617 sudo update-alternatives --set mailx /usr/bin/mail.mailutils
1618
1619 ######### end misc packages #########
1620
1621
1622 # packages I once used before and liked, but don\'t want installed now for
1623 # various reasons:
1624 # python-sqlite is used for offlineimap
1625 # lxappearance python-sqlite dolphin paman dconf-editor
1626
1627
1628
1629 ######## unfinished
1630
1631 # todo, finish configuring smart.
1632
1633 pi smartmontools
1634 # mostly from https://wiki.archlinux.org/index.php/S.M.A.R.T.
1635 # turn on smart. background on options:
1636 # first line, -a = test everyting on all devices.
1637 # -S on, turn on disk internal saving of vendor specific info,
1638 # from google, seems like this is usually already on and fairly standard.
1639 # -o on, turn on 4 hour period non-performance degrading testing.
1640 # short test daily 2-3am, extended tests Saturdays between 3-4am:
1641 sched="-s (S/../.././02|L/../../6/03)"
1642 sudo sed -i --follow-symlinks "s#^[[:space:]]*DEVICESCAN.*#\
1643 DEVICESCAN -a -o on -S on -n standby,q $sched \
1644 -m root@mail.iankelling.org -M exec /usr/local/bin/smart-notify#" /etc/smartd.conf
1645
1646 # in the default configuration of at least ubuntu 14.04, resolvconf is
1647 # configured to order any nameservers associated with tun* or tap*
1648 # before the normal internet interfaces, which means they are always
1649 # consulted first. This is often slower and undesirable, ie. local dns
1650 # queries go from 0ms to 10+ or 100+ ms. To reverse the ordering, you
1651 # can do:
1652 #sudo sed -i --follow-symlinks '/tun\*\|tap\*/d' /etc/resolvconf/interface-order
1653 # however, this breaks dns lookup for hosts on the openvpn lan.
1654 # I can\'t figure out why hosts on the normal lan would not be
1655 # broken under the default ordering, except the host I was
1656 # testing with previously had an entry in /etc/hosts.
1657
1658 ############# end unfinished
1659
1660 ########### misc stuff
1661
1662
1663 xdg-settings set default-web-browser abrowser.desktop
1664 # see current with:
1665 # xdg-settings get default-web-browser
1666
1667 # pressing tab after sdf here:
1668 # scp sdfbash: set +o noglob: command not found
1669 # in t11, bash 5.1.16. this fixes it.
1670 sudo sed -ri 's/([[:space:]]*)(\$reset)$/\1set +o noglob #$reset/' /usr/share/bash-completion/bash_completion
1671
1672 rm -fv /home/iank/.mpv/watch_later
1673 rm -rf /home/iank/.mpv
1674
1675 if [[ ! -e ~/.local/bin/pip ]]; then
1676 tmp=$(mktemp)
1677 wget -O$tmp https://bootstrap.pypa.io/get-pip.py
1678 python3 $tmp --user
1679 hash -r
1680 fi
1681
1682 ## begin beets
1683 # soo, apt install beets fails due to wanting a pip package,
1684 # we find out why it wants this through
1685 # apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances beets | less
1686 # python-mediafile requires tox, which requires virtualenv, which requires pip.
1687 # but, python-mediafile doesn't really require tox, it is specified in
1688 # ./usr/lib/python3/dist-packages/mediafile-0.9.0.dist-info/METADATA
1689 # as being required only for testing, but the debian package
1690 # included it anyways, due to a mistake or bad tooling or something.
1691 # I don't plan to use tox, so, according to https://serverfault.com/a/251091,
1692 # we can create and install a dummy package by:
1693 #
1694 # "equivs-control <name>, edit the file produced to provide the right
1695 # dependency and have a nice name, then run equivs-build <name> and
1696 # finally dpkg -i the resulting .deb file"
1697 # as of 2023-02, the tox dependency was removed in debian unstable, so
1698 # this hack will probably go away in t12.
1699
1700 if pcheck beets; then
1701 tmpdir="$(mktemp -d)"
1702 cd "$tmpdir"
1703 # edited from output of equivs-control tox
1704 cat >tox <<'EOF'
1705 Section: python
1706 Priority: optional
1707 Standards-Version: 3.9.2
1708 Package: tox
1709 Description: tox-dummy
1710 EOF
1711 equivs-build tox
1712 sudo dpkg -i tox_1.0_all.deb
1713 rm -rf ./tox*
1714 pi beets python3-discogs-client
1715 cd
1716 rm -r "$tmpdir"
1717 fi
1718
1719 # get rid of annoying message
1720 s sed -ri "s/^([[:space:]]*ui.print_\('Playing)/#\1/" /usr/share/beets/beetsplug/play.py
1721
1722
1723 # notes about barrier
1724 # run barrier, do the gui config,
1725 # setup the 2 screens, using hostnames for the new screen.
1726 # save the server config
1727 # $HOME/.local/share/barrier/.barrier.conf
1728 # per the man page.
1729 #
1730 # ssl errors, resolved via advice here: https://github.com/debauchee/barrier/issues/231
1731 # BARRIER_SSL_PATH=~/.local/share/barrier/SSL/
1732 # mkdir -p "${BARRIER_SSL_PATH}"
1733 # openssl req -x509 -nodes -days 365 -subj /CN=Barrier -newkey rsa:4096 -keyout ${BARRIER_SSL_PATH}/Barrier.pem -out ${BARRIER_SSL_PATH}/Barrier.pem
1734 # ran on both machines.
1735 # When pressing start in the gui, the cli options used are printed to the console,
1736 # they are useful. So on server, just run barriers, client run barrierc SERVER_IP
1737
1738 ### begin timetrap setup
1739 if mountpoint /p &>/dev/null; then
1740 mkdir -p ~/.timetrap/
1741 ln -sf /a/opt/timetrap_formatters ~/.timetrap/formatters
1742 if ! type -p t &>/dev/null; then
1743 pi ruby-dev libsqlite3-dev
1744 gem install --user timetrap
1745 fi
1746 fi
1747 ### end timetrap setup
1748
1749 # leftover cleanup for t9
1750 pu resolvconf
1751
1752 case $codename in
1753 # needed for debootstrap scripts for fai since fai requires debian
1754 flidas)
1755 pi dnsmasq
1756 pi-nostart network-manager
1757 # i hate networkmanager. noo, of course disabling it doesnt work
1758 # unless you add a hack. found this by doing
1759 # systemd-analyze dot > x.dot
1760 # less x.dot
1761 # /networkman
1762 soff NetworkManager
1763 soff NetworkManager-wait-online.service
1764 # make networkmanager use resolvconf instead of its own dnsmasq which
1765 # conflicts with the normal dnsmasq package.
1766 f=/etc/NetworkManager/NetworkManager.conf
1767 m=$(md5sum $f)
1768 sudo sed -ri '/ *\[main\]/,/^ *\[[^]]+\]/{/^\s*dns[[:space:]=]/d}' $f
1769 sudo sed -ri '/ *\[main\]/a dns=default' $f
1770 if [[ $m != $(md5sum $f) ]]; then
1771 srestart NetworkManager
1772 fi
1773 # networkmanager has this nasty behavior on flidas: if the machine
1774 # crashes with dnsmasq running, on subsequent boot, it adds an entry to
1775 # resolvconf for 127.0.0.1 in some stupid attempt to restore
1776 # nameservers.
1777 # This can be manually fixed by stoping dnsmasq,
1778 # then based on whats in /run/dnsmasq/, i see we can run
1779 # s resolvconf -d NetworkManager
1780 # oh ya, and stoping NetworkManager leaves this crap behind without cleaning it up.
1781 ser disable NetworkManager
1782 ;;
1783 esac
1784
1785 # I have no use for avahi,
1786 # had to run this twice when doing manually, i dunno why
1787 soff avahi-daemon ||:
1788 sleep 1
1789 soff avahi-daemon
1790
1791 # make my /etc/fonts/conf.d/ get used.
1792 # I have a new sans-serif font there because the default one
1793 # displays l and I as the same char, grrrrr.
1794 sudo fc-cache
1795
1796 pi desktop-file-utils
1797 m /a/bin/distro-setup/mymimes
1798
1799 if type -p dbus-launch >/dev/null; then
1800 # stop autopoping windows when i plug in an android phone.
1801 # dbus-launch makes this work within an ssh connection, otherwise you get this message,
1802 # with still 0 exit code.
1803 # dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
1804 m dbus-launch gsettings set org.gnome.desktop.media-handling automount-open false
1805 fi
1806
1807 # on grub upgrade, we get prompts unless we do this
1808 devs=()
1809 for dev in $(s btrfs fil show /boot | sed -nr 's#.*path\s+(\S+)$#\1#p'); do
1810 devs+=("$(devbyid $dev),")
1811 done
1812 devs[-1]=${devs[-1]%,} # jonied by commas
1813 sudo debconf-set-selections <<EOF
1814 grub-pc grub-pc/install_devices multiselect ${devs[*]}
1815 EOF
1816
1817
1818 sysd-prom-fail-install dynamicipupdate
1819 sysd-prom-fail-install systemstatus
1820 sysd-prom-fail-install btrfsmaintstop
1821 sgo btrfsmaint.timer
1822 sgo btrfsmaintstop
1823 sgo systemstatus
1824 sgo dynamicipupdate
1825
1826
1827 if grep -xFq $HOSTNAME /a/bin/ds/machine_specific/btrbk.hosts; then
1828 sgo btrbk.timer
1829 fi
1830
1831 # note: to see when a timer was last run,
1832 # ser list-timers
1833
1834
1835 ### begin prometheus ###
1836
1837 case $HOSTNAME in
1838 kd)
1839 # Font awesome is needed for the alertmanager ui.
1840 pi prometheus-alertmanager prometheus fonts-font-awesome
1841 /c/roles/prom/files/simple/usr/local/bin/fsf-install-prometheus
1842 # make it available for other machines
1843 rsync -a /usr/local/bin/amtool /a/opt/bin
1844 web-conf -p 9091 -f 9090 - apache2 i.b8.nz <<'EOF'
1845 <Location "/">
1846 AuthType Basic
1847 AuthName "basic_auth"
1848 # created with
1849 # htpasswd -c prometheus-htpasswd USERNAME
1850 AuthUserFile "/etc/prometheus-htpasswd"
1851 Require valid-user
1852 </Location>
1853 EOF
1854
1855 web-conf -p 9094 -f 9093 - apache2 i.b8.nz <<'EOF'
1856 <Location "/">
1857 AuthType Basic
1858 AuthName "basic_auth"
1859 # created with
1860 # htpasswd -c prometheus-htpasswd USERNAME
1861 AuthUserFile "/etc/prometheus-htpasswd"
1862 Require valid-user
1863 </Location>
1864 EOF
1865
1866 # by default, the alertmanager web ui is not enabled other than a page
1867 # that suggests to use the amtool cli. that tool is good, but you cant
1868 # silence things nearly as easily as with the gui.
1869 if [[ ! -e /usr/share/prometheus/alertmanager/ui/index.html ]]; then
1870 # default script didnt work, required some changes to get elm 19.1,
1871 # which is a dependency of the latest alertmanager. I modified
1872 # and copied it into /b/ds. In future, might need some other
1873 # solution.
1874 #sudo /usr/share/prometheus/alertmanager/generate-ui.sh
1875 sudo /b/ds/generate-ui.sh
1876 ser restart prometheus-alertmanager
1877 fi
1878
1879 s /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter -l 127.0.0.1
1880
1881 for ser in prometheus-node-exporter prometheus-alertmanager prometheus; do
1882 sysd-prom-fail-install $ser
1883 done
1884
1885 ;;
1886 *)
1887 s /c/roles/prom_export/files/simple/usr/local/bin/fsf-install-node-exporter
1888 ;;
1889 esac
1890
1891 # cleanup old files. 2023-02
1892 x=(/var/lib/prometheus/node-exporter/*.premerge)
1893 if [[ -e ${x[0]} ]]; then
1894 s rm /var/lib/prometheus/node-exporter/*
1895 fi
1896
1897
1898 case $HOSTNAME in
1899 # todo, for limiting node exporter http,
1900 # either use iptables or, in
1901 # /etc/default/prometheus-node-exporter
1902 # listen on the wireguard interface
1903
1904 *)
1905 wgip=$(command sudo sed -rn 's,^ *Address *= *([^/]+).*,\1,p' /etc/wireguard/wghole.conf)
1906 # old filename. remove once all hosts are updated.
1907 s rm -fv /etc/apache2/sites-enabled/${HOSTNAME}wg.b8.nz.conf
1908 web-conf -i -a $wgip -p 9101 -f 9100 - apache2 ${HOSTNAME}wg.b8.nz <<'EOF'
1909 <Location "/">
1910 AuthType Basic
1911 AuthName "basic_auth"
1912 # created with
1913 # htpasswd -c prometheus-export-htpasswd USERNAME
1914 AuthUserFile "/etc/prometheus-export-htpasswd"
1915 Require valid-user
1916 </Location>
1917 EOF
1918 # For work, i think we will just use the firewall for hosts in the main data center, and
1919 # vpn for hosts outside it.
1920
1921 # TODO: figure out how to detect the ping failure and try again.
1922
1923 # Binding to the wg interface, it might go down, so always restart, and wait for it on boot.
1924 s mkdir /etc/systemd/system/apache2.service.d
1925 sd /etc/systemd/system/apache2.service.d/restart.conf <<EOF
1926 [Unit]
1927 After=wg-quick@wghole.service
1928 StartLimitIntervalSec=0
1929
1930 [Service]
1931 Restart=always
1932 RestartSec=30
1933 EOF
1934
1935 ;;
1936 esac
1937
1938 ### end prometheus ###
1939
1940 ### begin nagios ###
1941
1942 pi nagios-nrpe-server
1943
1944 case $HOSTNAME in
1945 kd)
1946 # the backport is for this bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800345
1947 pi nagios4 nagios-nrpe-plugin monitoring-plugins-basic/bullseye-backports
1948 s rm -fv /etc/apache2/conf-enabled/nagios4-cgi.conf
1949
1950 # to add a password for admin:
1951 # htdigest /etc/nagios4/htdigest.users Nagios4 iank
1952 # now using the same pass as prometheus
1953
1954 # nagstamon auth settings, set to digest instead of basic.
1955
1956 web-conf -p 3005 - apache2 i.b8.nz <<'EOF'
1957 # adapted from /etc/apache2/conf-enabled/nagios4-cgi.conf
1958
1959 ScriptAlias /cgi-bin/nagios4 /usr/lib/cgi-bin/nagios4
1960 ScriptAlias /nagios4/cgi-bin /usr/lib/cgi-bin/nagios4
1961
1962 # Where the stylesheets (config files) reside
1963 Alias /nagios4/stylesheets /etc/nagios4/stylesheets
1964
1965 # Where the HTML pages live
1966 Alias /nagios4 /usr/share/nagios4/htdocs
1967
1968 <DirectoryMatch (/usr/share/nagios4/htdocs|/usr/lib/cgi-bin/nagios4|/etc/nagios4/stylesheets)>
1969 Options FollowSymLinks
1970 DirectoryIndex index.php index.html
1971 AllowOverride AuthConfig
1972 #
1973 # The default Debian nagios4 install sets use_authentication=0 in
1974 # /etc/nagios4/cgi.cfg, which turns off nagos's internal authentication.
1975 # This is insecure. As a compromise this default apache2 configuration
1976 # only allows private IP addresses access.
1977 #
1978 # The <Files>...</Files> below shows how you can secure the nagios4
1979 # web site so anybody can view it, but only authenticated users can issue
1980 # commands (such as silence notifications). To do that replace the
1981 # "Require all granted" with "Require valid-user", and use htdigest
1982 # program from the apache2-utils package to add users to
1983 # /etc/nagios4/htdigest.users.
1984 #
1985 # A step up is to insist all users validate themselves by moving
1986 # the stanza's in the <Files>..<Files> into the <DirectoryMatch>.
1987 # Then by setting use_authentication=1 in /etc/nagios4/cgi.cfg you
1988 # can configure which people get to see a particular service from
1989 # within the nagios configuration.
1990 #
1991 AuthDigestDomain "Nagios4"
1992 AuthDigestProvider file
1993 AuthUserFile "/etc/nagios4-htdigest.users"
1994 AuthGroupFile "/etc/group"
1995 AuthName "Nagios4"
1996 AuthType Digest
1997 Require valid-user
1998 </DirectoryMatch>
1999
2000 <Directory /usr/share/nagios4/htdocs>
2001 Options +ExecCGI
2002 </Directory>
2003 EOF
2004 ;;
2005 esac
2006
2007 # when you alter a service through the web, it changes vars in /var/lib/nagios4/status.dat. for example:
2008 # notifications_enabled=1
2009 # note, the same variable exists in the correspdonding "define service {"
2010
2011 # in the default config, we have these definitions
2012
2013 # 11 define command {
2014 # 2 define contact {
2015 # 1 define contactgroup {
2016 # 9 define host {
2017 # 4 define hostgroup {
2018 # 23 define service {
2019 # 5 define timeperiod {
2020
2021
2022 # on klaxon
2023
2024 # klaxon:/etc/nagios3 # grep -rho '^ *define [^{ ]*' | sort | uniq -c
2025 # 76 define command
2026 # 11 define contact
2027 # 6 define contactgroup
2028 # 162 define host
2029 # 1 define hostextinfo
2030 # 16 define hostgroup
2031 # 3040 define service
2032 # 2 define servicedependency
2033 # 6 define timeperiod
2034
2035
2036
2037
2038 ### end nagios ###
2039
2040 ### begin bitcoin ###
2041
2042 case $HOSTNAME in
2043 sy|kd)
2044 sudo install -m 0755 -o root -g root -t /usr/bin /a/opt/bitcoin-26.0/bin/*
2045 # Note: i leave it to system-status to start and stop bitcoin.
2046 # note: the bitcoin user & group are setup in fai
2047 sudo usermod -a -G bitcoin iank
2048 # todo: make bitcoin have a stable uid/gid
2049 sudo mkdir -p /var/lib/bitcoind
2050 sudo chown bitcoin:bitcoin /var/lib/bitcoind
2051 # 710 comes from the upstream bitcoin unit file
2052 sudo chmod 710 /var/lib/bitcoind
2053 # note, there exists
2054 # /a/bin/ds/disabled/bitcoin
2055 ;;
2056 esac
2057
2058 ### end bitcoin
2059
2060 ### begin live streaming ###
2061
2062 # comparing nginx rtmp to icecast
2063 # `mpv --cache=no` had about 2.5 sec latency vs 4 seconds.
2064 # Then I discovered this command which had about .5 sec latency:
2065 #ffplay -f live_flv -fast -x 1280 -y 720 -fflags nobuffer -flags low_delay -strict experimental -vf "setpts=N/60/TB" -af "asetpts=N/60/TB" -noframedrop -i rtmp://url_here
2066 ## a lot of those args arent needed, here is what I ended up with:
2067 # #ffplay -f live_flv -fflags nobuffer -flags low_delay -i rtmp://localhost/live
2068 #
2069 # A problem with rtmp is that it doesn't support vp8/vp9, requiring the partly patent encumbered h264.
2070 # Looking at alternative protocols: dash & hls are both high latency, I tested dash with the nginx-rtmp
2071 # module and got about 5 seconds of latency, web results imply that is normal.
2072 #
2073 # Webrtc is what jitsi & bbb use, but an annoying thing is that
2074 # generally requires a web browser with javascript, or some special
2075 # client, and afaik, it has a smaller limit on number of clients.
2076 #
2077 # Another option is to try rtp/rtsp, there are some servers here:
2078 # https://en.wikipedia.org/wiki/Real-Time_Streaming_Protocol
2079
2080
2081 ## reference for setting up rtmp
2082 # pi nginx libnginx-mod-rtmp
2083 # cat >/etc/nginx/modules-enabled/rtmp.conf <<'EOF'
2084 ## based on https://opensource.com/article/19/1/basic-live-video-streaming-server#comments
2085 ## and https://github.com/arut/nginx-rtmp-module/wiki/Directives
2086
2087 # rtmp {
2088 # allow publish 127.0.0.1;
2089 # deny publish all;
2090 # server {
2091 # listen 1935;
2092 # application live {
2093 # live on;
2094 # record off;
2095 # }
2096 # }
2097 # }
2098 # EOF
2099
2100 ### end live streaming ###
2101
2102 ### begin gh ####
2103
2104 # from https://raw.githubusercontent.com/cli/cli/trunk/docs/install_linux.md
2105 # One time setup afterwards:
2106 # gh auth login
2107 #
2108 # When it gets to the page where it asks to authorize github, the button
2109 # is grayed out. You can just open browser dev tools, inspect the
2110 # button, remove disabled="", then click it and it works.
2111 #
2112 # Auth token gets saved into /p/c/subdir_files/.local/share/keyrings/
2113 #
2114 # initial config goes to /home/iank/.config/gh
2115 curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
2116 && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
2117 && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
2118 && sudo apt update \
2119 && sudo apt install gh -y
2120
2121 ### end gh ####
2122
2123 # remove trisquel banner. it is cool but takes up too much space.
2124 sudo rm -f /etc/update-motd.d/01-banner
2125
2126 case $HOSTNAME in
2127 kw|x3)
2128 sd /etc/cups/client.conf <<'EOF'
2129 ServerName printserver1.office.fsf.org
2130 EOF
2131 ;;
2132 esac
2133
2134
2135 end_msg <<'EOF'
2136 In mate settings settings, change scrolling to two-finger,
2137 because the default edge scroll doesn\'t work. Originally found this in debian.
2138 EOF
2139
2140 # Remove dep that came in with desktop to fix associations.
2141 m pu transmission-gtk
2142
2143 case $HOSTNAME in
2144 kd)
2145 lnf -T /d/vidshare /home/iank/Videos
2146 ;;
2147 esac
2148
2149 # # Based on guix manual instructions, also added code to profile.
2150 # # disabled since i'm not using it now.
2151 # pi nscd
2152 # if ! type -p guix >/dev/null; then
2153 # cd $(mktemp -d)
2154 # wget https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh
2155 # # added some stuff to envonment.sh for profile based on
2156 # # manual instructions
2157 # # wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -
2158 # # echo is to get past prompt
2159 # yes | sudo -E HOME=$HOME bash guix-install.sh || [[ $? == 141 ]]
2160 # guix install glibc-utf8-locales
2161 # guix package --install guile
2162 # fi
2163
2164 lnf -T /a/opt ~/src
2165
2166 pi tor
2167 m /a/bin/buildscripts/tor-browser
2168 # one root command needed to install
2169 s ln -sf /a/opt/tor-browser/Browser/start-tor-browser /usr/local/bin
2170
2171
2172 case $HOSTNAME in
2173 kd)
2174 web-conf -p 4500 -f 4533 -e ian@iankelling.org apache2 b8.nz
2175 sgo navidrome
2176 ;;
2177 esac
2178
2179 # nfs server
2180 pi-nostart nfs-kernel-server
2181
2182 # todo, this is old, probably needs removing
2183 if [[ $HOSTNAME == tp ]]; then
2184 sd /etc/wireguard/wg0.conf <<EOF
2185 [Interface]
2186 PrivateKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.key)
2187 Address = 10.3.0.2/24, fdfd::2/64
2188
2189 [Peer]
2190 PresharedKey = $(cat /p/c/machine_specific/tp/filesystem/root/wg.psk)
2191 PublicKey = 9RnAsJB+ISrA/9lmDKBoT08oBiKwzA64exBBj+rO+ng=
2192 Endpoint = b8.nz:26000
2193 AllowedIPs = 10.3.0.1/24, fdfd::1/64
2194 PersistentKeepalive = 20
2195 EOF
2196 sudo systemctl enable wg-quick@wg0
2197 sudo systemctl start wg-quick@wg0
2198 fi
2199
2200
2201 if [[ $HOSTNAME == kw ]]; then
2202 # hosts 1-199. 200+ are dynamic, avoid those
2203 tu /etc/exports <<'EOF'
2204 /root/.ianktrisquel_9/.iank/e/e 192.168.0.0/25(rw,no_root_squash,async,no_subtree_check) 192.168.0.128/26(rw,no_root_squash,async,no_subtree_check) 192.168.0.192/29(rw,no_root_squash,async,no_subtree_check)
2205 /home/iank/.iank/e/e 192.168.0.0/25(rw,no_root_squash,async,no_subtree_check) 192.168.0.128/26(rw,no_root_squash,async,no_subtree_check) 192.168.0.192/29(rw,no_root_squash,async,no_subtree_check)
2206 EOF
2207 ekw
2208 sgo nfs-server
2209 sudo exportfs -rav
2210 fi
2211
2212
2213 # if I was going to create a persistent vm, i might do it like this:
2214 # variant=something # from: virt-install --os-variant list
2215 # s virt-install --noautoconsole --graphics spice,listen=0.0.0.0 \
2216 # --disk=/a/images/some_name.qcow2,bus=virtio --vcpus 2 -r 4096 -w bridge=br0 \
2217 # -n some_name --import --os-variant $variant --cpu host-model-only
2218
2219
2220 # for brother HL-2270DW, this worked:
2221 # https://askubuntu.com/questions/1067234/cant-use-wireless-brother-printer-2270dw-ubuntu-18-04
2222 # /a/opt/linux-brprinter-installer-2.2.2-1
2223 # answer n when it asks about uri.
2224 # Then go to cups, delete the existing printer, added on with dnssd url. browsed to
2225 # ppd at /usr/share/ppd/HL2270DW.ppd, which is duplicated at /usr/share/cups/model/HL2270DW.ppd
2226 # ppd file got installed from bash -x ./usr/local/Brother/Printer/HL2270DW/cupswrapper/cupswrap,
2227 # which I downloaded from their driver. but dont do that again, i copied it to /a/opt/HL2270DW.ppd,
2228 # use that.
2229
2230 # I had to reset it to use wired instead of wifi. it only uses 1 at a time. boot with go button held, after lights turn off, tap go 6 times.
2231 # Then it was already configured, but if i needed to, go to its web ui, default pass is "access".
2232
2233 ######### begin stuff belonging at the end ##########
2234
2235 end