]>
Commit | Line | Data |
---|---|---|
f0e44959 UD |
1 | #! /bin/sh |
2 | # rellns-sh - Simplified ln program to generate relative symbolic link. | |
3 | # Copyright (C) 1996 Free Software Foundation, Inc. | |
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 | ||
20 | if test $# -ne 2; then | |
68dbb3a6 UD |
21 | echo "Usage: rellns SOURCE DEST" >&2 |
22 | exit 1 | |
23 | fi | |
24 | ||
c84142e8 UD |
25 | # We only handle the case where SOURCE is the name of an existing file |
26 | if test ! -f $1; then | |
27 | echo "rellns: $1 must name an existing file" >&2 | |
28 | exit 1 | |
29 | fi | |
30 | ||
f0e44959 UD |
31 | case $1 in |
32 | /*) | |
33 | # Make both paths absolute. | |
34 | to=`echo $1 | sed 's%^/%%'` | |
35 | ||
36 | if test -d $2; then | |
8a523922 | 37 | from=`echo $2 | sed 's%/*$%%'` |
f0e44959 | 38 | else |
8a523922 | 39 | from=`echo $2 | sed 's%/*[^/]*$%%'` |
f0e44959 UD |
40 | fi |
41 | ||
8a523922 UD |
42 | case "$from" in |
43 | /*) from=`echo $from | sed 's%^/*%%'` ;; | |
f0e44959 UD |
44 | ?*) from=`cd $from && pwd | sed 's%^/%%'` ;; |
45 | *) from=`pwd | sed 's%^/%%'` ;; | |
46 | esac | |
68dbb3a6 UD |
47 | ;; |
48 | *) | |
49 | to=$1 | |
f0e44959 | 50 | |
68dbb3a6 UD |
51 | if test -d $2; then |
52 | from=`echo $2 | sed 's%/*$%%'` | |
53 | else | |
54 | from=`echo $2 | sed 's%/*[^/]*$%%'` | |
55 | fi | |
56 | ;; | |
57 | esac | |
f0e44959 | 58 | |
68dbb3a6 UD |
59 | while test -n "$to" && test -n "$from"; do |
60 | preto=`echo $to | sed 's%^\([^/]*\)/.*%\1%'` | |
61 | prefrom=`echo $from | sed 's%^\([^/]*\)/.*%\1%'` | |
f0e44959 | 62 | |
68dbb3a6 | 63 | test "$preto" != "$prefrom" && break |
f0e44959 | 64 | |
68dbb3a6 UD |
65 | to=`echo $to | sed 's%^[^/]*/*\(.*\)$%\1%'` |
66 | from=`echo $from | sed 's%^[^/]*/*\(.*\)$%\1%'` | |
67 | done | |
f0e44959 | 68 | |
68dbb3a6 UD |
69 | while test -n "$from"; do |
70 | rfrom="../$rfrom" | |
71 | from=`echo $from | sed 's%^[^/]*/*%%'` | |
72 | done | |
73 | ||
74 | ln -s $rfrom$to $2 |