2019-04-27 22:09:36 +00:00
|
|
|
#! env zsh
|
2019-12-11 05:52:23 +00:00
|
|
|
# -*- sh -*-
|
|
|
|
|
2019-12-13 17:36:07 +00:00
|
|
|
REPORT="`dirname $0`/report"
|
2019-04-27 22:09:36 +00:00
|
|
|
|
|
|
|
if [ -z "$1" ] || [ -z "$2" ] ; then
|
2019-12-13 17:36:07 +00:00
|
|
|
"$REPORT" error "ERROR: Both to and from string must be defined.\n source: $1 \n symlnk: $2"
|
2019-12-13 19:31:35 +00:00
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -h $2 ]] ; then
|
|
|
|
link_location=$(readlink $2)
|
|
|
|
if [[ "$1" == "$link_location" ]] ; then
|
2020-03-09 17:30:45 +00:00
|
|
|
"$REPORT" pass "Symlink already installed $1"
|
2019-12-13 19:31:35 +00:00
|
|
|
exit 0
|
|
|
|
else
|
2020-03-09 17:30:45 +00:00
|
|
|
"$REPORT" warn "Symlink already exist, buut doesn't point to the src"
|
2019-12-13 19:31:35 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-04-27 22:09:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -e $2 ]] ; then
|
2019-12-13 19:31:35 +00:00
|
|
|
"$REPORT" warn "Something already exists at $2."
|
|
|
|
exit 1
|
2019-04-27 22:09:36 +00:00
|
|
|
fi
|
|
|
|
|
2019-12-13 17:36:07 +00:00
|
|
|
parent=$(dirname "$2")
|
|
|
|
if [[ ! -e $parent ]] ; then
|
|
|
|
"$REPORT" warn "$parent doesn't exist. Creating."
|
|
|
|
mkdir -p $parent
|
|
|
|
fi
|
|
|
|
|
2020-03-09 17:30:45 +00:00
|
|
|
"$REPORT" pass "Symlinked `ln -svf $1 $2`"
|