|
Packit |
6c4009 |
#!/bin/sh
|
|
Packit |
6c4009 |
# rellns-sh - Simplified ln program to generate relative symbolic link.
|
|
Packit |
6c4009 |
# Copyright (C) 1996-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
# Written by Ulrich Drepper <drepper@cygnus.com>, October 1996
|
|
Packit |
6c4009 |
#
|
|
Packit |
6c4009 |
# This program is free software; you can redistribute it and/or modify
|
|
Packit |
6c4009 |
# it under the terms of the GNU General Public License as published by
|
|
Packit |
6c4009 |
# the Free Software Foundation; either version 2, or (at your option)
|
|
Packit |
6c4009 |
# any later version.
|
|
Packit |
6c4009 |
#
|
|
Packit |
6c4009 |
# This program is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
6c4009 |
# GNU General Public License for more details.
|
|
Packit |
6c4009 |
#
|
|
Packit |
6c4009 |
# You should have received a copy of the GNU General Public License
|
|
Packit |
6c4009 |
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# With -p, instead of creating the link print the computed relative link
|
|
Packit |
6c4009 |
# name.
|
|
Packit |
6c4009 |
do_print=false
|
|
Packit |
6c4009 |
case $1 in
|
|
Packit |
6c4009 |
-p)
|
|
Packit |
6c4009 |
do_print=true
|
|
Packit |
6c4009 |
shift
|
|
Packit |
6c4009 |
;;
|
|
Packit |
6c4009 |
esac
|
|
Packit |
6c4009 |
if test $# -ne 2; then
|
|
Packit |
6c4009 |
echo "Usage: rellns [-p] SOURCE DEST" >&2
|
|
Packit |
6c4009 |
exit 1
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Make both paths absolute.
|
|
Packit |
6c4009 |
if test -d $1; then
|
|
Packit |
6c4009 |
to=`cd $1 && pwd -P`
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
temp=`echo $1 | sed 's%/*[^/]*$%%'`
|
|
Packit |
6c4009 |
if test -z "$temp"; then
|
|
Packit |
6c4009 |
to=`pwd -P`
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
to=`cd $temp && pwd -P`
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
to="$to/`echo $1 | sed 's%.*/\([^/][^/]*\)$%\1%'`"
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
to=`echo $to | sed 's%^/%%'`
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if test -d $2; then
|
|
Packit |
6c4009 |
from=`echo $2 | sed 's%/*$%%'`
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
from=`echo $2 | sed 's%/*[^/]*$%%'`
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if test -z "$from"; then
|
|
Packit |
6c4009 |
from=`pwd -P | sed 's%^/%%'`
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
from=`cd $from && pwd -P | sed 's%^/%%'`
|
|
Packit |
6c4009 |
fi
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
while test -n "$to" && test -n "$from"; do
|
|
Packit |
6c4009 |
preto=`echo $to | sed 's%^\([^/]*\)/.*%\1%'`
|
|
Packit |
6c4009 |
prefrom=`echo $from | sed 's%^\([^/]*\)/.*%\1%'`
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
test "$preto" != "$prefrom" && break
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
to=`echo $to | sed 's%^[^/]*/*\(.*\)$%\1%'`
|
|
Packit |
6c4009 |
from=`echo $from | sed 's%^[^/]*/*\(.*\)$%\1%'`
|
|
Packit |
6c4009 |
done
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
while test -n "$from"; do
|
|
Packit |
6c4009 |
rfrom="../$rfrom"
|
|
Packit |
6c4009 |
from=`echo $from | sed 's%^[^/]*/*%%'`
|
|
Packit |
6c4009 |
done
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if $do_print; then
|
|
Packit |
6c4009 |
echo "$rfrom$to"
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
ln -s $rfrom$to $2
|
|
Packit |
6c4009 |
fi
|