__file: --type symlink supported
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
9e7a430372
commit
a190ee13b8
3 changed files with 53 additions and 36 deletions
|
@ -13,7 +13,7 @@ case "$__target_host" in
|
||||||
# Everybody has this
|
# Everybody has this
|
||||||
localhost)
|
localhost)
|
||||||
# Usual example
|
# Usual example
|
||||||
__file test --type file --destination /tmp/cdist-testfile
|
__file test --type symlink --source /etc/cdist-configured --destination /tmp/cdist-testfile
|
||||||
;;
|
;;
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
# example for typewrites later
|
# example for typewrites later
|
||||||
#
|
#
|
||||||
|
|
||||||
type="$(cat "$__object/parameter/type")"
|
|
||||||
|
|
||||||
# If destination was specified, do not use the id
|
# If destination was specified, do not use the id
|
||||||
if [ -f "$__object/parameter/destination" ]; then
|
if [ -f "$__object/parameter/destination" ]; then
|
||||||
destination="$(cat "$__object/parameter/destination")"
|
destination="$(cat "$__object/parameter/destination")"
|
||||||
|
@ -40,6 +38,7 @@ if ! $(echo "$destination" | grep -q ^/); then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Use correct md5sum binary - MacOSx is different here
|
||||||
case "$os" in
|
case "$os" in
|
||||||
macosx)
|
macosx)
|
||||||
md5sum="md5"
|
md5sum="md5"
|
||||||
|
@ -50,16 +49,29 @@ case "$os" in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Copy source if existing
|
type="$(cat "$__object/parameter/type")"
|
||||||
# FIXME: directory handling not supported - add recursive flag?
|
|
||||||
if [ -f "$__object/parameter/source" ]; then
|
case "$type" in
|
||||||
|
directory)
|
||||||
|
if [ -f "$__object/parameter/source" ]; then
|
||||||
|
echo "Source not supported for directory currently - FIXME" >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
||||||
|
echo mkdir \"$destination\"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
file)
|
||||||
|
if [ -f "$__object/parameter/source" ]; then
|
||||||
source="$(cat "$__object/parameter/source")"
|
source="$(cat "$__object/parameter/source")"
|
||||||
|
|
||||||
if [ -f "$source" ]; then
|
if [ -f "$source" ]; then
|
||||||
local_md5sum="$($md5sum < "$source")"
|
local_md5sum="$($md5sum < "$source")"
|
||||||
remote_md5sum="$(cat "$__object/explorer/md5sum")"
|
remote_md5sum="$(cat "$__object/explorer/md5sum")"
|
||||||
|
|
||||||
# Is md5sum the right approach?
|
# FIXME: Is md5sum the right approach?
|
||||||
if [ "$local_md5sum" != "$remote_md5sum" ]; then
|
if [ "$local_md5sum" != "$remote_md5sum" ]; then
|
||||||
# FIXME: This is ugly and hardcoded, replace after 1.0!
|
# FIXME: This is ugly and hardcoded, replace after 1.0!
|
||||||
# Probably a better aproach is to have the user configured
|
# Probably a better aproach is to have the user configured
|
||||||
|
@ -68,27 +80,31 @@ if [ -f "$__object/parameter/source" ]; then
|
||||||
scp "$source" "root@${__target_host}:${destination}"
|
scp "$source" "root@${__target_host}:${destination}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# No source? Create empty file/dir
|
else
|
||||||
else
|
|
||||||
# Only touch / create if it does not exist
|
|
||||||
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
||||||
case "$type" in
|
echo touch \"$destination\"
|
||||||
directory)
|
fi
|
||||||
echo mkdir \"$destination\"
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
file)
|
symlink)
|
||||||
echo touch \"$destination\"
|
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
|
echo "Unsupported type: \"$type\"" >&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Mode settings
|
||||||
if [ -f "$__object/parameter/mode" ]; then
|
if [ -f "$__object/parameter/mode" ]; then
|
||||||
mode="$(cat "$__object/parameters/mode")"
|
mode="$(cat "$__object/parameters/mode")"
|
||||||
echo chmod \"$mode\" \"$destination\"
|
echo chmod \"$mode\" \"$destination\"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* Update regexp used for sane characters
|
* Update regexp used for sane characters
|
||||||
* Allow types without parameters
|
* Allow types without parameters
|
||||||
* Allow type to be singleton (DOCUMENTATION MISSING)
|
* Allow type to be singleton (DOCUMENTATION MISSING)
|
||||||
|
* Type __file learned --type symlink
|
||||||
|
|
||||||
1.0.2: 2011-03-09
|
1.0.2: 2011-03-09
|
||||||
* Add manpages: cdist-type, cdist-type__file, cdist-reference, cdist-explorer
|
* Add manpages: cdist-type, cdist-type__file, cdist-reference, cdist-explorer
|
||||||
|
|
Loading…
Reference in a new issue