]> git.ipfire.org Git - thirdparty/glibc.git/blame - rellns-sh
Update.
[thirdparty/glibc.git] / rellns-sh
CommitLineData
f0e44959
UD
1#! /bin/sh
2# rellns-sh - Simplified ln program to generate relative symbolic link.
2f6d1f1b 3# Copyright (C) 1996, 1997 Free Software Foundation, Inc.
f0e44959
UD
4# Written by Ulrich Drepper <drepper@cygnus.com>, October 1996
5#
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.
10#
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.
15#
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.
19
20if test $# -ne 2; then
68dbb3a6
UD
21 echo "Usage: rellns SOURCE DEST" >&2
22 exit 1
23fi
24
c131718c
UD
25# Make both paths absolute.
26if test -d $1; then
63551311 27 to=`cd $1 && /bin/pwd`
c131718c
UD
28else
29 temp=`echo $1 | sed 's%/*[^/]*$%%'`
b4012b75
UD
30 if test -z "$temp"; then
31 to=`/bin/pwd`
32 else
33 to=`cd $temp && /bin/pwd`
34 fi
c131718c
UD
35 to="$to/`echo $1 | sed 's%.*/\([^/][^/]*\)$%\1%'`"
36fi
37to=`echo $to | sed 's%^/%%'`
f0e44959 38
c131718c
UD
39if test -d $2; then
40 from=`echo $2 | sed 's%/*$%%'`
41else
42 from=`echo $2 | sed 's%/*[^/]*$%%'`
43fi
f0e44959 44
c131718c 45if test -z "$from"; then
63551311
UD
46 from=`/bin/pwd | sed 's%^/%%'`
47else
48 from=`cd $from && /bin/pwd | sed 's%^/%%'`
c131718c 49fi
f0e44959 50
68dbb3a6
UD
51while test -n "$to" && test -n "$from"; do
52 preto=`echo $to | sed 's%^\([^/]*\)/.*%\1%'`
53 prefrom=`echo $from | sed 's%^\([^/]*\)/.*%\1%'`
f0e44959 54
68dbb3a6 55 test "$preto" != "$prefrom" && break
f0e44959 56
68dbb3a6
UD
57 to=`echo $to | sed 's%^[^/]*/*\(.*\)$%\1%'`
58 from=`echo $from | sed 's%^[^/]*/*\(.*\)$%\1%'`
59done
f0e44959 60
68dbb3a6
UD
61while test -n "$from"; do
62 rfrom="../$rfrom"
63 from=`echo $from | sed 's%^[^/]*/*%%'`
64done
65
66ln -s $rfrom$to $2