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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#! /bin/bash
# create a symlink, idempotent
#
# (c) Thomas Lange 2019, lange@debian.org
#
# if $target is defined, create link relative to $target
mk-link() {
local from=$1
local to=$2
local oldto
local vopt
if [ X$verbose = X1 ]; then
vopt=-v
fi
# todo: check if $from starts with a slash
if [ -n "$target" ]; then
from="$target$from"
fi
if [ ! -e $from ] && [ ! -h $from ]; then
ln -s $vopt $to $from
return
fi
# check if already same link
if [ -h $from ]; then
oldto=$(readlink $from)
if [ $oldto = $to ]; then
if [ X$verbose = X1 ]; then
printf "fai-link: Nothing to do for link $from -> $to\n"
fi
return
fi
fi
# if different create new link
ln -sf $vopt $to $from
}
# make link from to
mk-link $1 $2
|