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