chiark / gitweb /
Get link target right for subdirs
[ian-dotfiles.git] / infra / makelinks
index 6f4310782957039f5f0c026cbbc79db67451d2dd..46c901e9b0c0a3d17a62abac41802243d6e6e231 100755 (executable)
@@ -76,6 +76,18 @@ process_object () {
     inhome="$HOME/$underhome"
     prhome="~/$underhome"
     linktarget="$basepath/$ours"
     inhome="$HOME/$underhome"
     prhome="~/$underhome"
     linktarget="$basepath/$ours"
+    chompy="$underhome"
+    while true; do
+       case "$chompy" in
+        *?/?*)
+           linktarget="../$linktarget"
+           chompy="${chompy%/*}"
+           ;;
+       *)
+           break
+           ;;
+       esac
+    done
     if [ "$inhome" -ef "$ours" ]; then
        good "already symlinked here"
     elif [ -h "$inhome" ]; then
     if [ "$inhome" -ef "$ours" ]; then
        good "already symlinked here"
     elif [ -h "$inhome" ]; then
@@ -85,7 +97,7 @@ process_object () {
        $act ln -s "$linktarget" "$inhome"
     elif [ -f "$inhome" ] && [ -f "$ours" ]; then
        if cmp -s "$ours" "$inhome"; then
        $act ln -s "$linktarget" "$inhome"
     elif [ -f "$inhome" ] && [ -f "$ours" ]; then
        if cmp -s "$ours" "$inhome"; then
-           needs setup "identical here but not yet symlinked"
+           needs setup "identical in this ~ but not yet symlinked"
            $act rm -f "$inhome"~
            $act ln -s "$linktarget" "$inhome"~
            $act mv -f "$inhome"~ "$inhome"
            $act rm -f "$inhome"~
            $act ln -s "$linktarget" "$inhome"~
            $act mv -f "$inhome"~ "$inhome"
@@ -96,7 +108,7 @@ process_object () {
            $act mv -f "$ours"~ "$ours"
        fi
     elif [ -d "$inhome" ] && [ -d "$ours" ]; then
            $act mv -f "$ours"~ "$ours"
        fi
     elif [ -d "$inhome" ] && [ -d "$ours" ]; then
-       needs dirimport "directory here not yet symlinked"
+       needs dirimport "directory in this ~, not yet symlinked"
        $act mv "$ours" "$ours~"
        $act ln -s "$linktarget" "$inhome"~
        $act mv "$inhome" "$ours"
        $act mv "$ours" "$ours~"
        $act ln -s "$linktarget" "$inhome"~
        $act mv "$inhome" "$ours"
@@ -109,15 +121,47 @@ process_object () {
 
 dots=$( find dot -mindepth 1 -maxdepth 1 -name '[0-9a-zA-Z]*[0-9a-zA-Z]' )
 
 
 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/}"
+for ours in $dots; do
+    underhome=".${ours#dot/}"
     process_object
 done
 
     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
+
+exec 3<correspondences
+while read <&3 ours underhome; do
+    case "$ours" in
+    ''|'#'*) ;;
+    *)
+       case "$underhome" in
+       */*)
+           parent=${underhome%/*}
+           punderhome="$HOME/$parent"
+           prhome="~/${underhome%/*}"
+           if [ -d "$punderhome" ]; then
+               good "directory exists"
+           elif ! [ -e "$punderhome" ]; then
+               needs setup "directory does not exist"
+               $act mkdir -p "$punderhome"
+           else
+               bad "ought to be director but isn't"
+           fi
+           ;;
+       esac
+       process_object
+       ;;
+    esac
+done
+
 brokens=$(
     cd $HOME
 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"
 )
 for underhome in $brokens; do
     inhome="$HOME/$underhome"