dotfiles/lib/helper/mk_link

34 lines
722 B
Plaintext
Raw Normal View History

#! env zsh
2019-12-11 05:52:23 +00:00
# -*- sh -*-
REPORT="`dirname $0`/report"
if [ -z "$1" ] || [ -z "$2" ] ; then
"$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
"$REPORT" pass "Symlink already installed $1"
2019-12-13 19:31:35 +00:00
exit 0
else
"$REPORT" warn "Symlink already exist, buut doesn't point to the src"
2019-12-13 19:31:35 +00:00
exit 1
fi
fi
if [[ -e $2 ]] ; then
2019-12-13 19:31:35 +00:00
"$REPORT" warn "Something already exists at $2."
exit 1
fi
parent=$(dirname "$2")
if [[ ! -e $parent ]] ; then
"$REPORT" warn "$parent doesn't exist. Creating."
mkdir -p $parent
fi
"$REPORT" pass "Symlinked `ln -svf $1 $2`"