ignore .git in subdir linking
[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 shopt -s nullglob
14 shopt -s extglob
15
16 # if we make a link back to the root, traversing the subdirs stops.
17 # This makes it so we can do subdir directories. Must call with absolute
18 # paths.
19
20 subdir-link-r() {
21 local root="$1"
22 local targets=()
23 if [[ $2 ]]; then
24 targets=( "$2"/!(.git) )
25 else
26 for f in "$1"/!(.git); do
27 [[ -d $f ]] && targets+=("$f") ||:
28 done
29 fi
30 local below="$( readlink -f "$root/..")"
31 for path in "${targets[@]}"; do
32 local fullpath="$(readlink -f "$path")"
33 #e $fullpath $below # debug
34 if [[ -f $path || $(dirname $(readlink -f "$fullpath")) == "$below" ]]; then
35 if [[ $dir == /p/* ]]; then
36 homes=(/home/ian)
37 else
38 homes=(/home/*)
39 fi
40 for user in ${homes[@]}; do
41 sysv lnf -T "$path" "$user/${path#$root/}"
42 done
43 elif [[ -d "$path" ]]; then
44 subdir-link-r "$root" "$path"
45 fi
46 done
47 }
48
49 common-file-setup() {
50 if [[ -e $1/subdir_files ]]; then
51 subdir-link-r $1/subdir_files
52 fi
53 local x=( $1/!(subdir_files|filesystem) )
54 (( ${#x[@]} >= 1 )) || return 0
55 sysv lnf ${x[@]} ~
56 # as of this writing, it doesn't exist in /a/c, but I've used it in the past.
57 if [[ -e $1/filesystem ]]; then
58 sysv s cp -R $1/filesystem/* /
59 fi
60 }
61
62 # p needs to go first so .ssh link is created, then config link inside it
63 for dir in {/a/c,/p/c}{,/machine_specific/$HOSTNAME}; do
64 common-file-setup $dir
65 done