2011-03-15 19:37:23 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2012-11-07 17:01:30 +00:00
|
|
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
2013-09-18 08:40:29 +00:00
|
|
|
# 2013 Steven Armstrong (steven-cdist at armstrong.cc)
|
2011-03-15 19:37:23 +00:00
|
|
|
#
|
|
|
|
# This file is part of cdist.
|
|
|
|
#
|
|
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# cdist is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
2011-03-19 22:44:25 +00:00
|
|
|
# Mostly a wrapper for ln
|
2011-03-15 19:37:23 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
destination="/$__object_id"
|
|
|
|
|
|
|
|
type="$(cat "$__object/parameter/type")"
|
|
|
|
source="$(cat "$__object/parameter/source")"
|
|
|
|
|
|
|
|
case "$type" in
|
2012-11-07 17:01:30 +00:00
|
|
|
symbolic)
|
|
|
|
lnopt="-s"
|
|
|
|
;;
|
|
|
|
hard)
|
|
|
|
lnopt=""
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown link type: $type" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2011-03-15 19:37:23 +00:00
|
|
|
esac
|
|
|
|
|
2012-02-06 20:08:59 +00:00
|
|
|
state_is="$(cat "$__object/explorer/state")"
|
2013-09-18 08:40:29 +00:00
|
|
|
state_should="$(cat "$__object/parameter/state")"
|
2012-02-06 20:08:59 +00:00
|
|
|
|
2012-11-07 17:01:30 +00:00
|
|
|
[ "$state_should" = "$state_is" ] && exit 0
|
2012-02-06 20:08:59 +00:00
|
|
|
|
2013-09-18 08:40:29 +00:00
|
|
|
file_type="$(cat "$__object/explorer/type")"
|
2011-07-21 22:28:41 +00:00
|
|
|
case "$state_should" in
|
2012-11-07 17:01:30 +00:00
|
|
|
present)
|
2013-09-18 08:40:29 +00:00
|
|
|
if [ "$file_type" = "directory" ]; then
|
2013-10-15 12:55:35 +00:00
|
|
|
# our destination is currently a directory, delete it
|
2013-09-18 08:40:29 +00:00
|
|
|
cat << DONE
|
2013-10-15 12:55:35 +00:00
|
|
|
rm -rf "$destination"
|
2013-09-18 08:40:29 +00:00
|
|
|
DONE
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create our link
|
|
|
|
cat << DONE
|
|
|
|
ln ${lnopt} -f "$source" "$destination"
|
|
|
|
DONE
|
2012-11-07 17:01:30 +00:00
|
|
|
;;
|
|
|
|
absent)
|
2013-09-18 08:40:29 +00:00
|
|
|
# only delete if it is a sym/hard link
|
|
|
|
if [ "$file_type" = "symlink" -o "$file_type" = "hardlink" ]; then
|
|
|
|
echo rm -f \"$destination\"
|
|
|
|
fi
|
2012-11-07 17:01:30 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown state: $state_should" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
2011-07-21 22:28:41 +00:00
|
|
|
esac
|