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