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