remove kinsis / unused input settings
[distro-setup] / conflink
1 #!/bin/bash
2
3 source /a/bin/errhandle/errcatch-function
4 source /a/bin/errhandle/bash-trace-function
5
6 errcatch
7
8 m() {
9 echo "$*"
10 "$@"
11 }
12 s() { sudo "$@"; }
13 lnf() { /a/exe/lnf "$@"; }
14
15
16 shopt -s nullglob
17 shopt -s extglob # note, already set with bash -l
18
19 # If we make a link back to the root, we stop going deeper into subdir_files.
20 # This makes it so we can do subdir directories.
21 #
22 # Also note, under filesystem/, symlinks are expanded.
23
24 subdir-link-r() {
25 local root="$1"
26 local targets=()
27 if [[ $2 ]]; then
28 targets=( "$2"/!(.git|..|.) )
29 else
30 for f in "$1"/!(.git|..|.); do
31 [[ -d $f ]] && targets+=("$f") ||:
32 done
33 fi
34 local below="$( readlink -f "$root/..")"
35 for path in "${targets[@]}"; do
36 local fullpath="$(readlink -f "$path")"
37 #e $fullpath $below # debug
38 if [[ -f $path || $(dirname $(readlink -f "$fullpath")) == "$below" ]]; then
39 m lnf -T "$path" "$HOME/${path#$root/}"
40 elif [[ -d "$path" ]]; then
41 subdir-link-r "$root" "$path"
42 fi
43 done
44 }
45
46
47
48 common-file-setup() {
49 local dir fs x bdir f dst
50 for dir in "$@"; do
51 fs=$dir/filesystem
52 if [[ -e $fs && $USER =~ ^iank?$ ]]; then
53 # note, symlinks get resolved, not copied.
54 s tar --mode=g-s --owner=0 --group=0 -cz -C $fs . | s tar -xz -C /
55 fi
56
57 if [[ -e $dir/subdir_files ]]; then
58 m subdir-link-r $dir/subdir_files
59 fi
60 local x=( $dir/!(binds|subdir_files|filesystem|machine_specific|..|.) )
61 (( ${#x[@]} >= 1 )) || continue
62 m lnf ${x[@]} ~
63 done
64 }
65
66 all_dirs=({/a/c,/p/c}{,/machine_specific/$HOSTNAME})
67 # note, we assume a group of hosts does not have the
68 # same name as a single host, which is no problem on our scale.
69 for x in /p/c/machine_specific/*.hosts; do
70 if grep -qxF $HOSTNAME $x; then all_dirs+=( ${x%.hosts} ); fi
71 done
72
73 c_dirs=(/a/c{,/machine_specific/$HOSTNAME})
74 case $USER in
75 ian|iank)
76 # p needs to go first so .ssh link is created, then config link inside it
77 m common-file-setup ${all_dirs[@]}
78
79 #### begin special extra stuff ####
80 install -d -m700 ~/gpg-agent-socket
81 if [[ -d /etc/bind/bind-writable ]]; then
82 # need bind writable dir for nsupdate, or else we get
83 # named[20823]: /etc/bind/db.iank.pw.jnl: create: permission denied
84 m s chgrp bind /etc/bind/bind-writable
85 fi
86 files=(/etc/bind/[Kk]*)
87 if [[ -e $files ]]; then
88 m s chgrp bind ${files[@]}
89 fi
90 if [[ -e /etc/davpass ]] && getent group www-data &>/dev/null; then
91 s chgrp www-data /etc/davpass
92 fi
93 ##### end special extra stuff #####
94
95
96
97 m sudo -H -u traci "$BASH_SOURCE"
98 ;;
99 traci)
100 m common-file-setup ${c_dirs[@]}
101 ;;
102 *)
103 echo "$0: error: unexpected user"; exit 1
104 ;;
105 esac