begin to cleanup __file
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
1619964cbb
commit
e06e8026dd
2 changed files with 27 additions and 73 deletions
|
@ -18,27 +18,13 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# __file is a very basic type and should be able to be used as an
|
# __file is a very basic type, which will probably be reused quite often
|
||||||
# example for typewrites later
|
|
||||||
#
|
#
|
||||||
|
|
||||||
# If destination was specified, do not use the id
|
destination="/$__object_id"
|
||||||
if [ -f "$__object/parameter/destination" ]; then
|
|
||||||
destination="$(cat "$__object/parameter/destination")"
|
|
||||||
else
|
|
||||||
# If no destination has been supplied, the id is the destination
|
|
||||||
# Prepend /, which got lost in the object id (and relative paths
|
|
||||||
# don't make sense)
|
|
||||||
destination="/$__object_id"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ensure we have an absolute path
|
|
||||||
if ! $(echo "$destination" | grep -q ^/); then
|
|
||||||
echo "Error: Destination ($destination) of $__object_id is not absolute." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use correct md5sum binary - MacOSx is different here
|
# Use correct md5sum binary - MacOSx is different here
|
||||||
|
# FIXME: broken: we don't know the host os!
|
||||||
case "$os" in
|
case "$os" in
|
||||||
macosx)
|
macosx)
|
||||||
md5sum="md5"
|
md5sum="md5"
|
||||||
|
@ -49,63 +35,31 @@ case "$os" in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
type="$(cat "$__object/parameter/type")"
|
if [ -f "$__object/parameter/source" ]; then
|
||||||
|
source="$(cat "$__object/parameter/source")"
|
||||||
|
|
||||||
case "$type" in
|
if [ -f "$source" ]; then
|
||||||
directory)
|
local_md5sum="$($md5sum < "$source")"
|
||||||
if [ -f "$__object/parameter/source" ]; then
|
remote_md5sum="$(cat "$__object/explorer/md5sum")"
|
||||||
echo "Source not supported for directory currently - FIXME" >&2
|
|
||||||
exit 1
|
# FIXME: Is md5sum the right approach?
|
||||||
else
|
if [ "$local_md5sum" != "$remote_md5sum" ]; then
|
||||||
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
# FIXME: This is ugly and hardcoded, replace after 1.0!
|
||||||
echo mkdir \"$destination\"
|
# Probably a better aproach is to have the user configured
|
||||||
fi
|
# ~/.ssh/config to contain the right username
|
||||||
|
# Probably describe it in cdist-quickstart...
|
||||||
|
scp "$source" "root@${__target_host}:${destination}"
|
||||||
fi
|
fi
|
||||||
;;
|
else
|
||||||
|
echo "Source \"$source\" does not exist." >&2
|
||||||
file)
|
|
||||||
if [ -f "$__object/parameter/source" ]; then
|
|
||||||
source="$(cat "$__object/parameter/source")"
|
|
||||||
|
|
||||||
if [ -f "$source" ]; then
|
|
||||||
local_md5sum="$($md5sum < "$source")"
|
|
||||||
remote_md5sum="$(cat "$__object/explorer/md5sum")"
|
|
||||||
|
|
||||||
# FIXME: Is md5sum the right approach?
|
|
||||||
if [ "$local_md5sum" != "$remote_md5sum" ]; then
|
|
||||||
# FIXME: This is ugly and hardcoded, replace after 1.0!
|
|
||||||
# Probably a better aproach is to have the user configured
|
|
||||||
# ~/.ssh/config to contain the right username
|
|
||||||
# Probably describe it in cdist-quickstart...
|
|
||||||
scp "$source" "root@${__target_host}:${destination}"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "Source \"$source\" does not exist." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
|
||||||
echo touch \"$destination\"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
symlink)
|
|
||||||
if [ ! -f "$__object/parameter/source" ]; then
|
|
||||||
echo "Source required for symlink" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
source="$(cat "$__object/parameter/source")"
|
|
||||||
|
|
||||||
# FIXME: handle directories or document & ignore?
|
|
||||||
echo ln -sf \"$source\" \"$destination\"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Unsupported type: \"$type\"" >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
fi
|
||||||
esac
|
else
|
||||||
|
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
||||||
|
echo touch \"$destination\"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Mode settings
|
# Mode settings
|
||||||
if [ -f "$__object/parameter/mode" ]; then
|
if [ -f "$__object/parameter/mode" ]; then
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Proposal for new types, which replace __file:
|
Proposal for new types, which replace __file:
|
||||||
|
|
||||||
__directory /etc [--mode --owner --group --parents [yes|no] ]
|
x __directory /etc [--mode --owner --group --parents [yes|no] ]
|
||||||
|
|
||||||
__link /destination --source abc --type [symbolic|hard]
|
x __link /destination --source abc --type [symbolic|hard]
|
||||||
|
|
||||||
__file /etc/passwd [--source] --mode --owner --group
|
__file /etc/passwd [--source] --mode --owner --group
|
||||||
|
|
Loading…
Reference in a new issue