Implement Nico's suggestions

Modified behavior of cksum explorer to print nothing if the file doesn't exist
Modified gencode-local to reflect cksum's new behavior
Modified gencode-remote to check states explicitly and error on invalid state.
This commit is contained in:
Jake Guffey 2012-09-21 10:06:16 -04:00
parent 5f435c1be7
commit 6afec72232
3 changed files with 16 additions and 16 deletions

View File

@ -34,8 +34,6 @@ PFCONF="${TMP:-"/etc/pf.conf"}"
if [ -f "${PFCONF}" ]; then # The pf config file exists, find its cksum. if [ -f "${PFCONF}" ]; then # The pf config file exists, find its cksum.
cksum -o 1 ${PFCONF} | cut -d= -f2 | awk '{print $1}' cksum -o 1 ${PFCONF} | cut -d= -f2 | awk '{print $1}'
else # the pf config file doesn't exist
echo NOTEXIST
fi fi
# Debug # Debug

View File

@ -59,7 +59,7 @@ case $uname in
;; ;;
esac esac
if [ ! "${cksum}" = "NOTEXIST" ]; then if [ -n "${cksum}" ]; then
if [ ! "\${currentSum}" = "${cksum}" ]; then if [ ! "\${currentSum}" = "${cksum}" ]; then
$__remote_copy "${source}" "$__target_host:${rcvar}.new" $__remote_copy "${source}" "$__target_host:${rcvar}.new"
fi fi

View File

@ -28,20 +28,22 @@
# Remove ${rcvar} in the case of --state absent # Remove ${rcvar} in the case of --state absent
state=$(cat "$__object/parameter/state") state=$(cat "$__object/parameter/state")
if [ ! "$state" = "absent" ]; then # There is nothing more for a *remote* script to do
exit 0
fi
rcvar=$(cat "$__object/explorer/rcvar") rcvar=$(cat "$__object/explorer/rcvar")
# --state absent, so ensure that .new doesn't exist and that conf is renamed to .old if [ "$state" = "present" ]; then # There is nothing more for a *remote* script to do
cat <<EOF exit 0
if [ -f "${rcvar}.new" ]; then elif [ "$state" = "absent" ]; then
rm "${rcvar}.new" # --state absent, so ensure that .new doesn't exist and that conf is renamed to .old
fi cat <<EOF
if [ -f "${rcvar}" ]; then if [ -f "${rcvar}.new" ]; then
mv "${rcvar}" "${rcvar}.old" rm "${rcvar}.new"
fi fi
if [ -f "${rcvar}" ]; then
mv "${rcvar}" "${rcvar}.old"
fi
EOF EOF
else
echo "Unknown state ${state}!" >&2
exit 1
fi