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