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