root linking not used, remove it
[distro-setup] / conflink
1 #!/bin/bash -l
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
5
6
7 sysv() {
8 e "$@"
9 "$@"
10 }
11
12
13 #
14 if [[ -e /root/.unison && ! -L /root/.unison ]]; then
15 d=/q/p/c/machine_specific/$host/.unison
16 mkdir -p $d
17 mv -f /root/.unison/* $d
18 fi
19
20
21 shopt -s nullglob
22 shopt -s extglob
23
24 # if we make a link back to the root, traversing the subdirs stops.
25 # This makes it so we can do subdir directories. Must call with absolute
26 # paths.
27
28 subdir-link-r() {
29 local root="$1"
30 local targets=()
31 if [[ $2 ]]; then
32 targets=( "$2"/!(.git) )
33 else
34 for f in "$1"/!(.git); do
35 [[ -d $f ]] && targets+=("$f") ||:
36 done
37 fi
38 local below="$( readlink -f "$root/..")"
39 for path in "${targets[@]}"; do
40 local fullpath="$(readlink -f "$path")"
41 #e $fullpath $below # debug
42 if [[ -f $path || $(dirname $(readlink -f "$fullpath")) == "$below" ]]; then
43 sysv lnf -T "$path" "$HOME/${path#$root/}"
44 elif [[ -d "$path" ]]; then
45 subdir-link-r "$root" "$path"
46 fi
47 done
48 }
49
50 common-file-setup() {
51 for dir in "$@"; do
52 if [[ -e $dir/subdir_files ]]; then
53 subdir-link-r $dir/subdir_files
54 fi
55 local x=( $dir/!(subdir_files|filesystem) )
56 (( ${#x[@]} >= 1 )) || return 0
57 sysv lnf ${x[@]} ~
58 # as of this writing, it doesn't exist in /a/c, but I've used it in the past.
59 if [[ -e $dir/filesystem && $USER == ian ]]; then
60 sysv s cp -R $dir/filesystem/* /
61 fi
62 done
63 }
64
65 link-dirs() {
66 for dir in "$@"; do
67 common-file-setup $dir
68 common-file-setup $dir/machine_specific/$HOSTNAME
69 done
70 }
71
72 all_dirs=({/a/c,/p/c}{,/machine_specific/$HOSTNAME})
73 c_dirs=(/a/c{,/machine_specific/$HOSTNAME})
74 case $USER in
75 ian)
76 # p needs to go first so .ssh link is created, then config link inside it
77 common-file-setup $dir ${all_dirs[@]}
78 sudo -u traci "$BASH_SOURCE"
79 ;;
80 traci)
81 common-file-setup ${c_dirs[@]}
82 ;;
83 *)
84 echo "$0: error: unexpected user"; exit 1
85 ;;
86 esac