various fixes and improvements
[distro-setup] / distro-begin
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
4
5 # todo. dunno why, but original bootstrap of timezone is not sticking.
6 # fixed manually with:
7 # s dpkg-reconfigure tzdata
8 # enter 12 then 11.
9
10
11 # for bootstrapping a new machine
12
13 # to make ssh run better, first run this:
14 sudo bash -c 'source /a/c/repos/bash/.bashrc && source /a/exe/ssh-emacs-setup'
15
16
17 # see t.org for OS installer notes
18
19 # usage: $0 [OPTIONS] HOSTNAME
20
21 # tips:
22 # run any sudo command first so your pass is cached
23 # set the scrollback to unlimited in case something goes wrong
24
25 if [[ $EUID == 0 ]]; then
26 if getent passwd ian; then
27 echo "$0: error: running as root. unprivileged user exists. use it."
28 exit 1
29 else
30 echo "$0: warning: running as root. I will setup users then exit"
31 fi
32 fi
33
34 interactive=false # set this to true if running by hand in emacs
35 [[ $- == *i* ]] || interactive=false
36
37 if ! $interactive; then
38 set -x
39 set -e -o pipefail
40 fi
41 set -E
42 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
43
44 exec &> >(sudo tee -a /var/log/distro-begin)
45 echo "$0: $(date): starting now)"
46
47 # headless=false # unused atm
48 recompile=false
49 # for copying to a new data fs
50 bootstrapfs=false # old flag, needs new look before using.
51 while [[ $1 == -* ]]; do
52 case $1 in
53 # avoid some of the longer compilation steps,
54 # when we need to rerun because we had an error
55 -r) recompile=true; shift ;;
56 esac
57 done
58
59 if [[ $1 ]]; then
60 export HOSTNAME=$1
61 fi
62
63 for f in iank-dev htpc treetowl x2 frodo tp li lj; do
64 eval "$f() { [[ $HOSTNAME == $f ]]; }"
65 done
66 has_p() { iank-dev || x2 || frodo || tp; }
67 has_x() { ! { lj || li; }; }
68 encrypted() { has_p; }
69
70 shopt -s extglob
71 export GLOBIGNORE=*/.:*/..
72 umask 0002
73
74
75 ####### end command line parsing
76
77 PATH="/a/exe:$PATH"
78 if encrypted; then
79 # I tried making a service which was dependent on reboot.target,
80 # but it happened too late in the shutdown process.
81 sudo dd of=/etc/systemd/system/keyscripton.service <<'EOF'
82 [Unit]
83 Description=Turn on automatic decryption of drives on boot
84 # tried using graphical.target, but it made my display manager restart before rebooting.
85 # generally, I don't think targets order shutdown like they do startup.
86 # So, I did systemd-analyze plot > something.svg, and picked a reliably started
87 # service that happens late in the game.
88 After=postfix.service
89 DefaultDependencies=no
90 Conflicts=reboot.target
91
92 [Service]
93 Type=oneshot
94 RemainAfterExit=yes
95 ExecStart=/bin/true
96 ExecStop=/a/exe/keyscript-on
97
98 [Install]
99 WantedBy=keyscriptoff.service
100 EOF
101 sudo systemctl daemon-reload # needed if the file was already there
102 sudo systemctl stop keyscripton.service
103 # sudo systemctl start keyscripton.service
104 sudo systemctl enable keyscripton.service
105
106 sudo dd of=/etc/systemd/system/keyscriptoff.service <<'EOF'
107 [Unit]
108 Description=Turn off automatic decryption of drives on boot
109
110 [Service]
111 Type=oneshot
112 ExecStart=/a/exe/keyscript-off
113
114 [Install]
115 WantedBy=multi-user.target
116 EOF
117 sudo systemctl daemon-reload # needed if the file was already there
118 sudo systemctl enable keyscriptoff.service
119 sudo systemctl start keyscriptoff.service
120 fi
121
122
123 install-myqueue
124
125 if iank-dev; then
126 desktop=$(ssh root@iankelling.org grep desktop /etc/hosts | grep -o "^.* ")
127 if $bootstrapfs; then
128 # for bootstrapping at a new job:
129 cp="scp $desktop:"
130 # for moving to a new hd, change $cp to move between filesystems
131 mkdir -p /a/bin
132 chown -R ian:ian /a # probably needs to be removed
133 $cp/a/c /a
134 $cp/a/c/bin/{bash-programs-by-ian,distro-begin,distro-functions,input-setup.sh} /a/bin
135 echo -e \\n\\n\\n | ssh-keygen -t rsa
136 fi
137 fi
138
139 # this script has been designed to be idempotent
140 # todo, it would be nice to cut down on some of the output
141
142
143 for x in /a/bin/errhandle/*-function; do
144 source $x
145 done
146
147
148 set +e
149 $interactive || errcatch
150 set +x
151 source /a/bin/distro-functions/src/identify-distros
152 $interactive || set -x
153 echo path:$PATH
154
155
156 if isfedora; then
157 # comment out line disallowing calling sudo in scripts
158 sudo sed -i 's/^Defaults *requiretty/#\0 # ian commented/' /etc/sudoers
159 # turn on magic sysrq commands for this boot cycle
160 echo 1 > sudo dd of=/proc/sys/kernel/sysrq
161 # selinux is not user friendly. Like, you enable samba, but you haven't run the magic selinux commands so it doesn't work
162 # and you have no idea why.
163 sudo sed -i 's/^\(SELINUX=\).*/\1disabled/' /etc/selinux/config
164 selinuxenabled && sudo setenforce 0
165 fi
166
167
168 # already ran for pxe installs, but used for vps & updates
169 distro=$(distro-name)
170 case $distro in
171 ubuntu|debian)
172 sudo bash -c ". /a/bin/fai/fai-wrapper && /a/bin/fai/fai/config/scripts/GRUB_PC/11-ian"
173 ;;
174 *)
175 sudo bash -c ". /a/bin/fai/fai-wrapper &&
176 /a/bin/fai/fai/config/distro-install-common/end"
177 ;;
178 esac
179
180
181 if [[ $EUID == 0 ]]; then
182 echo "$0: running as root. exiting now that users are setup"
183 exit 0
184 fi
185
186
187 # link files
188
189 lnf-home() {
190 # $2 and opts are unused so far.
191 opts=()
192 while [[ $1 == -* ]]; do
193 opts+=($1)
194 shift
195 done
196 lnf ${opts[@]} "$1" /home/ian/$2
197 sudo -u traci -i <<EOF
198 PATH="/a/exe:$PATH"
199 lnf ${opts[@]} "$1" /home/traci/$2
200 EOF
201 }
202
203 for x in /a/c/repos/bash/!(.git); do
204 lnf-home "$x"
205 sudo -i <<EOF
206 PATH="/a/exe:$PATH"
207 lnf $x /root
208 EOF
209 done
210
211 echo path:$PATH
212
213 set +x
214 errallow
215 source ~/.bashrc
216 echo path:$PATH
217 $interactive || errcatch
218 $interactive || set -x
219
220
221 # passwordless sudo
222 tu /etc/sudoers <<'EOF'
223 ian ALL=(ALL) NOPASSWD: ALL
224 Defaults env_keep += SUDOD
225 EOF
226
227
228 # enable magic sysrq keys. debian docs say it is already enabled by default
229 isfedora && tu /etc/sysctl.conf 'kernel.sysrq = 1'
230
231
232
233 if isdebian; then
234 codename=$(debian-codename)
235 # non-existent var, as Im not planning to use stable right now
236 if isdebian-stable; then
237 if has_x; then
238 s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
239 deb http://mozilla.debian.net/ $codename-backports firefox-release
240 deb-src http://mozilla.debian.net/ $codename-backports firefox-release
241 EOF
242 fi
243
244 # we change the mirror from the default, so we cant use tu
245 s dd of=/etc/apt/sources.list.d/main-backports.list <<EOF
246 deb http://http.debian.net/debian $codename-backports main contrib non-free
247 deb-src http://http.debian.net/debian $codename-backports main contrib non-free
248 EOF
249
250 p update
251 # take care of mozilla signing errors in previous command
252 pi pkg-mozilla-archive-keyring
253 p update
254 else
255 :
256 # this would change stable to testing, but I set that up already.
257 # It\'s just a no-op if its already testing.
258 # sudo sed -ri 's!^( *[^ #]+ +[^ ]+ +)[[:alpha:]]+(.*)!\1testing\2!' /etc/apt/sources.list
259 p update
260 fi
261 fi
262
263 if isarch; then
264 #https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
265 sudo pacman -S --noconfirm --needed base-devel jq
266 # pacaur seems to be the best, although it + cower has a few minor bugs,
267 # its design goals seem good, so, going for it.
268
269 aurpi() {
270 for p in "$@"; do
271 tempdir=$(mktemp -d)
272 pushd $tempdir
273 aurex "$p"
274 makepkg -sri --skippgpcheck --noconfirm
275 popd
276 rm -rf $tempdir
277 done
278 }
279 aurpi cower pacaur
280
281 # for aur, automatically dl & add gpg keys.
282 # Just the keyserver-options line goes in dirmngr.conf once
283 # this bug is fixed: https://bugs.gnupg.org/gnupg/issue2147
284 for homedir in /home/*; do
285 # this creates ~/.gnupg. addgnupghome is kinda broken on arch.
286 HOME=$homedir gpg -k
287 teeu $homedir/.gnupg/gpg.conf <<EOF
288 $(grep -o '^ *keyserver .*' $homedir/.gnupg/dirmngr.conf)
289 keyserver-options auto-key-retrieve
290 EOF
291 done
292 pi pacserve
293 x=$(mktemp); /a/opt/pacman.conf-insert_pacserve >$x
294 sudo dd of=/etc/pacman.conf if=$x; rm $x
295 sudo systemctl enable pacserve.service
296 sudo systemctl start pacserve.service
297
298 # strange error if just installing trash-cli: "pyalpm requires python",
299 # so I see that it requires python2, and installing that manually fixes it.
300 # I didn't see this on earlier installation, main thing which changed was
301 # pacserve, so not sure if it's related.
302 pi python2
303 fi
304
305 pup
306 pi trash-cli
307
308
309 ###### link files ###########
310 # convenient to just do all file linking in one place
311
312 # if it wasn't set already, we could set hostname here
313 #echo treetowl | s dd of=/etc/hostname
314 #s hostname -F /etc/hostname
315 #HOSTNAME=$(hostname)
316
317 #########################################
318 # NOTE: only /a needs to be mounted for creating links!
319 ###########################################
320
321 # todo: reconcile ~/.ssh/config work/home
322 s lnf -T /q/p /p
323 s lnf -T /a/bin /b
324 conflink
325
326 if has_p; then
327 lnf -T /p/offlineimap ~/Maildir
328 lnf -T /p/News ~/News
329 # don't use /* because I don't want to require it to be mounted
330 fi
331
332 s lnf /q/root/.editor-backups /q/root/.undo-tree-history \
333 /a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root
334
335 rootsshsync
336
337 s lnf /a/c/.inputrc /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
338
339 # machine is going away
340 # if [[ $HOSTNAME == htpc ]]; then
341 # lnf -T /i/Videos ~/Downloads
342 # fi
343
344 if has_p; then
345 # for dovecot
346 lnf -T /i/k/mboxes ~/mail
347 fi
348
349
350 # basic needed packages
351 case $(distro-name) in
352 debian)
353 if has_x; then
354 if isdebian-stable; then
355 pi firefox/$codename-backports
356 else
357 pi firefox/unstable # has no unstable dependencies
358 fi
359 fi
360 # for hosts which require nonfree drivers
361 case $HOSTNAME in
362 tp|x2) : ;;
363 *) pi linux-image-amd64 firmware-linux-nonfree \
364 firmware-linux-free linux-headers-amd64
365 ;;
366 esac
367 ;;&
368 ubuntu|debian)
369 if has_x; then
370 pi xmacro gtk-redshift xinput
371 fi
372 ;;&
373 fedora)
374 p -y groupinstall development-tools c-development books admin-tools
375 pi wget man-pages
376 if has_x; then
377 pi redshift-gtk
378 # debian has this package patched to work, upstream is dead
379 # tried using alien, pi alien, alien -r *.deb, rpm -Uhv *.rpm, got this error, so fuck it
380 # 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
381 # http://packages.debian.org/source/sid/xmacro
382 pi patch libXtst-devel
383 cd $(mktemp -d)
384 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911.orig.tar.gz
385 wget http://ftp.de.debian.org/debian/pool/main/x/xmacro/xmacro_0.3pre-20000911-6.diff.gz
386 ex *.gz
387 patch -p0 < xmacro_0.3pre-20000911-6.diff
388 cd xmacro-0.3pre-20000911.orig
389 make
390 sleep 1 # not sure why the following command couldn\'t find, so trying this
391 # no make install target
392 s cp -f xmacroplay xmacrorec xmacrorec2 /usr/local/bin
393 fi
394 ;;&
395 arch)
396 # like apt-cache
397 pi pkgfile
398 s pkgfile --update
399 if has_x; then
400 # libxtst is missing dep https://aur.archlinux.org/packages/xmacro/#news
401 pi xorg-server redshift xorg-xinput libxtst xmacro
402
403 # background:
404 # https://aur.archlinux.org/packages/xkbset/#comment-545419
405 cert=$(mktemp)
406 cat >$cert <<'EOF'
407 -----BEGIN CERTIFICATE-----
408 MIIJADCCB+igAwIBAgIRAIVAhZ0TMbQ5jTm0koI8X6YwDQYJKoZIhvcNAQELBQAw
409 djELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1JMRIwEAYDVQQHEwlBbm4gQXJib3Ix
410 EjAQBgNVBAoTCUludGVybmV0MjERMA8GA1UECxMISW5Db21tb24xHzAdBgNVBAMT
411 FkluQ29tbW9uIFJTQSBTZXJ2ZXIgQ0EwHhcNMTUxMjA4MDAwMDAwWhcNMTgxMjA3
412 MjM1OTU5WjCBsTELMAkGA1UEBhMCVVMxDjAMBgNVBBETBTY1MjExMREwDwYDVQQI
413 EwhNaXNzb3VyaTERMA8GA1UEBxMIQ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S5lZHWCFHBtLmNoZW0ubWlzc291cmku
446 ZWR1ghxyZWNydWl0aW5nLmVjb24ubWlzc291cmkuZWR1ghdyZXBlYy5lY29uLm1p
447 c3NvdXJpLmVkdYIUc2NhbmxhYi5taXNzb3VyaS5lZHWCFnNzc2MuY29hcy5taXNz
448 b3VyaS5lZHWCF3RlYWNoLmNvYXMubWlzc291cmkuZWR1ghd0b3B0ZWFjaGVyLm1p
449 c3NvdXJpLmVkdYIQdnNmLm1pc3NvdXJpLmVkdYIid2hpdGVwYXBlci5ncmFkc2No
450 b29sLm1pc3NvdXJpLmVkdTANBgkqhkiG9w0BAQsFAAOCAQEAQutYVAqG7MpmG2Nu
451 Z/UypjYkN4JvwRbKBpTrce2IT/Sy29x6chBbyD+0WE6QORBtaUHuzE1KoXqpnF4M
452 QrkKw0oBAC6x9dISoomq0DkIndtoBYYLaxSoII6F4OGWgF7pQ/7MiCBYzsKQpn9t
453 aofMcTfvnCjq+MCIaeYnUKBVww0lOJlUxZGKxFJvRpf78HfbBauojjRO2zXLZD/u
454 KMspbTfDaj5etIgWGShY2eml3N/SjAENmZYkcgDBYFyi8CckcEBAVzpH1+D+7Anz
455 txHSYDNHAYLv83MwbegApa1FwPqlG/4SdEU8G6e6Xf5GLC/6GPGVTUpr7o348OOO
456 lzGQzw==
457 -----END CERTIFICATE-----
458 -----BEGIN CERTIFICATE-----
459 MIIF+TCCA+GgAwIBAgIQRyDQ+oVGGn4XoWQCkYRjdDANBgkqhkiG9w0BAQwFADCB
460 iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
461 cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
462 BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQx
463 MDA2MDAwMDAwWhcNMjQxMDA1MjM1OTU5WjB2MQswCQYDVQQGEwJVU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5jb20wDQYJKoZI
480 hvcNAQEMBQADggIBAC0RBjjW29dYaK+qOGcXjeIT16MUJNkGE+vrkS/fT2ctyNMU
481 11ZlUp5uH5gIjppIG8GLWZqjV5vbhvhZQPwZsHURKsISNrqOcooGTie3jVgU0W+0
482 +Wj8mN2knCVANt69F2YrA394gbGAdJ5fOrQmL2pIhDY0jqco74fzYefbZ/VS29fR
483 5jBxu4uj1P+5ZImem4Gbj1e4ZEzVBhmO55GFfBjRidj26h1oFBHZ7heDH1Bjzw72
484 hipu47Gkyfr2NEx3KoCGMLCj3Btx7ASn5Ji8FoU+hCazwOU1VX55mKPU1I2250Lo
485 RCASN18JyfsD5PVldJbtyrmz9gn/TKbRXTr80U2q5JhyvjhLf4lOJo/UzL5WCXED
486 Smyj4jWG3R7Z8TED9xNNCxGBMXnMete+3PvzdhssvbORDwBZByogQ9xL2LUZFI/i
487 eoQp0UM/L8zfP527vWjEzuDN5xwxMnhi+vCToh7J159o5ah29mP+aJnvujbXEnGa
488 nrNxHzu+AGOePV8hwrGGG7hOIcPDQwkuYwzN/xT29iLp/cqf9ZhEtkGcQcIImH3b
489 oJ8ifsCnSbu0GB9L06Yqh7lcyvKDTEADslIaeSEINxhO2Y1fmcYFX/Fqrrp1WnhH
490 OjplXuXE0OPa0utaKC25Aplgom88L2Z8mEWcyfoB7zKOfD759AN7JKZWCYwk
491 -----END CERTIFICATE-----
492 -----BEGIN CERTIFICATE-----
493 MIIF3jCCA8agAwIBAgIQAf1tMPyjylGoG7xkDjUDLTANBgkqhkiG9w0BAQwFADCB
494 iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
495 cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
496 BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTAw
497 MjAxMDAwMDAwWhcNMzgwMTE4Mj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8wDQYJKoZIhvcNAQEMBQADggIBAFzUfA3P9wF9QZllDHPF
514 Up/L+M+ZBn8b2kMVn54CVVeWFPFSPCeHlCjtHzoBN6J2/FNQwISbxmtOuowhT6KO
515 VWKR82kV2LyI48SqC/3vqOlLVSoGIG1VeCkZ7l8wXEskEVX/JJpuXior7gtNn3/3
516 ATiUFJVDBwn7YKnuHKsSjKCaXqeYalltiz8I+8jRRa8YFWSQEg9zKC7F4iRO/Fjs
517 8PRF/iKz6y+O0tlFYQXBl2+odnKPi4w2r78NBc5xjeambx9spnFixdjQg3IM8WcR
518 iQycE0xyNN+81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYze
519 Sf7dNXGiFSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZ
520 XHlKYC6SQK5MNyosycdiyA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/
521 qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
522 VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
523 L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
524 jjxDah2nGN59PRbxYvnKkKj9
525 -----END CERTIFICATE-----
526 EOF
527 cat /etc/ssl/certs/ca-certificates.crt >> $cert
528 CURL_CA_BUNDLE=$cert pi xkbset
529 fi
530
531 ;;&
532 ubuntu|debian|fedora)
533 if has_x; then
534 pi xkbset
535 fi
536 ;;&
537 esac
538
539 if has_x; then
540 pi xbindkeys
541 fi
542 pi cryptsetup lvm2
543 # enables trim for volume delete, other rare commands.
544 sudo sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
545
546 if encrypted; then
547 if isdeb; then
548 sudo cp /usr/share/doc/util-linux/examples/fstrim.{service,timer} /etc/systemd/system
549 fi
550 # does weekly trim
551 sudo systemctl enable fstrim.timer
552 fi
553
554 dirs=(/mnt/{1,2,3,4,5,6,7,8,9})
555 s mkdir -p "${dirs[@]}"
556 s chown ian:ian "${dirs[@]}"
557
558 if [[ $HOSTNAME == treetowl ]]; then
559 tu /etc/fstab <<'EOF'
560 UUID=3f7b31cd-f299-40b4-a86b-7604282e2715 /i btrfs noatime 0 2
561 EOF
562 else
563 tu /etc/fstab <<'EOF'
564 /q/i /i none bind 0 0
565 EOF
566 fi
567
568 tu /etc/fstab <<'EOF'
569 /i/w /w none bind 0 0
570 /i/k /k none bind 0 0
571 EOF
572
573 if ! mountpoint /kfrodo; then
574 s mkdir -p /kfrodo
575 s chown ian:traci /kfrodo
576 fi
577 if [[ $HOSTNAME == frodo ]]; then
578 tu /etc/fstab <<'EOF'
579 /k /kfrodo none bind 0 0
580 EOF
581 else
582 tu /etc/fstab <<'EOF'
583 frodo:/k /kfrodo nfs defaults 0 0
584 EOF
585 fi
586
587 s mkdir -p /q/i/{w,k}
588 for dir in /{i,w,k}; do
589 if mountpoint $dir; then continue; fi
590 s mkdir -p $dir
591 s chown ian:ian $dir
592 s mount $dir
593 done
594
595
596 # ssh and probably some other things care about parent directory
597 # ownership, and ssh doesn\'t allow any group writable parent
598 # directories, so we are forced to use a directory structure similar
599 # to home directories
600 s chown root:ian /q
601 s chmod 755 /q
602
603
604 # it comes with stretch and arch, but not jessie.
605 # propogate /etc/udev/hwdb.d
606 if which systemd-hwdb; then
607 s systemd-hwdb update
608 ser restart systemd-udev-trigger
609 fi
610
611 # work desktop doesnt need gpg stuff, but it doesnt hurt
612 s dd of=/etc/profile.d/environment.sh <<'EOF'
613 # IAN: EDIT THIS FROM /a/bin/distro-setup/distro-begin
614
615 if [ -f $HOME/path_add-function ]; then
616 . $HOME/path_add-function
617 path_add /usr/sbin /usr/local/sbin /sbin
618 path_add /a/exe /a/opt/bin $HOME/.cabal/bin
619
620 if [ -r /etc/alternatives/java_sdk ]; then
621 export JAVA_HOME=/etc/alternatives/java_sdk
622 path_add /etc/alternatives/java_sdk
623 fi
624 fi
625
626 export EDITOR="emacsclient"
627 # this makes emacsclient file/-c start a server instance if none is running,
628 # instead of some alternate editor logic
629 export ALTERNATE_EDITOR=""
630
631 # ubuntu starts gpg agent automatically with /etc/X11/Xsession.d/90gpg-agent.
632 # fedora doesn't, which left me to figure this out, and google was no help.
633 # fedora documentation is often quite bad :(
634 # This is mostly copied from that file.
635 # Main difference is that we eval the result of starting gpg-agent,
636 # while that file executes it through xsession specific var.
637 # Also make sourcing the pidfile make more sense.
638 # End result should be the same afaik.
639 # for gpg-agent to work when calling gpg from the command line,
640 # we need an environment variable that is setup via the eval.
641 # which is why we do this upon login, so it can propogate
642 # It is also written to the file $HOME/.gnupg/gpg-agent-info-$(hostname)
643 # I'm not aware if that is ever used, but just fyi.
644 # I also added the bit about xmessaging the stderr,
645 # because I'd like to know if the command fails
646 if [ -f /etc/fedora-release ]; then
647 : ${GNUPGHOME=$HOME/.gnupg}
648
649 GPGAGENT=/usr/bin/gpg-agent
650 PID_FILE="$GNUPGHOME/gpg-agent-info-$(hostname)"
651
652 if ! $GPGAGENT 2>/dev/null; then
653 temp="$(mktemp)"
654 eval "$($GPGAGENT --homedir /p/do-not-delete --daemon --sh --write-env-file=$PID_FILE 2>$temp)"
655 temperr="$(<"$temp")"
656 [ -n "$temperr" ] && xmessage "gpg-agent stderr: $temperr"
657 elif [ -r "$PID_FILE" ]; then
658 . "$PID_FILE"
659 export GPG_AGENT_INFO
660 fi
661 fi
662
663 # ubuntu has 002, debian has 022.
664 # from what I've read, benefit of 002 makes shared groups read/write.
665 # Security concern is where some unixes put everyone in a same group,
666 # so if you copy files there with exact perms, that is probably not
667 # what you want. I don't use a system like that, and I don't really care
668 # either way, but I'd prefer
669 # being able to sync file perms with ubuntu systems at work,
670 # and it's easier to change the debian one.
671
672 umask 002
673 EOF
674
675
676
677 postfix-setup
678
679 if isubuntu; then
680 # disable crash report annoying crap
681 s dd of=/etc/default/apport <<<'enabled=0'
682 fi
683
684 if has_x; then
685 if isarch; then
686 # install so it's build dependencies don't get removed.
687
688 # emacs git build is currently broken
689 if false; then
690 x=$(mktemp -d)
691 pushd $x
692 aurex emacs-git
693 makepkg -si --noconfirm
694 popd
695 rm -rf $x
696 else
697 pi emacs
698 fi
699 pi hunspell hunspell-en
700 else
701 # to disable emacs git build,
702 # s apt-get install emacs
703 if $recompile; then
704 /a/bin/buildscripts/emacs -u
705 else
706 /a/bin/buildscripts/emacs -r
707 fi
708 fi
709
710 # todo, figure this out for arch if we ever try out gnome.
711 if ! isarch; then
712 # install for multiple display managers in case we use one
713 if isdeb; then
714 dir=/etc/gdm3
715 elif isfedora; then
716 # fedora didn\'t have the 3.
717 dir=/etc/gdm
718 fi
719 s mkdir -p $dir/PostLogin
720 s command cp /a/bin/desktop-20-autostart.sh $dir/PostLogin/Default
721 s mkdir /etc/lightdm/lightdm.conf.d
722 s dd of=/etc/lightdm/lightdm.conf.d/12-ian.conf <<'EOF'
723 [SeatDefaults]
724 session-setup-script=/a/bin/desktop-20-autostart.sh
725 EOF
726 fi
727
728
729 pi ghc sakura
730 # todo, also note for work comp, scp opt/org-mode bin/build-scripts
731
732 # use the package manger version to install the cabal version
733 pi cabal-install
734 cabal update
735 PATH="$PATH:$HOME/.cabal/bin"
736
737 # todo, on older ubuntu I used cabal xmonad + xfce,
738 # see /a/bin/old-unused/xmonad-cabal.sh
739
740 # trying out the distros versions newer distros
741 pi xmonad
742 if isarch; then
743 # for displaying error messages.
744 # optional dependency in arch, standard elsewhere.
745 pi xorg-xmessage xmonad-contrib xorg-xsetroot xorg-xinit
746
747 # https://wiki.archlinux.org/index.php/Xinitrc
748 for homedir in /home/*; do
749 cp /etc/X11/xinit/xinitrc $homedir/.xinitrc
750 sed -ri '/^ *twm\b/,$d' $homedir/.xinitrc
751 echo "source /a/bin/xinitrc" | tee -a $homedir/.xinitrc
752 done
753 else
754 pi suckless-tools
755 fi
756 pi dmenu
757
758 if isdeb && (tp || x2); then
759 pi task-laptop
760 fi
761 fi
762
763 # the first pup command can kill off our /etc/
764 /a/bin/ssh-emacs-setup
765 echo "$0: $(date): ending now"