Merge independent repo conflink into this one
[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/repos/bash/.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 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; do
69 eval "$f() { [[ $HOSTNAME == $f ]]; }"
70 done
71 has_p() { treetowl || x2 || frodo || tp || demohost; }
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 # selinux is not user friendly. Like, you enable samba, but you haven't run the magic selinux commands so it doesn't work
159 # and you have no idea why.
160 sudo $sed -i 's/^\(SELINUX=\).*/\1disabled/' /etc/selinux/config
161 selinuxenabled && sudo setenforce 0
162 fi
163
164
165 # already ran for pxe installs, but used for vps & updates
166 distro=$(distro-name)
167 case $distro in
168 ubuntu|debian)
169 sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/GRUB_PC/11-ian"
170 ;;
171 *)
172 sudo bash -c ". /a/bin/fai/fai-wrapper &&
173 /a/bin/fai/fai/config/distro-install-common/end"
174 ;;
175 esac
176
177 if linode; then
178 sudo $sed -i '/^127\.0\.1\.1/d' /etc/hosts
179 echo "127.0.1.1 $HOSTNAME.lan $HOSTNAME" | sudo tee -a /etc/hosts
180 fi
181
182
183 if [[ $EUID == 0 ]]; then
184 echo "$0: running as root. exiting now that users are setup"
185 exit 0
186 fi
187
188
189 # this needs to be before installing pacserve so we have gpg conf.
190 conflink
191
192 set +x
193 errallow
194 source ~/.bashrc
195 $interactive || errcatch
196 $interactive || set -x
197
198
199 # passwordless sudo
200 tu /etc/sudoers <<'EOF'
201 ian ALL=(ALL) NOPASSWD: ALL
202 Defaults env_keep += SUDOD
203 EOF
204
205
206 # enable magic sysrq keys. debian docs say it is already enabled by default
207 isfedora && tu /etc/sysctl.conf 'kernel.sysrq = 1'
208
209
210 if isdebian; then
211 codename=$(debian-codename)
212 if isdebian-stable && has_x; then
213 s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
214 deb http://mozilla.debian.net/ $codename-backports firefox-release
215 deb-src http://mozilla.debian.net/ $codename-backports firefox-release
216 EOF
217 p update
218 # take care of mozilla signing errors in previous command
219 pi pkg-mozilla-archive-keyring
220 p update
221 else
222 :
223 # this would change stable to testing, but I set that up already.
224 # It\'s just a no-op if its already testing.
225 # sudo sed -ri 's!^( *[^ #]+ +[^ ]+ +)[[:alpha:]]+(.*)!\1testing\2!' /etc/apt/sources.list
226 p update
227 fi
228 fi
229
230 if isarch; then
231 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
232 sudo pacman -S --noconfirm --needed base-devel jq
233 # pacaur seems to be the best, although it + cower has a few minor bugs,
234 # its design goals seem good, so, going for it.
235
236 aurpi() {
237 for p in "$@"; do
238 tempdir=$(mktemp -d)
239 pushd $tempdir
240 aurex "$p"
241 makepkg -sri --skippgpcheck --noconfirm
242 popd
243 rm -rf $tempdir
244 done
245 }
246 aurpi cower pacaur
247
248 pi pacserve
249
250 x=$(mktemp); /usr/bin/pacman.conf-insert_pacserve >$x
251 sudo dd of=/etc/pacman.conf if=$x; rm $x
252 sudo systemctl enable pacserve.service
253 sudo systemctl start pacserve.service
254
255 # strange error if just installing trash-cli: "pyalpm requires python",
256 # so I see that it requires python2, and installing that manually fixes it.
257 # I didn't see this on earlier installation, main thing which changed was
258 # pacserve, so not sure if it's related.
259 pi python2
260 fi
261
262 pup
263 pi trash-cli
264
265
266 ###### link files ###########
267 # convenient to just do all file linking in one place
268
269 # if it wasn't set already, we could set hostname here
270 #echo treetowl | s dd of=/etc/hostname
271 #s hostname -F /etc/hostname
272 #HOSTNAME=$(hostname)
273
274
275 s lnf -T /a/bin /b
276
277 if has_p; then
278 lnf -T /p/News ~/News
279 fi
280
281 s lnf /q/root/.editor-backups /q/root/.undo-tree-history \
282 /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root
283
284 rootsshsync
285
286 s lnf /a/c/.inputrc /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
287
288 # machine is going away
289 # if [[ $HOSTNAME == htpc ]]; then
290 # lnf -T /i/Videos ~/Downloads
291 # fi
292
293 if has_p; then
294 # for dovecot
295 lnf -T /i/k/mboxes ~/mail
296 fi
297
298
299 # basic needed packages
300 case $(distro-name) in
301 debian)
302 if has_x; then
303 if isdebian-stable; then
304 pi firefox/$codename-backports
305 else
306 # for a while, firefox/unstable did not have
307 # dependencies satisfied by testing packages, and i hit
308 # a conflict, it wanted a newer libfontconfig1, but
309 # emacs build-deps wanted an older one. In this case,
310 # I switch to using firefox-esr. note: They seem
311 # to release a new esr version every 9 months or so.
312 pi firefox/unstable
313 s dd of=/etc/apt/preferences.d/firefox <<'EOF'
314 Package: firefox
315 Pin: release a=unstable
316 Pin-Priority: 500
317 EOF
318 fi
319 fi
320 # for hosts which require nonfree drivers
321 # i previously had extra packages listed here linux-image-amd64
322 # firmware-linux-free linux-headers-amd64, but I
323 # don\'t see any reason why. seems to work in testing without.
324 # remove this note if it continues to work.
325 p=firmware-linux-nonfree
326 if apt-cache show $p &>/dev/null; then
327 pi $p
328 fi
329 ;;&
330 ubuntu|debian)
331 if has_x; then
332 if isdebian-stable; then
333 pi xmacro
334 else
335 pi xmacro/unstable # has no unstable deps
336 fi
337 pi gtk-redshift xinput
338 fi
339 ;;&
340 fedora)
341 p -y groupinstall development-tools c-development books admin-tools
342 pi wget man-pages
343 if has_x; then
344 pi redshift-gtk
345 # debian has this package patched to work, upstream is dead
346 # tried using alien, pi alien, alien -r *.deb, rpm -Uhv *.rpm, got this error, so fuck it
347 # 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
348 # http://packages.debian.org/source/sid/xmacro
349 pi patch libXtst-devel
350 cd $(mktemp -d)
351 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911.orig.tar.gz
352 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911-6.diff.gz
353 ex *.gz
354 patch -p0 < xmacro_0.3pre-20000911-6.diff
355 cd xmacro-0.3pre-20000911.orig
356 make
357 sleep 1 # not sure why the following command couldn\'t find, so trying this
358 # no make install target
359 s cp -f xmacroplay xmacrorec xmacrorec2 /usr/local/bin
360 fi
361 ;;&
362 arch)
363 # like apt-cache
364 pi pkgfile
365 s pkgfile --update
366 if has_x; then
367 # libxtst is missing dep https://aur.archlinux.org/packages/xmacro/#news
368 pi xorg-server redshift xorg-xinput libxtst xmacro
369
370 # background:
371 # https://aur.archlinux.org/packages/xkbset/#comment-545419
372 cert=$(mktemp)
373 cat >$cert <<'EOF'
374 -----BEGIN CERTIFICATE-----
375 MIIJADCCB+igAwIBAgIRAIVAhZ0TMbQ5jTm0koI8X6YwDQYJKoZIhvcNAQELBQAw
376 djELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1JMRIwEAYDVQQHEwlBbm4gQXJib3Ix
377 EjAQBgNVBAoTCUludGVybmV0MjERMA8GA1UECxMISW5Db21tb24xHzAdBgNVBAMT
378 FkluQ29tbW9uIFJTQSBTZXJ2ZXIgQ0EwHhcNMTUxMjA4MDAwMDAwWhcNMTgxMjA3
379 MjM1OTU5WjCBsTELMAkGA1UEBhMCVVMxDjAMBgNVBBETBTY1MjExMREwDwYDVQQI
380 EwhNaXNzb3VyaTERMA8GA1UEBxMIQ29sdW1iaWExHzAdBgNVBAkTFjExMDAgQ2Fy
381 cmllIEZyYW5ja2UgRHIxHzAdBgNVBAoTFlVuaXZlcnNpdHkgb2YgTWlzc291cmkx
382 CzAJBgNVBAsTAk1VMR0wGwYDVQQDExRmYWN1bHR5Lm1pc3NvdXJpLmVkdTCCASIw
383 DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN8Kap8hASpxQeqjHibGsCR1PBkh
384 nW9p5FkuhGpMW/3ko8QfxH0W1Hq2y2DTFUmq17kH3GfT3h9a7HcmUrC3q15PciOB
385 WR3j8u0bDfVppyAZXiHJzYGN7xHiPrZtFEGgwZd28+sW80WXTbGl+zKkmeZguGdH
386 AVGeWJEFK44ctLbpjHWCy+xNuhxJuL4olwPoV7WX9IUhceC0rxYQANhLGOJhbchj
387 Z76MA8dc2K3CZI5m7VqQwl09QSnCfz00afUr88ny9vj1S5k2ADS46ga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YzsKQpn9t
420 aofMcTfvnCjq+MCIaeYnUKBVww0lOJlUxZGKxFJvRpf78HfbBauojjRO2zXLZD/u
421 KMspbTfDaj5etIgWGShY2eml3N/SjAENmZYkcgDBYFyi8CckcEBAVzpH1+D+7Anz
422 txHSYDNHAYLv83MwbegApa1FwPqlG/4SdEU8G6e6Xf5GLC/6GPGVTUpr7o348OOO
423 lzGQzw==
424 -----END CERTIFICATE-----
425 -----BEGIN CERTIFICATE-----
426 MIIF+TCCA+GgAwIBAgIQRyDQ+oVGGn4XoWQCkYRjdDANBgkqhkiG9w0BAQwFADCB
427 iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
428 cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
429 BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQx
430 MDA2MDAwMDAwWhcNMjQxMDA1MjM1OTU5WjB2MQswCQYDVQQGEwJVUzELMAkGA1UE
431 CBMCTUkxEjAQBgNVBAcTCUFubiBBcmJvcjESMBAGA1UEChMJSW50ZXJuZXQyMREw
432 DwYDVQQLEwhJbkNvbW1vbjEfMB0GA1UEAxMWSW5Db21tb24gUlNBIFNlcnZlciBD
433 QTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJwb8bsvf2MYFVFRVA+e
434 xU5NEFj6MJsXKZDmMwysE1N8VJG06thum4ltuzM+j9INpun5uukNDBqeso7JcC7v
435 HgV9lestjaKpTbOc5/MZNrun8XzmCB5hJ0R6lvSoNNviQsil2zfVtefkQnI/tBPP
436 iwckRR6MkYNGuQmm/BijBgLsNI0yZpUn6uGX6Ns1oytW61fo8BBZ321wDGZq0GTl
437 qKOYMa0dYtX6kuOaQ80tNfvZnjNbRX3EhigsZhLI2w8ZMA0/6fDqSl5AB8f2IHpT
438 eIFken5FahZv9JNYyW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HnHcAP9Dc1ew91Pq7P8yF1m9/
488 qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
489 VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
490 L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
491 jjxDah2nGN59PRbxYvnKkKj9
492 -----END CERTIFICATE-----
493 EOF
494 cat /etc/ssl/certs/ca-certificates.crt >> $cert
495 CURL_CA_BUNDLE=$cert pi xkbset
496 fi
497
498 ;;&
499 ubuntu|debian|fedora)
500 if has_x; then
501 if isdebian-stable; then
502 pi xkbset
503 else
504 # xkbset was in testing for quite a while, dunno
505 # why it\'s not anymore. Sometime I should check and
506 # see if it\'s back in testing, but the unstable package
507 # doesn\'t upgrade anything form testing, and it\'s tiny
508 # so I\'m not bothering to automate it.
509 pi xkbset/unstable
510 fi
511 fi
512 ;;&
513 esac
514
515 if has_x; then
516 pi xbindkeys
517 fi
518 pi cryptsetup lvm2
519 # enables trim for volume delete, other rare commands.
520 sudo $sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
521
522 if encrypted; then
523 if isdeb; then
524 sudo cp /usr/share/doc/util-linux/examples/fstrim.{service,timer} /etc/systemd/system
525 fi
526 # does weekly trim
527 sudo systemctl enable fstrim.timer
528 fi
529
530 dirs=(/mnt/{1,2,3,4,5,6,7,8,9})
531 s mkdir -p "${dirs[@]}"
532 s chown ian:ian "${dirs[@]}"
533
534
535 tu /etc/fstab <<'EOF'
536 /i/w /w none bind,noauto 0 0
537 /i/k /k none bind,noauto 0 0
538 EOF
539
540
541 if ! mountpoint /kr; then
542 s mkdir -p /kr
543 s chown ian:traci /kr
544 fi
545
546 if home_network; then
547 if [[ $HOSTNAME == treetowl ]]; then
548 tu /etc/fstab <<'EOF'
549 /k /kr none bind,noauto 0 0
550 EOF
551 else
552 tu /etc/fstab <<'EOF'
553 treetowl:/k /kr nfs noauto 0 0
554 EOF
555 fi
556 fi
557
558 s mkdir -p /q /i/{w,k}
559 for dir in /{i,w,k}; do
560 if mountpoint $dir; then continue; fi # already mounted
561 s mkdir -p $dir
562 s chown ian:ian $dir
563 done
564
565 # not needed for all hosts, but rather just keep it uniform
566 s mkdir -p /mnt/iroot
567
568 # debian auto mounting of multi-disk encrypted btrfs is busted. It is
569 # in jessie, and in stretch as of 11/26/2016 I have 4 disks in cryptab,
570 # based on 3 of those, it creates .device units for /dev/mapper/dev...
571 # then waits endlessly for them on bootup, after the /dev/mapper disks
572 # have already been created and exist. todo: create a simple repro
573 # for this in a vm and report it upstream.
574 if has_btrfs || home_network; then
575 pi nfs-common
576 s dd of=/root/imount <<'EOF'
577 #!/bin/bash
578 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
579 set -eE -o pipefail
580 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
581 for dir in /i /mnt/iroot /k /kr /w; do
582 if ! mountpoint $dir &>/dev/null && \
583 awk '{print $2}' /etc/fstab | grep -xF $dir &>/dev/null; then
584 if awk '{print $3}' /etc/fstab | grep -xF nfs &>/dev/null; then
585 mount $dir || echo "warning: failed to mount nfs on $dir"
586 else
587 mount $dir
588 fi
589 fi
590 done
591 EOF
592 s chmod +x /root/imount
593
594 s dd of=/etc/systemd/system/imount.service <<'EOF'
595 [Unit]
596 Description=Mount /i and related mountpoints
597
598 [Service]
599 Type=oneshot
600 ExecStart=/root/imount
601
602 [Install]
603 # note /kr needs networking, this target is the simplest way to
604 # time it when the network should be up, but not do something
605 # dumb like delay startup until the network is up. It happens
606 # at some time after network.target
607 WantedBy=multi-user.target
608 EOF
609 sudo systemctl daemon-reload # needed if the file was already there
610 sudo systemctl enable imount.service
611 sudo systemctl start imount.service
612 fi
613
614 dir=/nocow
615 if has_btrfs; then
616 if ! mountpoint $dir; then
617 subvol=/mnt/root/nocow
618 if [[ ! -e $subvol ]]; then
619 s btrfs subvolume create $subvol
620 s chown root:1000 $subvol
621 s chattr +C $subvol
622 fi
623
624 first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab)
625 tu /etc/fstab <<EOF
626 $first_root_crypt /nocow btrfs noatime,subvol=nocow 0 0
627 EOF
628 s mkdir -p $dir
629 s chown ian:ian $dir
630 s mount $dir
631 fi
632 else
633 sudo mkdir -p $dir
634 fi
635
636 # ssh and probably some other things care about parent directory
637 # ownership, and ssh doesn\'t allow any group writable parent
638 # directories, so we are forced to use a directory structure similar
639 # to home directories
640 s chown root:ian /q
641 s chmod 755 /q
642
643
644 # it comes with stretch and arch, but not jessie.
645 # propogate /etc/udev/hwdb.d
646 if which systemd-hwdb; then
647 s systemd-hwdb update
648 ser restart systemd-udev-trigger
649 fi
650
651
652 if isdeb; then
653 # I\'ve had problems with postfix on debian:
654 # on stretch, a startup ordering issue caused all mail to fail.
655 # postfix changed defaults to only use ipv6 dns, causing all my mail to fail.
656 # exim4 is default on debian, so I assume it would
657 # be packaged better to avoid these types of things.
658 # I haven\'t gotten around to getting a non-debian exim
659 # setup.
660 mail-setup exim4
661 else
662 mail-setup postfix
663 fi
664
665 if isubuntu; then
666 # disable crash report annoying crap
667 s dd of=/etc/default/apport <<<'enabled=0'
668 fi
669
670 # fai sets this an old way that doesn't work for stretch.
671 # no harm in setting it universally here.
672 # using debconf-set-selection, the area gets reset to ETC
673 # on my linode test machine after doing a dpkg-reconfigure, or a reinstall,
674 # so we are using expect :(
675 # I got a random error when running this, so I added a sleep
676 # rather than trying to write a whole detect and wait loop.
677 # E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
678 # E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
679 sleep 1
680 s apt-get -y install --no-install-recommends expect
681 s expect <<EOF
682 set force_conservative 0
683 spawn dpkg-reconfigure tzdata -freadline
684 expect -nocase timeout {exit 1} "Geographic area:"
685 send "12\r"
686 expect -nocase timeout {exit 1} "Time zone:"
687 send "11\r"
688 expect eof
689 exit
690 EOF
691
692
693 if has_x; then
694 if isarch; then
695 # install so it's build dependencies don't get removed.
696
697 # emacs git build is currently broken
698 if false; then
699 x=$(mktemp -d)
700 pushd $x
701 aurex emacs-git
702 makepkg -si --noconfirm
703 popd
704 rm -rf $x
705 else
706 pi emacs
707 fi
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 || /a/bin/buildscripts/emacs
714 fi
715 fi
716
717 # todo, figure this out for arch if we ever try out gnome.
718 if ! isarch; then
719 # install for multiple display managers in case we use one
720 if isdeb; then
721 dir=/etc/gdm3
722 elif isfedora; then
723 # fedora didn\'t have the 3.
724 dir=/etc/gdm
725 fi
726 s mkdir -p $dir/PostLogin
727 s command cp /a/bin/distro-setup/desktop-20-autostart.sh $dir/PostLogin/Default
728 s mkdir /etc/lightdm/lightdm.conf.d
729 s dd of=/etc/lightdm/lightdm.conf.d/12-ian.conf <<'EOF'
730 [SeatDefaults]
731 session-setup-script=/a/bin/distro-setup/desktop-20-autostart.sh
732 EOF
733 fi
734
735
736 pi ghc sakura
737 # todo, also note for work comp, scp opt/org-mode bin/build-scripts
738
739 # use the package manger version to install the cabal version
740 pi cabal-install
741 cabal update
742 PATH="$PATH:$HOME/.cabal/bin"
743
744 # todo, on older ubuntu I used cabal xmonad + xfce,
745 # see /a/bin/old-unused/xmonad-cabal.sh
746
747 # trying out the distros versions newer distros
748 pi xmonad
749 if isarch; then
750 # for displaying error messages.
751 # optional dependency in arch, standard elsewhere.
752 pi xorg-xmessage xmonad-contrib xorg-xsetroot xorg-xinit
753
754 # https://wiki.archlinux.org/index.php/Xinitrc
755 for homedir in /home/*; do
756 cp /etc/X11/xinit/xinitrc $homedir/.xinitrc
757 $sed -ri '/^ *twm\b/,$d' $homedir/.xinitrc
758 tee -a $homedir/.xinitrc <<'EOF'
759 /a/bin/desktop-20-autostart.sh
760 xsetroot -cursor_name left_ptr
761 exec xmonad
762 EOF
763 done
764 else
765 pi suckless-tools
766 fi
767 pi dmenu
768
769 if isdeb && (tp || x2); then
770 pi task-laptop
771 fi
772 fi
773
774 # the first pup command can kill off our /etc/ mod, so rerun this
775 /a/exe/ssh-emacs-setup
776 echo "$0: $(date): ending now"