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