Commit 67c142b192db1779ddf4754a4240c8dd63f558fa

Thomas de Grivel 2019-10-06T17:25:35

fix skel

diff --git a/bin/rol-skel b/bin/rol-skel
index 250a051..a7c5af9 100755
--- a/bin/rol-skel
+++ b/bin/rol-skel
@@ -2,24 +2,45 @@
 
 set -e
 
-NAME="$1"
-
-mkdir -p "$NAME"
-cd "$NAME"
 DIR="$PWD"
+NAME="$1"
 
-cd "$(dirname "$0")/../../rol"
+cd "$(dirname "$0")"
+cd ..
 ROL_DIR="$PWD"
+cd skel
+ROL_SKEL_DIR="$PWD"
+
+mkdir -p "$DIR/$NAME"
+cd "$DIR/$NAME"
+DIR="$PWD"
 
 VARS=""
-VARS="$VARS -e s/@{NAME}/$NAME/g"
-VARS="$VARS -e s/@{ROL_DIR}/$ROL_DIR/g"
+VARS="$VARS -e s:@{NAME}:$NAME:g"
+VARS="$VARS -e s:@{ROL_DIR}:$ROL_DIR:g"
 
-cd "$(dirname "$0")/../skel"
+cd "$ROL_SKEL_DIR/skel"
 find | while read SKEL; do
     if [ -d "$SKEL" ]; then
         echo "D $SKEL"
-        mkdir "$DIR/$SKEL"
+        mkdir -p "$DIR/$SKEL"
     elif [ -f "$SKEL" ]; then
         echo "F $SKEL"
-        sed $VARS 
+        sed $VARS < "$SKEL" > "$DIR/$SKEL.tmp"
+        if [ -f "$DIR/$SKEL" ]; then
+            if cmp "$DIR/$SKEL.tmp" "$DIR/$SKEL"; then
+                rm "$DIR/$SKEL.tmp"
+            else
+                diff -u "$DIR/$SKEL" "$DIR/$SKEL.tmp"
+            fi
+        else
+            mv "$DIR/$SKEL.tmp" "$DIR/$SKEL"
+        fi
+    elif [ -h "$SKEL" ]; then
+        TARGET="$(readlink "$SKEL" | sed $VARS)"
+        echo "L $SKEL -> $TARGET"
+        ln -s "$TARGET" "$DIR/$SKEL"
+    else
+        echo "? $SKEL"
+    fi
+done
diff --git a/skel/lib/rol b/skel/lib/rol
index b51dadf..655c6b7 120000
--- a/skel/lib/rol
+++ b/skel/lib/rol
@@ -1 +1 @@
-@{ROL_PATH}
\ No newline at end of file
+@{ROL_DIR}
\ No newline at end of file