aboutsummaryrefslogtreecommitdiffstats
path: root/apps/rellink
blob: 2981f3f178925bf93d908923324400a312217513 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

set -e

test $# = 2 || test $# = 3

target="$1"
link="$2"
destdir="$3"

test $(printf '%s\n' "$target" "$link" | grep '^/' | wc -l) = 2

T="$target"
L="$link"
while test $(printf '%s\n' "$T" "$L" | grep / | wc -l) = 2; do
	Td="$(printf '%s\n' "$T" | cut -d / -f 1)"
	Ld="$(printf '%s\n' "$L" | cut -d / -f 1)"
	if test ! "$Td" = "$Ld"; then
		break
	fi
	T="$(printf '%s\n' "$T" | cut -d / -f 2-)"
	L="$(printf '%s\n' "$L" | cut -d / -f 2-)"
done
while printf '%s\n' "$L" | grep / > /dev/null; do
	T="$(printf '../%s\n' "$T")"
	L="$(printf '%s\n' "$L" | cut -d / -f 2-)"
done
target="$T"

ln -s -- "$target" "$destdir$link"