various improvements and fixes
[distro-setup] / distro-begin
1 #!/bin/bash -l
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
17
18
19 # for bootstrapping a new machine
20
21 # in case we need it,
22 # to make ssh interactive shell run better, we run this first.
23 sudo bash -c 'source /a/c/.bashrc && source /a/exe/ssh-emacs-setup'
24
25
26 # usage: $0 [-r] HOSTNAME
27
28 # tips:
29 # run any sudo command first so your pass is cached
30 # set the scrollback to unlimited in case something goes wrong
31
32 if [[ $EUID == 0 ]]; then
33 if getent passwd iank || getent passwd ian ; then
34 echo "$0: error: running as root. unprivileged user exists. use it."
35 exit 1
36 else
37 echo "$0: warning: running as root. I will setup users then exit"
38 fi
39 fi
40
41 interactive=true # set this to false to force set -x
42 [[ $- == *i* ]] || interactive=false
43
44 if ! $interactive; then
45 set -x
46 set -e -o pipefail
47 fi
48 set -E
49 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
50
51 exec &> >(sudo tee -a /var/log/distro-begin)
52 echo "$0: $(date): starting now)"
53
54 # headless=false # unused atm
55 recompile=false
56 # for copying to a new data fs
57 bootstrapfs=false # old flag, needs new look before using.
58 while [[ $1 == -* ]]; do
59 case $1 in
60 -r) recompile=true; shift ;;
61 esac
62 done
63
64 if [[ $1 ]]; then
65 export HOSTNAME=$1
66 fi
67
68 for f in iank-dev htpc treetowl x2 frodo tp li lj demohost kw fz; do
69 eval "$f() { [[ $HOSTNAME == $f ]]; }"
70 done
71 has_p() { ! linode; } # when tp is tracis, then not tp either
72 has_x() { ! linode; }
73 linode() { lj || li; }
74 has_btrfs() { ! linode; }
75 home_network() { ! linode; }
76 encrypted() { has_p; }
77
78 shopt -s extglob
79 export GLOBIGNORE=*/.:*/..
80 umask 0002
81
82
83 ####### end command line parsing
84
85 PATH="/a/exe:$PATH"
86 sed="sed --follow-symlinks"
87
88 ##### begin setup encryption scripts ######
89 if encrypted; then
90 # I tried making a service which was dependent on reboot.target,
91 # but it happened too late in the shutdown process.
92 sudo dd of=/etc/systemd/system/keyscripton.service <<'EOF'
93 [Unit]
94 Description=Turn on automatic decryption of drives on boot
95 # tried using graphical.target, but it made my display manager restart before rebooting.
96 # generally, I don't think targets order shutdown like they do startup.
97 # So, I did systemd-analyze plot > something.svg, and picked a reliably started
98 # service that happens late in the game.
99 After=ntp.service
100 DefaultDependencies=no
101 # not sure if needed, makes sure we shut down before reboot.target
102 Conflicts=reboot.target
103
104 [Service]
105 Type=oneshot
106 RemainAfterExit=yes
107 ExecStart=/bin/true
108 ExecStop=/a/exe/keyscript-on
109
110 [Install]
111 WantedBy=keyscriptoff.service
112 EOF
113 sudo systemctl daemon-reload # needed if the file was already there
114 sudo systemctl stop keyscripton.service
115 # sudo systemctl start keyscripton.service
116 sudo systemctl enable keyscripton.service
117
118 sudo dd of=/etc/systemd/system/keyscriptoff.service <<'EOF'
119 [Unit]
120 Description=Turn off automatic decryption of drives on boot
121
122 [Service]
123 Type=oneshot
124 ExecStart=/a/exe/keyscript-off
125
126 [Install]
127 WantedBy=multi-user.target
128 EOF
129 sudo systemctl daemon-reload # needed if the file was already there
130 sudo systemctl enable keyscriptoff.service
131 sudo systemctl start keyscriptoff.service
132 fi
133 ##### end setup encryption scripts ######
134
135
136 install-myqueue
137
138 # this script has been designed to be idempotent
139 # todo, it would be nice to cut down on some of the output
140
141
142 for x in /a/bin/errhandle/*-function; do
143 source $x
144 done
145
146
147 set +e
148 $interactive || errcatch
149 set +x
150 source /a/bin/distro-functions/src/identify-distros
151 $interactive || set -x
152
153 if isfedora; then
154 # comment out line disallowing calling sudo in scripts
155 sudo $sed -i 's/^Defaults *requiretty/#\0 # ian commented/' /etc/sudoers
156 # turn on magic sysrq commands for this boot cycle
157 echo 1 > sudo dd of=/proc/sys/kernel/sysrq
158 echo "kernel.sysrq = 1" > /etc/sysctl.d/90-sysrq.conf
159 # selinux is not user friendly. Like, you enable samba, but you haven't run the magic selinux commands so it doesn't work
160 # and you have no idea why.
161 sudo $sed -i 's/^\(SELINUX=\).*/\1disabled/' /etc/selinux/config
162 selinuxenabled && sudo setenforce 0
163 fi
164
165
166 # already ran for pxe installs, but used for vps & updates
167 distro=$(distro-name)
168 case $distro in
169 ubuntu|debian|trisquel)
170 sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/GRUB_PC/11-iank"
171 ;;
172 *)
173 sudo bash -c ". /a/bin/fai/fai-wrapper &&
174 /a/bin/fai/fai/config/distro-install-common/end"
175 ;;
176 esac
177
178 sudo $sed -i '/^127\.0\.1\.1/d' /etc/hosts
179 echo "127.0.1.1 $HOSTNAME.b8.nz $HOSTNAME" | sudo tee -a /etc/hosts
180
181
182 if [[ $EUID == 0 ]]; then
183 echo "$0: running as root. exiting now that users are setup"
184 exit 0
185 fi
186
187
188 #### begin link bashrc for root ######
189 for x in /a/c/{.bashrc,brc,.bash_profile,.profile,.inputrc,path_add_function}; do
190 sudo -i <<EOF
191 PATH="/a/exe:$PATH"
192 lnf $x /root
193 EOF
194 done
195 #### end link bashrc repo for root ######
196
197 # li needs the bind group before conflink
198 if [[ $HOSTNAME == li ]]; then
199 getent group bind &>/dev/null || sudo groupadd -r bind
200 fi
201 # this needs to be before installing pacserve so we have gpg conf.
202 conflink
203
204 set +x
205 errallow
206 source /etc/profile.d/environment.sh
207 source ~/.bashrc
208 $interactive || errcatch
209 $interactive || set -x
210
211
212 # passwordless sudo
213 tu /etc/sudoers <<EOF
214 $USER ALL=(ALL) NOPASSWD: ALL
215 Defaults env_keep += SUDOD
216 # makes ubuntu be like debian
217 # https://unix.stackexchange.com/a/91572
218 Defaults always_set_home
219 EOF
220
221
222 # enable magic sysrq keys. debian docs say it is already enabled by default
223 isfedora && tu /etc/sysctl.conf 'kernel.sysrq = 1'
224
225
226 if isdeb; then
227 codename=$(debian-codename)
228 ## ian: disabled. backports are not being published atm due to rust packaging issue
229 # if isdebian-stable && has_x; then
230 # s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
231 # deb http://mozilla.debian.net/ $codename-backports firefox-release
232 # deb-src http://mozilla.debian.net/ $codename-backports firefox-release
233 # EOF
234 # p update
235 # # take care of mozilla signing errors in previous command
236 # pi pkg-mozilla-archive-keyring
237 # fi
238 p update
239
240 fi
241
242
243 ###### begin arch aur wrapper ########
244 if isarch; then
245 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
246 sudo pacman -S --noconfirm --needed base-devel jq
247 # pacaur seems to be the best, although it + cower has a few minor bugs,
248 # its design goals seem good, so, going for it.
249
250 aurpi() {
251 for p in "$@"; do
252 tempdir=$(mktemp -d)
253 pushd $tempdir
254 aurex "$p"
255 makepkg -sri --skippgpcheck --noconfirm
256 popd
257 rm -rf $tempdir
258 done
259 }
260 aurpi cower pacaur
261
262 pi pacserve
263
264 x=$(mktemp); /usr/bin/pacman.conf-insert_pacserve >$x
265 sudo dd of=/etc/pacman.conf if=$x; rm $x
266 sudo systemctl enable pacserve.service
267 sudo systemctl start pacserve.service
268
269 fi
270 ###### end arch aur wrapper ########
271
272 pup
273
274
275 ###### begin trash cli install ######
276 if isarch; then
277 # strange error if just installing trash-cli: "pyalpm requires python",
278 # so I see that it requires python2, and installing that manually fixes it.
279 # I didn\'t see this on earlier installation, main thing which changed was
280 # pacserve, so not sure if it\'s related.
281 pi python2
282 fi
283 pi trash-cli
284 ###### end trash cli install ######
285
286
287 ######## begin fix evbug bug ######
288 case $distro in
289 trisquel|ubuntu)
290 # noticed in flidas.
291 #https://bugs.launchpad.net/ubuntu/+source/module-init-tools/+bug/240553
292 sudo rmmod evbug ||: # might not be loaded yet
293 file=/etc/modprobe.d/blacklist.conf
294 line="blacklist evbug"
295 if ! grep -xFq "$line" $file; then
296 sudo tee -a $file &>/dev/null <<<"$line"
297 sudo depmod -a
298 sudo update-initramfs -u
299 fi
300 ;;
301 esac
302 ######## end fix evbug bug ######
303
304
305
306 ###### begin link files ###########
307 # convenient to just do all file linking in one place
308
309
310 s lnf -T /a/bin /b
311 s lnf -T /nocow/t /t
312
313 if has_p; then
314 lnf -T /p/News ~/News
315 fi
316
317 s lnf /q/root/.editor-backups /q/root/.undo-tree-history \
318 /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root
319
320 rootsshsync
321
322 s lnf /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
323
324 # machine is going away
325 # if [[ $HOSTNAME == htpc ]]; then
326 # lnf -T /i/Videos ~/Downloads
327 # fi
328
329 if has_p; then
330 # for dovecot
331 lnf -T /i/k/mboxes ~/mail
332 fi
333
334 ###### end link files ###########
335
336
337 ##### basic needed packages
338
339 ### begin setup for keyboard and redshift ###
340 case $(distro-name) in
341
342 trisquel|ubuntu|debian)
343 if has_x; then
344 if isdebian-testing; then
345 pi xmacro/unstable # has no unstable deps
346 else
347 pi xmacro
348 fi
349 pi xinput
350 # recommends gets us geoclue (for darkening automatically at night i assume),
351 # which recommends modemmanager, which is annoying to fix for the model01 keyboard.
352 pi --no-install-recommends gtk-redshift
353 fi
354 ;;&
355 fedora)
356 p -y groupinstall development-tools c-development books admin-tools
357 pi wget man-pages
358 if has_x; then
359 pi redshift-gtk
360 # debian has this package patched to work, upstream is dead
361 # tried using alien, pi alien, alien -r *.deb, rpm -Uhv *.rpm, got this error, so fuck it
362 # file /usr/bin from install of xmacro-0.3pre_20000911-7.x86_64 conflicts with file from package filesystem-3.2-19.fc20.x86_64
363 # http://packages.debian.org/source/sid/xmacro
364 pi patch libXtst-devel
365 cd $(mktemp -d)
366 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911.orig.tar.gz
367 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911-6.diff.gz
368 ex *.gz
369 patch -p0 < xmacro_0.3pre-20000911-6.diff
370 cd xmacro-0.3pre-20000911.orig
371 make
372 sleep 1 # not sure why the following command couldn\'t find, so trying this
373 # no make install target
374 s cp -f xmacroplay xmacrorec xmacrorec2 /usr/local/bin
375 fi
376 ;;&
377 arch)
378 # like apt-cache
379 pi pkgfile
380 s pkgfile --update
381 if has_x; then
382 # libxtst is missing dep https://aur.archlinux.org/packages/xmacro/#news
383 pi xorg-server redshift xorg-xinput libxtst xmacro
384
385 # background:
386 # https://aur.archlinux.org/packages/xkbset/#comment-545419
387 cert=$(mktemp)
388 cat >$cert <<'EOF'
389 -----BEGIN CERTIFICATE-----
390 MIIJADCCB+igAwIBAgIRAIVAhZ0TMbQ5jTm0koI8X6YwDQYJKoZIhvcNAQELBQAw
391 djELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1JMRIwEAYDVQQHEwlBbm4gQXJib3Ix
392 EjAQBgNVBAoTCUludGVybmV0MjERMA8GA1UECxMISW5Db21tb24xHzAdBgNVBAMT
393 FkluQ29tbW9uIFJTQSBTZXJ2ZXIgQ0EwHhcNMTUxMjA4MDAwMDAwWhcNMTgxMjA3
394 MjM1OTU5WjCBsTELMAkGA1UEBhMCVVMxDjAMBgNVBBETBTY1MjExMREwDwYDVQQI
395 EwhNaXNzb3VyaTERMA8GA1UEBxMIQ29sdW1iaWExHzAdBgNVBAkTFjExMDAgQ2Fy
396 cmllIEZyYW5ja2UgRHIxHzAdBgNVBAoTFlVuaXZlcnNpdHkgb2YgTWlzc291cmkx
397 CzAJBgNVBAsTAk1VMR0wGwYDVQQDExRmYWN1bHR5Lm1pc3NvdXJpLmVkdTCCASIw
398 DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN8Kap8hASpxQeqjHibGsCR1PBkh
399 nW9p5FkuhGpMW/3ko8QfxH0W1Hq2y2DTFUmq17kH3GfT3h9a7Hc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Fkc2No
432 b29sLm1pc3NvdXJpLmVkdTANBgkqhkiG9w0BAQsFAAOCAQEAQutYVAqG7MpmG2Nu
433 Z/UypjYkN4JvwRbKBpTrce2IT/Sy29x6chBbyD+0WE6QORBtaUHuzE1KoXqpnF4M
434 QrkKw0oBAC6x9dISoomq0DkIndtoBYYLaxSoII6F4OGWgF7pQ/7MiCBYzsKQpn9t
435 aofMcTfvnCjq+MCIaeYnUKBVww0lOJlUxZGKxFJvRpf78HfbBauojjRO2zXLZD/u
436 KMspbTfDaj5etIgWGShY2eml3N/SjAENmZYkcgDBYFyi8CckcEBAVzpH1+D+7Anz
437 txHSYDNHAYLv83MwbegApa1FwPqlG/4SdEU8G6e6Xf5GLC/6GPGVTUpr7o348OOO
438 lzGQzw==
439 -----END CERTIFICATE-----
440 -----BEGIN CERTIFICATE-----
441 MIIF+TCCA+GgAwIBAgIQRyDQ+oVGGn4XoWQCkYRjdDANBgkqhkiG9w0BAQwFADCB
442 iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
443 cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
444 BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQx
445 MDA2MDAwMDAwWhcNMjQxMDA1MjM1OTU5WjB2MQswCQYDVQQGEwJVUzELMAkGA1UE
446 CBMCTUkxEjAQBgNVBAcTCUFubiBBcmJvcjESMBAGA1UEChMJSW50ZXJuZXQyMREw
447 DwYDVQQLEwhJbkNvbW1vbjEfMB0GA1UEAxMWSW5Db21tb24gUlNBIFNlcnZlciBD
448 QTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJwb8bsvf2MYFVFRVA+e
449 xU5NEFj6MJsXKZDmMwysE1N8VJG06thum4ltuzM+j9INpun5uukNDBqeso7JcC7v
450 HgV9lestjaKpTbOc5/MZ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eambx9spnFixdjQg3IM8WcR
500 iQycE0xyNN+81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYze
501 Sf7dNXGiFSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZ
502 XHlKYC6SQK5MNyosycdiyA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/
503 qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
504 VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
505 L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
506 jjxDah2nGN59PRbxYvnKkKj9
507 -----END CERTIFICATE-----
508 EOF
509 cat /etc/ssl/certs/ca-certificates.crt >> $cert
510 CURL_CA_BUNDLE=$cert pi xkbset
511 fi
512
513 ;;&
514 ubuntu|trisquel|debian|fedora)
515 if has_x; then
516 if isdebian-testing; then
517 # xkbset was in testing for quite a while, dunno
518 # why it\'s not anymore. Sometime I should check and
519 # see if it\'s back in testing, but the unstable package
520 # doesn\'t upgrade anything form testing, and it\'s tiny
521 # so I\'m not bothering to automate it.
522 pi xkbset/unstable
523 else
524 pi xkbset
525 fi
526 fi
527 ;;&
528 esac
529 if has_x; then
530 pi xbindkeys
531 fi
532 ### end setup for keyboard and redshift ###
533
534
535 pi cryptsetup lvm2
536 # enables trim for volume delete, other rare commands.
537 sudo $sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
538
539 if encrypted; then
540 if isdeb; then
541 sudo cp /usr/share/doc/util-linux/examples/fstrim.{service,timer} /etc/systemd/system
542 fi
543 # does weekly trim
544 sudo systemctl enable fstrim.timer
545 fi
546
547 dirs=(/mnt/{1,2,3,4,5,6,7,8,9} /nocow/t)
548 s mkdir -p "${dirs[@]}"
549 s chown $USER:$USER "${dirs[@]}"
550
551
552 tu /etc/fstab <<'EOF'
553 /i/w /w none bind,noauto 0 0
554 /i/k /k none bind,noauto 0 0
555 EOF
556
557
558 if ! mountpoint /kr; then
559 s mkdir -p /kr
560 s chown $USER:traci /kr
561 fi
562
563 if home_network; then
564 if [[ $HOSTNAME == frodo ]]; then
565 tu /etc/fstab <<'EOF'
566 /k /kr none bind,noauto 0 0
567 EOF
568 else
569 tu /etc/fstab <<'EOF'
570 frodo:/k /kr nfs noauto 0 0
571 EOF
572 fi
573 fi
574
575 s mkdir -p /q /i/{w,k}
576 for dir in /{i,w,k}; do
577 if mountpoint $dir; then continue; fi # already mounted
578 s mkdir -p $dir
579 s chown $USER:$USER $dir
580 done
581
582 # not needed for all hosts, but rather just keep it uniform
583 s mkdir -p /mnt/iroot
584
585 # debian auto mounting of multi-disk encrypted btrfs is busted. It is
586 # in jessie, and in stretch as of 11/26/2016 I have 4 disks in cryptab,
587 # based on 3 of those, it creates .device units for /dev/mapper/dev...
588 # then waits endlessly for them on bootup, after the /dev/mapper disks
589 # have already been created and exist. todo: create a simple repro
590 # for this in a vm and report it upstream.
591 if has_btrfs || home_network; then
592 pi nfs-common
593 s dd of=/root/imount <<'EOF'
594 #!/bin/bash
595 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
596 set -eE -o pipefail
597 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
598 for dir in /i /mnt/iroot /k /kr /w; do
599 if ! mountpoint $dir &>/dev/null && \
600 awk '{print $2}' /etc/fstab | grep -xF $dir &>/dev/null; then
601 if awk '{print $3}' /etc/fstab | grep -xF nfs &>/dev/null; then
602 mount $dir || echo "warning: failed to mount nfs on $dir"
603 else
604 mount $dir
605 fi
606 fi
607 done
608 EOF
609 s chmod +x /root/imount
610
611 s dd of=/etc/systemd/system/imount.service <<EOF
612 [Unit]
613 Description=Mount /i and related mountpoints
614 Before=syncthing@$USER.service
615
616 [Service]
617 Type=oneshot
618 ExecStart=/root/imount
619
620 [Install]
621 RequiredBy=syncthing@$USER.service
622 # note /kr needs networking, this target is the simplest way to
623 # time it when the network should be up, but not do something
624 # dumb like delay startup until the network is up. It happens
625 # at some time after network.target
626 WantedBy=multi-user.target
627 EOF
628 sudo systemctl daemon-reload # needed if the file was already there
629 sudo systemctl enable imount.service
630 sudo systemctl start imount.service
631 fi
632
633 dir=/nocow
634 if has_btrfs; then
635 if ! mountpoint $dir; then
636 subvol=/mnt/root/nocow
637 if [[ ! -e $subvol ]]; then
638 s btrfs subvolume create $subvol
639 s chown root:1000 $subvol
640 s chattr +C $subvol
641 fi
642
643 first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab)
644 tu /etc/fstab <<EOF
645 $first_root_crypt /nocow btrfs noatime,subvol=nocow 0 0
646 EOF
647 s mkdir -p $dir
648 s chown $USER:$USER $dir
649 s mount $dir
650 fi
651 else
652 sudo mkdir -p $dir
653 fi
654
655 # ssh and probably some other things care about parent directory
656 # ownership, and ssh doesn\'t allow any group writable parent
657 # directories, so we are forced to use a directory structure similar
658 # to home directories
659 s chown root:$USER /q
660 s chmod 755 /q
661
662
663 # it comes with stretch and arch, but not jessie.
664 # propogate /etc/udev/hwdb.d
665 if which systemd-hwdb; then
666 s systemd-hwdb update
667 ser restart systemd-udev-trigger
668 fi
669
670
671 if isdeb; then
672 # I\'ve had problems with postfix on debian:
673 # on stretch, a startup ordering issue caused all mail to fail.
674 # postfix changed defaults to only use ipv6 dns, causing all my mail to fail.
675 # exim4 is default on debian, so I assume it would
676 # be packaged better to avoid these types of things.
677 # I haven\'t gotten around to getting a non-debian exim
678 # setup.
679 mail-setup exim4
680 else
681 mail-setup postfix
682 fi
683
684 if isubuntu; then
685 # disable crash report annoying dialogs.
686 s dd of=/etc/default/apport <<<'enabled=0'
687 fi
688
689 # fai sets this an old way that doesn't work for stretch.
690 # no harm in setting it universally here.
691 # using debconf-set-selection, the area gets reset to ETC
692 # on my linode test machine after doing a dpkg-reconfigure, or a reinstall,
693 # so we are using expect :(
694 # I got a random error when running this, so I added a sleep
695 # rather than trying to write a whole detect and wait loop.
696 # E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
697 # E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
698 sleep 1
699 # todo: this is not idempotent, it fails when running twice, due to prepopulated values.
700 # check into unsetting them using debconf-set-selection.
701 s apt-get -y install --no-install-recommends expect
702 s expect <<EOF ||:
703 set force_conservative 0
704 spawn dpkg-reconfigure tzdata -freadline
705 expect -nocase timeout {exit 1} "Geographic area:"
706 send "\02512\r"
707 expect -nocase timeout {exit 1} "Time zone:"
708 send "\0255\r"
709 expect eof
710 exit
711 EOF
712
713
714 if has_x; then
715 if isarch; then
716 # install so it's build dependencies don't get removed.
717
718 # emacs git build is currently broken
719 if false; then
720 x=$(mktemp -d)
721 pushd $x
722 aurex emacs-git
723 makepkg -si --noconfirm
724 popd
725 rm -rf $x
726 else
727 pi emacs
728 fi
729 pi hunspell hunspell-en
730 else
731 if $recompile; then
732 /a/bin/buildscripts/emacs
733 else
734 /a/bin/buildscripts/emacs --no-r || /a/bin/buildscripts/emacs
735 fi
736 fi
737
738 # todo, figure this out for arch if we ever try out gnome.
739 if ! isarch; then
740 # install for multiple display managers in case we use one
741 if isdeb; then
742 dir=/etc/gdm3
743 elif isfedora; then
744 # fedora didn\'t have the 3.
745 dir=/etc/gdm
746 fi
747 s mkdir -p $dir/PostLogin
748 s command cp /a/bin/distro-setup/desktop-20-autostart.sh $dir/PostLogin/Default
749 s mkdir /etc/lightdm/lightdm.conf.d
750 s dd of=/etc/lightdm/lightdm.conf.d/12-iank.conf <<'EOF'
751 [SeatDefaults]
752 session-setup-script=/a/bin/distro-setup/desktop-20-autostart.sh
753 EOF
754 fi
755
756
757 pi ghc sakura
758 # todo, also note for work comp, scp opt/org-mode bin/build-scripts
759
760 # use the package manger version to install the cabal version
761 pi cabal-install
762 cabal update
763 PATH="$PATH:$HOME/.cabal/bin"
764
765 # todo, on older ubuntu I used cabal xmonad + xfce,
766 # see /a/bin/old-unused/xmonad-cabal.sh
767
768 # trying out the distros versions newer distros
769 pi xmonad
770 if isarch; then
771 # for displaying error messages.
772 # optional dependency in arch, standard elsewhere.
773 pi xorg-xmessage xmonad-contrib xorg-xsetroot xorg-xinit
774
775 # https://wiki.archlinux.org/index.php/Xinitrc
776 for homedir in /home/*; do
777 cp /etc/X11/xinit/xinitrc $homedir/.xinitrc
778 $sed -ri '/^ *twm\b/,$d' $homedir/.xinitrc
779 tee -a $homedir/.xinitrc <<'EOF'
780 /a/bin/desktop-20-autostart.sh
781 xsetroot -cursor_name left_ptr
782 exec xmonad
783 EOF
784 done
785 else
786 pi suckless-tools
787 fi
788 pi dmenu
789
790 if tp || x2; then
791 case $distro in
792 debian)
793 pi task-laptop
794 ;;
795 ubuntu|trisquel)
796 # the exact packages that task-laptop would install, since ubuntu
797 # doesn\'t have this virtual in practice package.
798 pi avahi-autoipd bluetooth powertop iw wireless-tools wpasupplicant
799 ;;
800 # todo: other distros unknown
801 esac
802 fi
803 fi
804
805 # the first pup command can kill off our /etc/ mod, so rerun this
806 /a/exe/ssh-emacs-setup
807 echo "$0: $(date): ending now"
808 exit 0