#! /bin/sh prog=`basename $0` x=`echo 'x\c'` if [ "$x" = x ] ; then X1= ; X2='\c' ; else X1='-n' ; X2= ; fi usage() { cat</dev/null 2>&1 test $? || { echo "Temp file $tmpfile already exists!" ls -l $tmpfile echo "No links made." exit } trap "/bin/rm -f $tmpfile" 0 cd $realrootdir is_ok=1 exec 3>$tmpfile for subdir in `find "$@" -type d -print` ; do path="$linkrootdir/$subdir" test -f "$path" && { echo "$path" >&3 echo "$path exists, and is supposed to be a directory, but it's not." } done # b) Check for links that already exist. cd $realrootdir find "$@" ! -type d -print | while read file ; do from="$linkrootdir/$file" test -f "$from" && { echo "$from" >&3 echo "$from exists, but is supposed to be a new symlink." } done exec 3>&- case `wc -l $tmpfile | awk '{print $1}'` in 0 ) action=none ;; * ) ans="" while case "$ans" in [qQ]* ) echo "No links made." ; exit 0 ;; [dD]* ) action=delete ; ok=1;; [rR]* ) action=rename ; ok=1;; * ) ok=0 ;; esac test $ok = 0 do echo $X1 "(q)uit, (d)elete the above, (r)ename them to *.bak: $X2" read ans done ;; esac # Create missing subdirectories cd $realrootdir for subdir in `find "$@" -type d -print` ; do path="$linkrootdir/$subdir" test -f "$path" && { case $action in delete ) echo "Deleting old $path" ; rm -f "$path" ;; rename ) echo "Renaming old $path to $path.bak" ; mv "$path" "$path.bak" ;; esac } test -d "$path" || { echo "Creating $path" ; echo mkdir "$path" ; } done # Create links cd $realrootdir find "$@" ! -type d -print | while read file ; do linkfrom="$linkrootdir/$file" test -f "$linkfrom" && { case $action in delete ) echo "Deleting old $linkfrom" ; rm -f "$linkfrom" ;; rename ) echo "Renaming old $linkfrom to $linkfrom.bak" ; mv "$linkfrom" "$linkfrom.bak" ;; esac } echo ln -s "$realrootdir/$file" "$linkfrom" ln -s "$realrootdir/$file" "$linkfrom" done