From 637163d4af0ec4c10327a73a83aed3fd39eecf00 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 10 Mar 2011 13:31:00 +0100 Subject: [PATCH 1/4] only md5sum if file is a regular file (not a directory) Signed-off-by: Nico Schottelius --- conf/type/__file/explorer/md5sum | 6 +++++- conf/type/__file/gencode | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/conf/type/__file/explorer/md5sum b/conf/type/__file/explorer/md5sum index b2867385..4ac0e1b9 100755 --- a/conf/type/__file/explorer/md5sum +++ b/conf/type/__file/explorer/md5sum @@ -41,7 +41,11 @@ esac # No output if file does not exist - does definitely not match the md5sum :-) if [ -e "$destination" ]; then - $md5sum < "$destination" + if [ -f "$destination" ]; then + $md5sum < "$destination" + else + echo "NO REGULAR FILE" + fi else echo "NO FILE FOUND, NO CHECKSUM CALCULATED." fi diff --git a/conf/type/__file/gencode b/conf/type/__file/gencode index 0f3b1bf8..43104f6f 100755 --- a/conf/type/__file/gencode +++ b/conf/type/__file/gencode @@ -55,16 +55,18 @@ esac if [ -f "$__object/parameter/source" ]; then source="$(cat "$__object/parameter/source")" - local_md5sum="$($md5sum < "$source")" - remote_md5sum="$(cat "$__object/explorer/md5sum")" + if [ -f "$source" ]; then + local_md5sum="$($md5sum < "$source")" + remote_md5sum="$(cat "$__object/explorer/md5sum")" - # 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}" + # 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 fi # No source? Create empty file/dir else From 62c64464120b101aff59e927d7ea6d81cbb5223e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 10 Mar 2011 13:36:58 +0100 Subject: [PATCH 2/4] exit true in case packet is not installed Signed-off-by: Nico Schottelius --- conf/type/__package_apt/gencode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/type/__package_apt/gencode b/conf/type/__package_apt/gencode index b451eb9f..413562d5 100755 --- a/conf/type/__package_apt/gencode +++ b/conf/type/__package_apt/gencode @@ -29,7 +29,7 @@ fi state="$(cat "$__object/parameter/state")" -is_installed="$(grep "^Status: install ok installed" "$__object/explorer/pkg_status")" +is_installed="$(grep "^Status: install ok installed" "$__object/explorer/pkg_status" || true)" case "$state" in installed) From e48458f27ff57c357f5c4514f42646cd4bbaf1ef Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 10 Mar 2011 13:38:12 +0100 Subject: [PATCH 3/4] add explorer to find out whether file exists Signed-off-by: Nico Schottelius --- conf/type/__file/explorer/exists | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 conf/type/__file/explorer/exists diff --git a/conf/type/__file/explorer/exists b/conf/type/__file/explorer/exists new file mode 100755 index 00000000..b0be82fc --- /dev/null +++ b/conf/type/__file/explorer/exists @@ -0,0 +1,34 @@ +#!/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 . +# +# +# Check whether file exists or not +# + +if [ -f "$__object/parameter/destination" ]; then + destination="$(cat "$__object/parameter/destination")" +else + destination="/$__object_id" +fi + +if [ -e "$destination" ]; then + echo yes +else + echo no +fi From 03502567e3c6f5e1f3c907865718b107c1295738 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 10 Mar 2011 13:40:05 +0100 Subject: [PATCH 4/4] check for existence before (re-)creation Signed-off-by: Nico Schottelius --- conf/type/__file/gencode | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/conf/type/__file/gencode b/conf/type/__file/gencode index 43104f6f..9ad956fe 100755 --- a/conf/type/__file/gencode +++ b/conf/type/__file/gencode @@ -70,20 +70,23 @@ if [ -f "$__object/parameter/source" ]; then fi # No source? Create empty file/dir else - case "$type" in - directory) - echo mkdir \"$destination\" - ;; + # Only touch / create if it does not exist + if [ no = "$(cat "$__object/explorer/exists")" ]; then + case "$type" in + directory) + echo mkdir \"$destination\" + ;; - file) - echo touch \"$destination\" - ;; + file) + echo touch \"$destination\" + ;; - *) - echo "Unsupported type: \"$type\"" >&2 - exit 1 - ;; - esac + *) + echo "Unsupported type: \"$type\"" >&2 + exit 1 + ;; + esac + fi fi if [ -f "$__object/parameter/mode" ]; then