2017-06-28 11:19:32 +00:00
|
|
|
#!/bin/sh -e
|
2011-03-15 19:37:23 +00:00
|
|
|
#
|
2012-11-07 17:01:30 +00:00
|
|
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
2014-03-11 19:48:47 +00:00
|
|
|
# 2013-2014 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
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
|
2014-03-11 20:07:20 +00:00
|
|
|
printf 'rm -rf "%s" &&\n' "$destination"
|
2019-04-11 10:59:15 +00:00
|
|
|
echo "removed '$destination' (directory)" >> "$__messages_out"
|
2014-03-11 20:07:20 +00:00
|
|
|
else
|
|
|
|
if [ "$state_is" = "wrongsource" ]; then
|
|
|
|
# our destination is a symlink but points to the wrong source,
|
|
|
|
# delete it
|
|
|
|
printf 'rm -f "%s" &&\n' "$destination"
|
2019-04-11 10:59:15 +00:00
|
|
|
echo "removed '$destination' (wrongsource)" >> "$__messages_out"
|
2014-03-11 20:07:20 +00:00
|
|
|
fi
|
2014-03-11 19:48:47 +00:00
|
|
|
fi
|
|
|
|
|
2013-09-18 08:40:29 +00:00
|
|
|
# create our link
|
2014-03-11 20:07:20 +00:00
|
|
|
printf 'ln %s -f "%s" "%s"\n' "$lnopt" "$source" "$destination"
|
2019-04-11 10:59:15 +00:00
|
|
|
echo "created '$destination'" >> "$__messages_out"
|
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
|
2018-10-01 20:13:24 +00:00
|
|
|
if [ "$file_type" = "symlink" ] || [ "$file_type" = "hardlink" ]; then
|
2014-03-11 20:07:20 +00:00
|
|
|
printf 'rm -f "%s"\n' "$destination"
|
2019-04-11 10:59:15 +00:00
|
|
|
echo "removed '$destination'" >> "$__messages_out"
|
2013-09-18 08:40:29 +00:00
|
|
|
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
|