rewrite type to work analog to __file and __link

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2013-09-18 13:25:45 +02:00
parent d7984df503
commit 7b065e931f
8 changed files with 117 additions and 189 deletions

View file

@ -1,39 +0,0 @@
#!/bin/sh
#
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
#
# 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/>.
#
#
# Check whether file exists or not
#
destination="/$__object_id"
os=$("$__explorer/os")
case "$os" in
"freebsd")
cmd="stat -f %Sg"
;;
*)
cmd="stat -c %G"
;;
esac
if [ -e "$destination" ]; then
$cmd "$destination"
fi

View file

@ -1,39 +0,0 @@
#!/bin/sh
#
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
#
# 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/>.
#
#
# Check whether file exists or not
#
destination="/$__object_id"
os=$("$__explorer/os")
case "$os" in
"freebsd")
cmd="stat -f %Op"
;;
*)
cmd="stat -c %a"
;;
esac
if [ -e "$destination" ]; then
$cmd "$destination"
fi

View file

@ -1,39 +0,0 @@
#!/bin/sh
#
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
#
# 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/>.
#
#
# Check whether file exists or not
#
destination="/$__object_id"
os=$("$__explorer/os")
case "$os" in
"freebsd")
cmd="stat -f %Su"
;;
*)
cmd="stat -c %U"
;;
esac
if [ -e "$destination" ]; then
$cmd "$destination"
fi

View file

@ -0,0 +1,26 @@
#!/bin/sh
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
destination="/$__object_id"
# nothing to work with, nothing we could do
[ -e "$destination" ] || exit 0
os=$("$__explorer/os")
case "$os" in
"freebsd")
# FIXME: should be something like this based on man page, but can not test
stat -f "type: %ST
owner: %Du %Su
group: %Dg %Sg
mode: %Op %Sp
" "$destination"
;;
*)
stat --printf="type: %F
owner: %u %U
group: %g %G
mode: %a %A
" "$destination"
;;
esac

View file

@ -1,30 +0,0 @@
#!/bin/sh
#
# 2011 Nico Schottelius (nico-cdist at schottelius.org)
#
# 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/>.
#
#
# Check whether file exists or not
#
destination="/$__object_id"
if [ -e "$destination" ]; then
echo present
else
echo absent
fi

View file

@ -0,0 +1,16 @@
#!/bin/sh
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
destination="/$__object_id"
if [ ! -e "$destination" ]; then
echo none
elif [ -h "$destination" ]; then
echo symlink
elif [ -f "$destination" ]; then
echo file
elif [ -d "$destination" ]; then
echo directory
else
echo unknown
fi

View file

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2013 Steven Armstrong (steven-cdist armstrong.cc)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -19,53 +20,84 @@
# #
destination="/$__object_id" destination="/$__object_id"
state_should="$(cat "$__object/parameter/state")"
type="$(cat "$__object/explorer/type")"
stat_file="$__object/explorer/stat"
state_is="$(cat "$__object/explorer/state")" # variable to keep track if we have to set directory attributes
owner_is="$(cat "$__object/explorer/owner")" set_attributes=
group_is="$(cat "$__object/explorer/group")"
mode_is="$(cat "$__object/explorer/mode")"
state_should="present"
[ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
mode=""
[ -f "$__object/parameter/mode" ] && mode="$(cat "$__object/parameter/mode")"
owner=""
[ -f "$__object/parameter/owner" ] && owner="$(cat "$__object/parameter/owner")"
group=""
[ -f "$__object/parameter/group" ] && group="$(cat "$__object/parameter/group")"
mkdiropt="" mkdiropt=""
[ -f "$__object/parameter/parents" ] && mkdiropt="-p" [ -f "$__object/parameter/parents" ] && mkdiropt="-p"
recursive="" recursive=""
[ -f "$__object/parameter/recursive" ] && recursive="-R" if [ -f "$__object/parameter/recursive" ]; then
recursive="-R"
# need to allways set attributes when recursive is given
# as we don't want to check all subfolders/files
set_attributes=1
fi
get_current_value() {
if [ -s "$stat_file" ]; then
_name="$1"
_value="$2"
case "$_value" in
[0-9]*)
_index=2
;;
*)
_index=3
;;
esac
awk '/'"$_name"':/ { print $'$_index' }' "$stat_file"
unset _name _value _index
fi
}
set_group() {
echo chgrp $recursive \"$1\" \"$destination\"
}
set_owner() {
echo chown $recursive \"$1\" \"$destination\"
}
set_mode() {
echo chmod $recursive \"$1\" \"$destination\"
}
case "$state_should" in case "$state_should" in
present) present)
if [ "$state_is" != "present" ]; then if [ "$type" != "directory" ];
echo mkdir $mkdiropt \"$destination\" # our destination is not a directory, remove whatever is there
fi # and then create our directory and set all attributes
set_attributes=1
cat << DONE
rm -f "$destination"
mkdir "$mkdiropt" "$destination"
DONE
fi
# Mode settings # Note: Mode - needs to happen last as a chown/chgrp can alter mode by
if [ "$mode" ] && [ "$mode_is" != "$mode" -o -n "$recursive" ]; then # clearing S_ISUID and S_ISGID bits (see chown(2))
echo chmod $recursive \"$mode\" \"$destination\" for attribute in group owner mode; do
fi if [ -f "$__object/parameter/$attribute" ]; then
value_should="$(cat "$__object/parameter/$attribute")"
# Group value_is="$(get_current_value "$attribute" "$value_should")"
if [ "$group" ] && [ "$group_is" != "$group" -o -n "$recursive" ]; then if [ "$set_attributes" -o "$value_should" != "$value_is" ]; then
echo chgrp $recursive \"$group\" \"$destination\" "set_$attribute" "$value_should"
fi fi
fi
# Owner done
if [ "$owner" ] && [ "$owner_is" != "$owner" -o -n "$recursive" ]; then ;;
echo chown $recursive \"$owner\" \"$destination\" absent)
fi if [ "$type" = "directory" ]; then
;; echo rm -rf \"$destination\"
absent) fi
if [ "$state_is" != "absent" ]; then ;;
echo rm -rf \"$destination\" *)
fi echo "Unknown state: $state_should" >&2
;; exit 1
*) ;;
echo "Unknown state: $state_should" >&2
exit 1
;;
esac esac

View file

@ -0,0 +1 @@
present