X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=infra%2Fmakelinks;h=20faafc592912d757c74acf5b4de56e381d45e2e;hb=d0c1c94d3fe906d51f7fcb563e60b369f3481ab4;hp=55de7a63e92f6160f3da57762dcb7aca8b64ab8f;hpb=51499ec4fac3fbb4ffd51b8af774ba39851bc84e;p=ian-dotfiles.git diff --git a/infra/makelinks b/infra/makelinks index 55de7a6..20faafc 100755 --- a/infra/makelinks +++ b/infra/makelinks @@ -33,8 +33,6 @@ esac mode=$1; shift -dots=$( find dot -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' ) - basepath=$(pwd) basepath=${basepath#$HOME/} @@ -46,18 +44,19 @@ show () { good () { if [ $mode = list ]; then - show "good: $dot: $1" + show "good: $prhome: $1" fi } bad () { estatus=16 - show "bad: $dot: $1" >&2 + show "bad: $prhome: $1" >&2 } needs () { if [ $mode = $1 ]; then act=$real_act + show "DOING $1: $prhome ($2)" else show "needs $1: $prhome: $2" act=: @@ -73,44 +72,59 @@ with_log () { "$@" } -for dot in $dots; do - underhome=".${dot#dot/}" +process_object () { inhome="$HOME/$underhome" prhome="~/$underhome" - if [ "$inhome" -ef "$dot" ]; then + linktarget="$basepath/$ours" + if [ "$inhome" -ef "$ours" ]; then good "already symlinked here" elif [ -h "$inhome" ]; then bad "wrong symlink target" elif ! [ -e "$inhome" ]; then needs setup "absent here" - $act ln -s "$basepath/$dot" "$inhome" - elif [ -f "$inhome" ] && [ -f "$dot" ]; then - if cmp -s "$dot" "$inhome"; then - needs setup "identical here but not yet symlinked" + $act ln -s "$linktarget" "$inhome" + elif [ -f "$inhome" ] && [ -f "$ours" ]; then + if cmp -s "$ours" "$inhome"; then + needs setup "identical in this ~ but not yet symlinked" $act rm -f "$inhome"~ - $act ln -s "$basepath/$dot" "$inhome"~ + $act ln -s "$linktarget" "$inhome"~ $act mv -f "$inhome"~ "$inhome" else needs import "modified here" - $act rm -f "$dot"~ - $act cp "$inhome" "$dot"~ - $act mv -f "$dot"~ "$dot" + $act rm -f "$ours"~ + $act cp "$inhome" "$ours"~ + $act mv -f "$ours"~ "$ours" fi - elif [ -d "$inhome" ] && [ -d "$dot" ]; then - needs dirimport "directory here not yet symlinked" - $act mv "$dot" "$dot~" - $act ln -s "$basepath/$dot" "$inhome"~ - $act mv "$inhome" "$dot" + elif [ -d "$inhome" ] && [ -d "$ours" ]; then + needs dirimport "directory in this ~, not yet symlinked" + $act mv "$ours" "$ours~" + $act ln -s "$linktarget" "$inhome"~ + $act mv "$inhome" "$ours" $act mv "$inhome~" "$inhome" - $act rm -rf "$dot~" + $act rm -rf "$ours~" else bad "mismatched file types" fi +} + +dots=$( find dot -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' ) + +for ours in $dots; do + underhome=".${ours#dot/}" + process_object +done + +nondots=$( find home -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' ) + +for ours in $nondots; do + underhome="${ours#home/}" + process_object done brokens=$( cd $HOME - find -L .[0-9a-zA-Z]* -maxdepth 0 -xdev -type l -lname "$basepath/dot/*" + find -L .[0-9a-zA-Z]* -maxdepth 0 -xdev -type l \ + \( -lname "$basepath/dot/*" -o -lname "$basepath/home/*" \) ) for underhome in $brokens; do inhome="$HOME/$underhome"