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