From dc9cf986307ee673850838d5bbcf9e5774bda2c3 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sat, 7 May 2016 14:52:17 -0700 Subject: [PATCH] working --- conflink | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 conflink diff --git a/conflink b/conflink new file mode 100755 index 0000000..ddf9901 --- /dev/null +++ b/conflink @@ -0,0 +1,64 @@ +#!/bin/bash -l + +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR + + +sysv() { + e "$@" + "$@" +} + + +shopt -s nullglob + +# if we make a link back to the root, traversing the subdirs stops. +# This makes it so we can do subdir directories. Must call with absolute +# paths. + +subdir-link-r() { + local root="$1" + local targets=() + if [[ $2 ]]; then + targets=( "$2"/* ) + else + for f in "$1"/*; do + [[ -d $f ]] && targets+=("$f") ||: + done + fi + local below="$( readlink -f "$root/..")" + for path in "${targets[@]}"; do + local fullpath="$(readlink -f "$path")" + #e $fullpath $below # debug + if [[ -f $path || $(dirname $(readlink -f "$fullpath")) == "$below" ]]; then + if [[ $dir == /p/* ]]; then + homes=(/home/ian) + else + homes=(/home/*) + fi + for user in ${homes[@]}; do + sysv lnf -T "$path" "$user/${path#$root/}" + done + elif [[ -d "$path" ]]; then + subdir-link-r "$root" "$path" + fi + done +} + +common-file-setup() { + if [[ -e $1/subdir_files ]]; then + subdir-link-r $1/subdir_files + fi + local x=( $1/!(subdir_files|filesystem) ) + (( ${#x[@]} >= 1 )) || return 0 + sysv lnf ${x[@]} ~ + # as of this writing, it doesn't exist in /a/c, but I've used it in the past. + if [[ -e $1/filesystem ]]; then + sysv s cp -R $1/filesystem/* / + fi +} + +# p needs to go first so .ssh link is created, then config link inside it +for dir in {/a/c,/p/c}{,/machine_specific/$HOSTNAME}; do + common-file-setup $dir +done -- 2.30.2