lots of fixes, automation for bitfolk
[distro-setup] / distro-begin
1 #!/bin/bash
2 # Copyright (C) 2016 Ian Kelling
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # for setting up a new machine
17 # usage: $0 [-r] [HOSTNAME]
18 # HOSTNAME changes the machine's hostname
19
20 # tips:
21 # run any sudo command first so your pass is cached
22 # set the scrollback to unlimited in case something goes wrong
23
24
25 # send to registrar, glue records:
26 # for iankelling.org:
27
28 # ns1.iankelling.org 72.14.176.105
29 # ns1.iankelling.org 2600:3c00::f03c:91ff:fe6d:baf8
30 # ns2.iankelling.org 172.105.84.95
31 # ns2.iankelling.org 2a01:7e01::f03c:91ff:feb5:baec
32
33 # for zroe.org:
34
35 # ns1.zroe.org 72.14.176.105
36 # ns1.zroe.org 2600:3c00::f03c:91ff:fe6d:baf8
37 # ns2.zroe.org 172.105.84.95
38 # ns2.zroe.org 2a01:7e01::f03c:91ff:feb5:baec
39 #
40
41
42
43 ####### begin setup environment #######
44
45
46 ### make ssh interactive shell run better. for when running line interactively line by line
47 sudo bash -c '/a/exe/ssh-emacs-setup'
48
49 ##### setup error handling
50 interactive=true # set this to false to force set -x
51 [[ $- == *i* ]] || interactive=false
52 if ! $interactive; then
53 set -x
54 fi
55 source /a/bin/errhandle/err
56
57 mkdir -p ~/.local
58 err-cleanup() {
59 echo 1 >~/.local/distro-begin
60 }
61
62 source /a/bin/distro-functions/src/package-manager-abstractions
63
64 ### setup logging
65 echo "$0: $(date): starting now)"
66
67
68 ### sanity checking
69 if [[ $EUID == 0 ]]; then
70 if getent passwd iank || getent passwd ian ; then
71 echo "$0: error: running as root. unprivileged user exists. use it."
72 exit 1
73 else
74 echo "$0: warning: running as root. I will setup users then exit"
75 fi
76 fi
77
78
79 ### arg parsing
80 recompile=false
81 emacs=false
82 if [[ -e /a/opt/emacs ]]; then
83 emacs=true
84 fi
85 while [[ $1 == -* ]]; do
86 case $1 in
87 -r) recompile=true; shift ;;
88 -e) emacs=false; shift ;;
89 esac
90 done
91 if [[ $1 ]]; then
92 export HOSTNAME=$1
93 fi
94
95
96 ##### variables/env setup
97 script_dir="$(readlink -f "${BASH_SOURCE[@]}")"; script_dir=${script_dir%/*}
98 # shellcheck source=./pkgs
99 source $script_dir/pkgs
100 set +x
101 source /a/bin/distro-functions/src/identify-distros
102 $interactive || set -x
103 for f in kd x2 x3 frodo tp li bk je demohost kw sy bo; do
104 eval "$f() { [[ $HOSTNAME == $f ]]; }"
105 done
106 codename=$(debian-codename)
107 bitfolk() { je || bk; }
108 has_wayland() { has_monitor && [[ $codename == buster ]]; }
109 has_x() { has_monitor && [[ $codename != buster ]]; }
110 has_monitor() { ! vps ; }
111 vps() { bitfolk || li; }
112 # linode actually has btrfs now, but we dont do anything with it.
113 has_btrfs() { ! vps; }
114 home_network() { ! vps && ! tp; }
115 has_p() { ! vps && ! tp; }
116 encrypted() { ! bitfolk; }
117 shopt -s extglob
118 export GLOBIGNORE="*/.:*/.."
119 umask 022
120 PATH="/a/exe:$PATH"
121 sed="sed --follow-symlinks"
122
123 ####### end setup environment #######
124
125
126 ##### begin setup encryption scripts ######
127 if encrypted; then
128 # I tried making a service which was dependent on reboot.target,
129 # but it happened too late in the shutdown process.
130 sudo dd of=/etc/systemd/system/keyscripton.service <<'EOF'
131 [Unit]
132 Description=keyscripton
133 # This is triggered by reboot and when keyscriptoff stops.
134
135 # tried using graphical.target, but it made my display manager restart before rebooting.
136 # generally, I don't think targets order shutdown like they do startup.
137 # So, I did systemd-analyze plot > something.svg, and picked a reliably started
138 # service that happens late in the game.
139 After=ntp.service
140 DefaultDependencies=no
141 # not sure if needed, makes sure we shut down before reboot.target
142 Conflicts=reboot.target
143
144 [Service]
145 Type=oneshot
146 RemainAfterExit=yes
147 ExecStart=/bin/true
148 ExecStop=/a/exe/keyscript-on
149
150 [Install]
151 WantedBy=keyscriptoff.service
152 EOF
153 sudo systemctl daemon-reload # needed if the file was already there
154 sudo systemctl enable keyscripton.service
155
156 sudo dd of=/etc/systemd/system/keyscriptoff.service <<'EOF'
157 [Unit]
158 Description=keyscriptoff
159
160 [Service]
161 Type=oneshot
162 ExecStart=/a/exe/keyscript-off
163
164 [Install]
165 WantedBy=multi-user.target
166 EOF
167 sudo systemctl daemon-reload # needed if the file was already there
168 sudo systemctl enable keyscriptoff.service
169 sudo systemctl start keyscriptoff.service
170
171 pi rsync zstd
172
173 ## /usr/share/doc/dropbear-initramfs/README.initramfs.gz
174 ## claims we need to do this. but it works fine without it.
175 # tmp=$(mktemp)
176 # while read -r m _; do /sbin/modinfo -F filename "$m"; done </proc/modules | \
177 # sed -nr "s@^/lib/modules/$(uname -r)/kernel/drivers/net(/.*)?/([^/]+)\.ko\$@\2@p" \
178 # | sudo dd of=$tmp
179 # if ! diff -q /etc/initramfs-tools/modules $tmp &>/dev/null; then
180 # sudo dd if=$tmp of=/etc/initramfs-tools/modules
181 # sudo /usr/sbin/update-initramfs -u -k all
182 # fi
183 #
184 ## if we were creating an intall for a different machine needing different modules, we could include them all like this:
185 ## find /lib/modules/*/kernel/drivers/net /lib/modules/*/kernel/net -type f -name '*.ko' -printf "%f\n" | sed 's/.ko$//' | sort -u >/etc/initramfs-tools/modules
186
187 # this is here to cleanup the leftover from the comments above. remove it eventually.
188 if [[ -s /etc/initramfs-tools/modules ]]; then
189 sudo truncate -s0 /etc/initramfs-tools/modules
190 sudo /usr/sbin/update-initramfs -u -k all
191 fi
192
193 # initram auth keys get setup with rootsshsync later on.
194 $script_dir/rootsshsync
195
196 ### To do a remote unlock: ssh and do this once per crypt disk:
197 # echo -n PASS >/lib/cryptsetup/passfifo
198 # or for buster+
199 # cryptroot-unlock
200
201 fi
202 ##### end setup encryption scripts ######
203
204
205 # disabled until its fixed up
206 # install-myqueue
207
208 # todo, it would be nice to cut down on some of the output
209
210
211 #### rerun my fai-time scripts
212 # already ran for pxe installs, but used for vps & updates
213 distro=$(distro-name)
214 case $distro in
215 ubuntu|debian|trisquel)
216 sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/GRUB_PC/11-iank"
217 ;;
218 *)
219 sudo bash -c ". /a/bin/fai/fai-wrapper &&
220 /a/bin/fai/fai/config/distro-install-common/end"
221 ;;
222 esac
223
224 ###### setup hostname
225 if [[ $HOSTNAME != $(cat /etc/hostname) ]]; then
226 echo $HOSTNAME > /etc/hostname
227 hostname -F /etc/hostname
228 fi
229 # office vpn dhcp adds to /etc/resolv.conf search office.fsf.org which
230 # makes that be #1 priority, which makes dnsmasq resolve that for
231 # unqualified hosts first, which means we skip the hosts file. Ya, its
232 # kinda dumb, but it is what it is. There is a dnsmasq config option to
233 # override it too, but this seems simpler.
234 sudo sed -i --follow-symlinks -f - /etc/hosts <<EOF
235 \$a 127.0.1.1 $HOSTNAME.b8.nz $HOSTNAME.office.fsf.org $HOSTNAME
236 /^127\.0\.1\.1/d
237 EOF
238
239 ##### exit first stage if running as root
240 if [[ $EUID == 0 ]]; then
241 if [[ ! -e /home/iank/.ssh/authorized_keys && ! -L /home/iank/.ssh/authorized_keys ]]; then
242 sudo -u iank mkdir -p /home/iank/.ssh
243 chmod 0700 /home/iank/.ssh
244 sudo -u iank ln -sf /p/c/machine_specific/vps/subdir_files/.ssh/authorized_keys /home/iank/.ssh
245 fi
246 echo "$0: running as root. exiting now that users are setup"
247 exit 0
248 fi
249
250
251 #### setup bash for root
252 for x in /a/c/{.bashrc,brc,brc2,.bash_profile,.profile,.inputrc,path_add_function}; do
253 sudo -i <<EOF
254 PATH="/a/exe:$PATH"
255 lnf $x /root
256 EOF
257 done
258
259 ###### link files
260 # convenient to just do all file linking in one place
261 sudo /a/exe/lnf -T /a/bin /b
262 sudo /a/exe/lnf -T /a/f /f
263 sudo /a/exe/lnf -T /var/log/exim4 /el
264 sudo /a/exe/lnf -T /a/f/ans /c
265 sudo /a/exe/lnf -T /nocow/t /t
266 if has_p; then
267 lnf -T /p/News ~/News
268 fi
269 dirs=(/q/root /q/root/.editor-backups /q/root/.undo-tree-history)
270 sudo mkdir -p ${dirs[@]}
271 sudo chmod 600 ${dirs[@]}
272 sudo /a/exe/lnf /q/root/.editor-backups /q/root/.undo-tree-history \
273 /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root
274 /a/bin/ds/install-my-scripts # needed for rootsshsync cronjob
275 sudo /a/exe/lnf /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
276
277
278 ###### do conflink
279 # vps needs bind group before conflink
280 if vps; then
281 pi-nostart bind9
282 fi
283 # this needs to be before installing pacserve so we have gpg conf.
284 conflink
285 rootsshsync
286 if [[ -e /etc/rootsudoenv ]]; then
287 source /etc/rootsudoenv
288 fi
289
290
291
292 ###### bash environment setup
293 set +x
294 err-allow
295 source /etc/profile.d/environment.sh
296 export LC_USEBASHRC=t
297 # shellcheck source=./.bashrc
298 source ~/.bashrc
299 err-catch
300 $interactive || set -x
301
302 ##### use systemd-resolved for glibc resolutions
303
304 pi libnss-resolve
305
306 if [[ ! -L /etc/nsswitch.conf ]]; then
307 sudo mkdir -p /etc/resolved-nsswitch
308 sudo mv /etc/nsswitch.conf /etc/resolved-nsswitch
309 sudo ln -sf /etc/resolved-nsswitch/nsswitch.conf /etc
310 fi
311
312 f=/etc/basic-nsswitch/nsswitch.conf
313 if [[ ! -e $f ]]; then
314 sudo mkdir -p ${f%/*}
315 sudo cp /etc/nsswitch.conf $f
316 sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files dns myhostname/' $f
317 fi
318 case $HOSTNAME in
319 bk)
320 sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files dns myhostname/' /etc/nsswitch.conf
321 soff systemd-resolved
322 ln -sf 127.0.0.1-resolv/stub-resolv.conf /etc/resolv.conf
323 sgo bind9
324 # cautious measure to make sure bind is up
325 sleep 1
326 ;;
327 *)
328 # default is
329 # files mdns4_minimal [NOTFOUND=return] dns myhostname
330 # mdns4 is needed for my printer and for bbb webrtc, not sure exactly why.
331 # https://www.freedesktop.org/software/systemd/man/nss-resolve.html#
332 # seems more important than some potential use case.
333 # Interestingly, t9/t10 man page says use files before resolve, debian 10 says the opposite.
334 # removing files makes hostname -f not actually give the fully qualified domain name.
335 sudo sed -i --follow-symlinks 's/^ *hosts:.*/hosts: files resolve [!UNAVAIL=return] mdns4_minimal [NOTFOUND=return] myhostname/' /etc/resolved-nsswitch/nsswitch.conf
336 ;;
337 esac
338
339 f=/etc/apparmor.d/abstractions/nameservice
340 if [[ -e $f ]] && ! grep -q /etc/resolved-nsswitch/nsswitch.conf $f; then
341 sudo sed -i '/\/etc\/nsswitch.conf/a /etc/resolved-nsswitch/nsswitch.conf r,' $f
342 sudo sed -i '/\/etc\/nsswitch.conf/a /etc/basic-nsswitch/nsswitch.conf r,' $f
343 if sytemctl is-enabled apparmor; then
344 m ser reload apparmor
345 fi
346 fi
347
348
349
350 if dpkg -s -- nscd &>/dev/null; then
351 sudo apt-get -y remove --purge --auto-remove nscd
352 sudo systemctl stop nscd ||: # fails if already stopped
353 fi
354
355 # http://strugglers.net/~andy/blog/2020/12/03/starting-services-only-when-the-network-is-ready-on-debiansystemd/
356 if systemctl cat ifupdown-wait-online.service &>/dev/null; then
357 sudo systemctl enable ifupdown-wait-online.service
358 fi
359
360 if bitfolk; then
361 # remove line like this: 85.119.82.128 je.iankelling.org je
362 # it messes with hostname -f.
363 sudo sed -ri "/^127\./n;/[[:space:]]$HOSTNAME\$/d" /etc/hosts
364 fi
365
366 # firefox exists but is 2 versions outdated
367 if isdeb && [[ $(debian-codename) == nabia ]]; then
368 sudo dd of=/etc/apt/preferences.d/nabia-focal-missing <<'EOF'
369 Package: unrar-free firefox libfdk-aac1 ansible
370 Pin: release n=focal,o=Ubuntu
371 Pin-Priority: 500
372 EOF
373
374 # it has a dependency python-paramiko that should be
375 # python3-paramiko. the backport version is pretty close to the normal
376 # version, so i just set the pin priority low for the backport and it
377 # doesnt bother me
378 sudo dd of=/etc/apt/preferences.d/nabia-backport <<'EOF'
379 Package: ansible
380 Pin: release a=nabia-backports
381 Pin-Priority: -100
382 EOF
383
384
385 fi
386
387
388 # to test when these become available in trisquel, copy the package list, remove the * chars, repaplace PACKAGES below
389 # for x in PACKAGES; do hr; e $x; if [[ $x == *- ]]; then s="^$x"; dpkg -l "$x*" | sed '0,/^+++/d'; else s="^$x\$"; fi; aptitude search "~O Trisquel ~n $s"; done
390
391
392 #### setup firefox backport
393 ## ian: disabled. backports are not being published atm due to rust packaging issue
394 # if isdeb; then
395 # codename=$(debian-codename)
396 # if isdebian-stable && has_x; then
397 # s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
398 # deb http://mozilla.debian.net/ $codename-backports firefox-release
399 # deb-src http://mozilla.debian.net/ $codename-backports firefox-release
400 # EOF
401 # p update
402 # # take care of mozilla signing errors in previous command
403 # pi pkg-mozilla-archive-keyring
404 # fi
405 # p update
406 # fi
407
408
409 ###### arch aur wrapper setup
410 if isarch; then
411 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
412 sudo pacman -S --noconfirm --needed base-devel jq
413 # pacaur seems to be the best, although it + cower has a few minor bugs,
414 # its design goals seem good, so, going for it.
415
416 aurpi() {
417 for p in "$@"; do
418 tempdir=$(mktemp -d)
419 pushd $tempdir
420 aurex "$p"
421 makepkg -sri --skippgpcheck --noconfirm
422 popd
423 rm -rf $tempdir
424 done
425 }
426 aurpi cower pacaur
427
428 pi pacserve
429
430 x=$(mktemp); /usr/bin/pacman.conf-insert_pacserve >$x
431 sudo dd of=/etc/pacman.conf if=$x; rm $x
432 sudo systemctl enable pacserve.service
433 sudo systemctl start pacserve.service
434
435 fi
436
437 #### update all packages
438 pup
439
440
441 ###### p1 packages install ######
442 pi ${p1[@]}
443
444
445 ######## fix evbug bug ######
446 case $(debian-codename-compat) in
447 xenial|bionic|focal)
448 # noticed in flidas. dunno if it affects any others
449 #https://bugs.launchpad.net/ubuntu/+source/module-init-tools/+bug/240553
450 #https://wiki.debian.org/KernelModuleBlacklisting
451 #common advice when searching is to use /etc/modprobe.d/blacklist.conf,
452 #but that file won't work and will get automatically reverted
453 sudo rmmod evbug ||: # might not be loaded yet
454 file=/etc/modprobe.d/evbug.conf
455 line="blacklist evbug"
456 if [[ $(cat $file) != "$line" ]]; then
457 sudo dd of=$file 2>/dev/null <<<"$line"
458 sudo depmod -a
459 sudo update-initramfs -u
460 fi
461 ;;
462 esac
463
464
465
466 #### arch specific early packages
467 case $(distro-name) in
468 arch)
469 # pkgfile is like apt-cache
470 pi pkgfile
471 sudo pkgfile --update
472 ;;
473 esac
474
475 #### enable trim
476 # enable trim for volume delete, other rare commands
477 sudo $sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
478 if encrypted; then
479 # flidas or so, these units arent built-in
480 if isdeb && ! systemctl list-unit-files | grep ^fstrim.timer &>/dev/null ; then
481 sudo cp /usr/share/doc/util-linux/examples/fstrim.{service,timer} /etc/systemd/system
482 fi
483 # does weekly trim
484 sudo systemctl enable fstrim.timer
485 fi
486
487 ##### make extra dirs
488 dirs=()
489 for dir in /mnt/{1,2,3,4,5,6,7,8,9} /nocow/t; do
490 [[ -e $dir ]] && continue
491 dirs+=($dir)
492 done
493 if (( ${#dirs[@]} )); then
494 # mkdir -p on a mounted directory will fail. so will chown if its an ro mount
495 sudo mkdir -p "${dirs[@]}"
496 sudo chown $USER:$USER "${dirs[@]}"
497 fi
498
499
500 # disabled temporarily
501 ###### setup /i
502 # if home_network; then
503 # tu /etc/fstab <<'EOF'
504 # /i/w /w none bind,noauto 0 0
505 # /i/k /k none bind,noauto 0 0
506 # EOF
507 # if ! mountpoint /kr; then
508 # sudo mkdir -p /kr
509 # sudo chown $USER:user2 /kr
510 # fi
511 # if [[ $HOSTNAME == frodo ]]; then
512 # tu /etc/fstab <<'EOF'
513 # /k /kr none bind,noauto 0 0
514 # EOF
515 # else
516 # tu /etc/fstab <<'EOF'
517 # frodo:/k /kr nfs noauto 0 0
518 # EOF
519 # fi
520 # sudo mkdir -p /i/{w,k}
521 # for dir in /{i,w,k}; do
522 # if mountpoint $dir; then continue; fi # already mounted
523 # sudo mkdir -p $dir
524 # sudo chown $USER:$USER $dir
525 # done
526 # # debian auto mounting of multi-disk encrypted btrfs is busted. It is
527 # # in jessie, and in stretch as of 11/26/2016 I have 4 disks in cryptab,
528 # # based on 3 of those, it creates .device units for /dev/mapper/dev...
529 # # then waits endlessly for them on bootup, after the /dev/mapper disks
530 # # have already been created and exist. todo: create a simple repro
531 # # for this in a vm and report it upstream.
532 # pi nfs-common
533 # sudo dd of=/root/imount <<'EOF'
534 # #!/bin/bash
535 # [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
536 # set -eE -o pipefail
537 # trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
538 # for dir in /i /k /kr /w; do
539 # if ! mountpoint $dir &>/dev/null && \
540 # awk '{print $2}' /etc/fstab | grep -xF $dir &>/dev/null; then
541 # if awk '{print $3}' /etc/fstab | grep -xF nfs &>/dev/null; then
542 # mount $dir || echo "warning: failed to mount nfs on $dir"
543 # else
544 # mount $dir
545 # fi
546 # fi
547 # done
548 # EOF
549 # sudo chmod +x /root/imount
550 # sudo dd of=/etc/systemd/system/imount.service <<EOF
551 # [Unit]
552 # Description=Mount /i and related mountpoints
553 # Before=syncthing@$USER.service
554
555 # [Service]
556 # Type=oneshot
557 # ExecStart=/root/imount
558
559 # [Install]
560 # RequiredBy=syncthing@$USER.service
561 # # note /kr needs networking, this target is the simplest way to
562 # # time it when the network should be up, but not do something
563 # # dumb like delay startup until the network is up. It happens
564 # # at some time after network.target
565 # WantedBy=multi-user.target
566 # EOF
567 # sudo systemctl daemon-reload # needed if the file was already there
568 # sudo systemctl enable imount.service
569 # sudo systemctl start imount.service
570 # fi
571 ###### end setup /i
572
573 ##### setup /nocow.
574 # a nocow dir that is common to multiple distros installed on the same system
575 dir=/nocow
576 if has_btrfs; then
577 if ! mountpoint $dir; then
578 subvol=/mnt/root/nocow
579 if [[ ! -e $subvol ]]; then
580 sudo btrfs subvolume create $subvol
581 sudo chown root:1000 $subvol
582 sudo chattr +C $subvol
583 fi
584
585 first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab)
586 tu /etc/fstab <<EOF
587 $first_root_crypt /nocow btrfs noatime,subvol=nocow$( ((`nproc` > 2)) && echo ,compress=zstd ) 0 0
588 EOF
589 sudo mkdir -p $dir
590 sudo chown $USER:$USER $dir
591 sudo mount $dir
592 fi
593 else
594 sudo mkdir -p $dir
595 fi
596
597 case $HOSTNAME in
598 kd)
599 tu /etc/fstab <<'EOF'
600 /dev/mapper/crypt_dev_ata-Samsung_SSD_870_QVO_8TB_S5VUNG0N900656V-part7 /d btrfs nofail,x-systemd.device-timeout=30s,x-systemd.mount-timeout=30s,noatime,compress=zstd,subvol=d 0 0
601 EOF
602 if ! mountpoint /d &>/dev/null; then
603 sudo mkdir /d
604 if [[ -d /mnt/r7/d ]]; then
605 sudo mount /d
606 fi
607 fi
608 ;;
609 esac
610
611 if bitfolk; then
612 sudo systemctl disable systemd-networkd
613 fi
614
615 ##### setup email
616 primary-setup
617
618 #### ubuntu nicety
619 if isubuntu; then
620 # disable crash report annoying dialogs.
621 sudo dd of=/etc/default/apport <<<'enabled=0'
622 fi
623
624 ##### install laptop hardware packages
625 if tp || x2 || x3 || bo || sy; then
626 case $distro in
627 debian)
628 pi task-laptop
629 ;;
630 ubuntu|trisquel)
631 # the exact packages that task-laptop would install, since ubuntu
632 # doesn\'t have this virtual in practice package.
633 pi avahi-autoipd bluetooth powertop iw wireless-tools wpasupplicant
634 ;;
635 # todo: other distros unknown
636 esac
637 fi
638
639 if has_monitor; then
640
641 # sway not packaged for t9, not bothering to build it yet since
642 # i3 doesnt seem to tear and stutter on video anymore.
643 if [[ $codename == buster ]]; then
644 pi sway xwayland
645 fi
646
647
648 ###### install X
649 # no recommends due to this bug: https://trisquel.info/en/issues/26525
650 pi --no-install-recommends i3
651
652 ##### install xinput
653 case $(distro-name) in
654 trisquel|ubuntu|debian)
655 pi xinput
656 ;;
657 esac
658
659 # recommends gets us geoclue (for darkening automatically at night i assume),
660 # which recommends modemmanager, which is annoying to fix for the model01 keyboard.
661 # commented because I dont use it much, and in nabia its named changed to redshift-gtk
662 #pi --no-install-recommends gtk-redshift
663
664 ##### setup X autostart
665 # install for multiple display managers in case we use one
666 dir=/etc/X11/xinit/xinitrc.d/
667 sudo mkdir -p $dir
668 sudo cp /a/bin/distro-setup/desktop-20-autostart.sh $dir
669 s teeu /etc/systemd/logind.conf <<'EOF'
670 HandleLidSwitch=
671 EOF
672
673 # this works on
674 dir=/etc/gdm3
675 sudo mkdir -p $dir/PostLogin
676 sudo cp /a/bin/distro-setup/desktop-20-autostart.sh $dir/PostLogin/Default
677 sudo mkdir -p /etc/lightdm/lightdm.conf.d
678 # etiona lightdm.log:
679 # [SeatDefaults] is now called [Seat:*], please update this configuration
680 sudo dd of=/etc/lightdm/lightdm.conf.d/12-iank.conf <<'EOF'
681 [Seat:*]
682 display-setup-script=/a/bin/ds/lightdm-start
683 session-setup-script=/a/bin/distro-setup/desktop-20-autostart.sh
684 EOF
685
686
687 # originally used xkbcomp, documented in input-setup.sh, this doesnt
688 # work under wayland, but its still useful for creating the config,
689 # then modifying the system files.
690 sudo sed -i.orig '/key *<KPMU> *{/,/}/s/KP_Multiply/underscore/g' /usr/share/X11/xkb/symbols/keypad
691
692 ##### basic graphical packages
693 pi konsole suckless-tools ssh-askpass
694 fi
695
696
697
698 ##### install emacs
699 if $emacs; then
700 if isarch; then
701 # emacs git build was broken last time i checked,
702 x=$(mktemp -d)
703 pushd $x
704 aurex emacs-git
705 makepkg -si --noconfirm
706 popd
707 rm -rf $x
708 pi hunspell hunspell-en
709 else
710 if $recompile; then
711 /a/bin/buildscripts/emacs
712 else
713 /a/bin/buildscripts/emacs --no-r
714 fi
715 fi
716 # the first pup command can kill off our /etc/ mod, so rerun this
717 /a/exe/ssh-emacs-setup
718 fi
719
720 if [[ $HOSTNAME == kd ]] && ! mountpoint /d &>/dev/null; then
721 cat <<'EOFOUTER'
722 # if this is a fresh reinstall, need to run something like this
723 # to restore data:
724 mkdir /mnt/r7/btrbk
725 btrbk archive /mnt/rust1/btrbk /mnt/r7/btrbk
726 btrfs sub snap /mnt/r7/btrbk/LATEST /mnt/r7/d
727 mount /d
728 EOFOUTER
729 fi
730
731
732 echo 0 >~/.local/distro-begin
733 echo "$0: $(date): ending now"
734 echo "exiting with status 0"
735 exit 0