From 37e0f4a3e376d02c600e0f29d3e9895926b2b149 Mon Sep 17 00:00:00 2001 From: Nico Dietrich Date: Tue, 25 Apr 2006 19:22:23 +0000 Subject: Both scripts can now be called by nested symlinks git-svn-id: http://svn.openslx.org/svn/openslx/ld4@195 95ad53e4-c205-0410-b2fa-d234c58c8868 --- initrd/mkdxsinitrd | 32 ++++++++++++++++++-------------- installer/ld4-inst | 33 ++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/initrd/mkdxsinitrd b/initrd/mkdxsinitrd index 815298e0..6cdfb30b 100755 --- a/initrd/mkdxsinitrd +++ b/initrd/mkdxsinitrd @@ -161,33 +161,37 @@ copy_distro_stuff() { } # This function makes the directory of this script to the present working directory -# Does also work when called by a link. FIXME: Breaks when called by a link to a link +# It is called within precheck() +# Does also work when called by symbolic links (even for nested links). goto_script_dir() { [ $DEBUG -ge 2 ] && echo "Aufgerufen wurde $0, checking if it is a link" calleddetails=`ls -l $0` # get the file flags (e.g. lrwxrwxrwx) [ $DEBUG -ge 2 ] && echo $calleddetails - index=`expr index "$calleddetails" "l"` - + calleddir=${0%/*} # Strip the filename from path [ $DEBUG -ge 2 ] && echo "Wechsele ins Verzeichnis des aufgerufenen scripts/links ($calleddir)" cd $calleddir + + while index=`expr index "$calleddetails" "l"`; + [ $index -eq 1 ]; do - - if [ $index -eq 1 ]; then [ $DEBUG -ge 2 ] && echo "It is a link" - - script=`echo $calleddetails | awk '{print $NF}'` - [ $DEBUG -ge 2 ] && echo "The script is: $script" - hasslash=`expr index "$script" "/"` + target=`echo $calleddetails | awk '{print $NF}'` + [ $DEBUG -ge 2 ] && echo "The target of the link is: $target" + hasslash=`expr index "$target" "/"` if [ $hasslash -ne 0 ]; then - scriptdir=${script%/*} - [ $DEBUG -ge 2 ] && echo "Following link to $scriptdir" - cd $scriptdir + targetpath=${target%/*} # extract the pathname + [ $DEBUG -ge 2 ] && echo "Following link to $targetpath" + cd $targetpath else - [ $DEBUG -ge 2 ] && echo "It is in the same directory as the link" + [ $DEBUG -ge 2 ] && echo "It is in the same directory as the link" fi - fi + targetfile=`basename $target` + [ $DEBUG -ge 2 ] && echo "The target file of the link is: $targetfile" + calleddetails=`ls -l $targetfile` # get the file flags (e.g. lrwxrwxrwx) + [ $DEBUG -ge 2 ] && echo $calleddetails + done [ $DEBUG -ge 2 ] && pwd } diff --git a/installer/ld4-inst b/installer/ld4-inst index e30334f8..37e2a36d 100755 --- a/installer/ld4-inst +++ b/installer/ld4-inst @@ -9,7 +9,7 @@ # Copyright: (c) 2003, 2006 - RZ Universitaet Freiburg # # Version: 0.2.0d -DEBUG=2 +DEBUG=0 header() { echo @@ -19,33 +19,36 @@ header() { # This function makes the directory of this script to the present working directory # It is called within precheck() -# Does also work when called by a link. FIXME: Breaks when called by a link to a link +# Does also work when called by a symbolic link. Even works for nested links. goto_script_dir() { [ $DEBUG -ge 2 ] && echo "Aufgerufen wurde $0, checking if it is a link" calleddetails=`ls -l $0` # get the file flags (e.g. lrwxrwxrwx) [ $DEBUG -ge 2 ] && echo $calleddetails - index=`expr index "$calleddetails" "l"` - + calleddir=${0%/*} # Strip the filename from path [ $DEBUG -ge 2 ] && echo "Wechsele ins Verzeichnis des aufgerufenen scripts/links ($calleddir)" cd $calleddir + + while index=`expr index "$calleddetails" "l"`; + [ $index -eq 1 ]; do - - if [ $index -eq 1 ]; then [ $DEBUG -ge 2 ] && echo "It is a link" - - script=`echo $calleddetails | awk '{print $NF}'` - [ $DEBUG -ge 2 ] && echo "The script is: $script" - hasslash=`expr index "$script" "/"` + target=`echo $calleddetails | awk '{print $NF}'` + [ $DEBUG -ge 2 ] && echo "The target of the link is: $target" + hasslash=`expr index "$target" "/"` if [ $hasslash -ne 0 ]; then - scriptdir=${script%/*} - [ $DEBUG -ge 2 ] && echo "Following link to $scriptdir" - cd $scriptdir + targetpath=${target%/*} # extract the pathname + [ $DEBUG -ge 2 ] && echo "Following link to $targetpath" + cd $targetpath else - [ $DEBUG -ge 2 ] && echo "It is in the same directory as the link" + [ $DEBUG -ge 2 ] && echo "It is in the same directory as the link" fi - fi + targetfile=`basename $target` + [ $DEBUG -ge 2 ] && echo "The target file of the link is: $targetfile" + calleddetails=`ls -l $targetfile` # get the file flags (e.g. lrwxrwxrwx) + [ $DEBUG -ge 2 ] && echo $calleddetails + done [ $DEBUG -ge 2 ] && pwd } -- cgit v1.2.3-55-g7522