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