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