Update.
[glibc.git] / rellns-sh
blobabe758a9976e922aadf59c088a335ebe4b2ccbfc
1 #! /bin/sh
2 # rellns-sh - Simplified ln program to generate relative symbolic link.
3 # Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4 # Written by Ulrich Drepper <drepper@cygnus.com>, October 1996
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 if test $# -ne 2; then
21 echo "Usage: rellns SOURCE DEST" >&2
22 exit 1
25 case $1 in
26 /*)
27 # Make both paths absolute.
28 to=`echo $1 | sed 's%^/%%'`
30 if test -d $2; then
31 from=`echo $2 | sed 's%/*$%%'`
32 else
33 from=`echo $2 | sed 's%/*[^/]*$%%'`
36 case "$from" in
37 /*) from=`echo $from | sed 's%^/*%%'` ;;
38 ?*) from=`cd $from && pwd | sed 's%^/%%'` ;;
39 *) from=`pwd | sed 's%^/%%'` ;;
40 esac
43 to=$1
45 if test -d $2; then
46 from=`echo $2 | sed 's%/*$%%'`
47 else
48 from=`echo $2 | sed 's%/*[^/]*$%%'`
51 esac
53 while test -n "$to" && test -n "$from"; do
54 preto=`echo $to | sed 's%^\([^/]*\)/.*%\1%'`
55 prefrom=`echo $from | sed 's%^\([^/]*\)/.*%\1%'`
57 test "$preto" != "$prefrom" && break
59 to=`echo $to | sed 's%^[^/]*/*\(.*\)$%\1%'`
60 from=`echo $from | sed 's%^[^/]*/*\(.*\)$%\1%'`
61 done
63 while test -n "$from"; do
64 rfrom="../$rfrom"
65 from=`echo $from | sed 's%^[^/]*/*%%'`
66 done
68 ln -s $rfrom$to $2