Home | History | Annotate | Download | only in util
      1 #!/bin/sh
      2 #
      3 # install-symlink source destination destdir
      4 #
      5 
      6 SYMLINKS=symlinks
      7 LN_S="@LN_S@"
      8 RM="@RM@"
      9 FORCE_RELATIVE=NO
     10 FORCE_ABSOLUTE=NO
     11 
     12 while echo $1 | grep -q -- ^- ;
     13 do
     14 	case $1 in
     15 		--relative)
     16 			FORCE_RELATIVE=YES
     17 			;;
     18 		--absolute)
     19 			FORCE_ABSOLUTE=YES
     20 			;;
     21 		--debian)
     22 			FORCE_ABSOLUTE=NO
     23 			FORCE_RELATIVE=NO
     24 			;;
     25 		--symlinks=*)
     26 			SYMLINKS=$(echo $1 | sed -e 's/--symlinks=//')
     27 			;;
     28 		*)
     29 			echo "Unknown option $1"
     30 			exit 1
     31 			;;
     32 	esac					     
     33 	shift;
     34 done
     35 
     36 
     37 FIX_SYMLINK="$SYMLINKS -c"
     38 
     39 SRC="$1"
     40 DEST="$2"
     41 DESTDIR="$3"
     42 
     43 if ! echo $SRC | grep -q ^/ ; then
     44 	echo $SRC: Source pathname must be absolute
     45 	exit 1
     46 fi
     47 
     48 if ! echo $DEST | grep -q ^/ ; then
     49 	echo $DEST: Destination pathname must be absolute
     50 	exit 1
     51 fi
     52 
     53 if ! test -e "$DESTDIR$SRC" ; then
     54 	echo $DESTDIR$SRC: file or directory does not exist
     55 	exit 1
     56 fi
     57 
     58 $RM -f "$DESTDIR$DEST"
     59 
     60 if test "$LN_S" != "ln -s" ; then
     61 	$LN_S "$DESTDIR$SRC" "$DESTDIR$DEST"
     62 	exit 0
     63 fi
     64 
     65 if test $(dirname "$SRC") = $(dirname "$DEST") ; then
     66 	$LN_S "$(basename "$SRC")" "$DESTDIR$DEST"
     67 	exit 0
     68 fi
     69 
     70 TOP_SRC=$(echo $SRC | awk -F/ '{print $2}')
     71 TOP_DEST=$(echo $DEST | awk -F/ '{print $2}')
     72 
     73 if test $FORCE_RELATIVE = YES ; then
     74 	TOP_SRC=FORCE
     75 	TOP_DEST=FORCE
     76 fi
     77 
     78 if test $FORCE_ABSOLUTE = YES ; then
     79 	TOP_SRC=FORCE
     80 	TOP_DEST=FORCE_ABSOLUTE
     81 fi
     82 
     83 if test $TOP_SRC != $TOP_DEST ; then
     84 	$LN_S "$SRC" "$DESTDIR$DEST"
     85 else
     86 	$LN_S "$DESTDIR$SRC" "$DESTDIR$DEST"
     87 	$FIX_SYMLINK "$DESTDIR$DEST"
     88 fi
     89 
     90