X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=ian-dotfiles.git;a=blobdiff_plain;f=infra%2Fmakelinks;h=dd167d31a200fcda856a91e3568a4a79670c275c;hp=0fd38dccfdfd34f927fda7eb08e1d4e2de132d15;hb=86c57ffcf5ec23436745c1cc9edd7180be417ba5;hpb=4cc053b8edfcb949f583c4383243a283e36a61b0 diff --git a/infra/makelinks b/infra/makelinks index 0fd38dc..dd167d3 100755 --- a/infra/makelinks +++ b/infra/makelinks @@ -9,7 +9,7 @@ set -e -o posix -o pipefail badusage () { - echo >&2 "usage: $0 [-n|-v] list|setup|import|clean" + echo >&2 "usage: $0 [-n|-v] list|setup|dirimport|dirmove|clean" exit 18 } @@ -27,14 +27,12 @@ while true; do done case "$#.$1" in -1.list|1.setup|1.import|1.clean) ;; +1.list|1.setup|1.import|1.dirimport|1.clean) ;; *) badusage ;; esac mode=$1; shift -dots=$( find dot -type f -name '[0-9a-zA-Z]*[0-9a-zA-Z]' ) - basepath=$(pwd) basepath=${basepath#$HOME/} @@ -58,6 +56,7 @@ bad () { needs () { if [ $mode = $1 ]; then act=$real_act + show "DOING $1: $prhome ($2)" else show "needs $1: $prhome: $2" act=: @@ -73,33 +72,48 @@ with_log () { "$@" } +dots=$( find dot -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' ) + for dot in $dots; do + ours="$dot" underhome=".${dot#dot/}" 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" ] && cmp -s "$dot" "$inhome"; then - needs setup "identical here but not yet symlinked" - $act rm -f "$inhome"~ - $act ln -s "$basepath/$dot" "$inhome"~ - $act mv -f "$inhome"~ "$inhome" + elif [ -f "$inhome" ] && [ -f "$ours" ]; then + if cmp -s "$ours" "$inhome"; then + needs setup "identical here but not yet symlinked" + $act rm -f "$inhome"~ + $act ln -s "$linktarget" "$inhome"~ + $act mv -f "$inhome"~ "$inhome" + else + needs import "modified here" + $act rm -f "$ours"~ + $act cp "$inhome" "$ours"~ + $act mv -f "$ours"~ "$ours" + fi + elif [ -d "$inhome" ] && [ -d "$ours" ]; then + needs dirimport "directory here not yet symlinked" + $act mv "$ours" "$ours~" + $act ln -s "$linktarget" "$inhome"~ + $act mv "$inhome" "$ours" + $act mv "$inhome~" "$inhome" + $act rm -rf "$ours~" else - needs import "modified here" - $act rm -f "$dot"~ - $act cp "$inhome" "$dot"~ - $act mv -f "$dot"~ "$dot" + bad "mismatched file types" fi done brokens=$( cd $HOME - find -L .[0-9a-zA-Z]* -xdev -type l -lname "$basepath/dot/*" + find -L .[0-9a-zA-Z]* -maxdepth 0 -xdev -type l -lname "$basepath/dot/*" ) for underhome in $brokens; do inhome="$HOME/$underhome"