cfgfoo

git clone https://orangeshoelaces.net/git/cfgfoo.git

fc5b98170b3710e9d9ee7a6a5d1be6fbcf7d2f40

Author: Vasilii Kolobkov on 12/18/2018

Committer: Vasilii Kolobkov on 12/18/2018

Check if file exists before checking content

Stats

cfgfoo            | 7 +++++++
steps/pf/check    | 1 +
steps/smtpd/check | 1 +
3 files changed, 9 insertions(+)

Patch

diff --git a/cfgfoo b/cfgfoo
index db1d13d..80488e7 100755
--- a/cfgfoo
+++ b/cfgfoo
@@ -15,6 +15,13 @@ if [ "$#" -gt 0 -a "$1" = -s ]; then
 	shift
 fi
 
+file_exists() {
+	if [ ! -f "$1" ]; then
+		printf "Can't find '%s'.\n" "$1"
+		return 1
+	fi
+}
+
 (
 	printf "cfgfoo: Step '%s" "${__step}"
 	[ "$#" -gt 0 ] && printf " %s'.\n" "$*" || printf "'.\n"
diff --git a/steps/pf/check b/steps/pf/check
index fd89c65..2c2dc5c 100644
--- a/steps/pf/check
+++ b/steps/pf/check
@@ -3,5 +3,6 @@ step_taken() {
 }
 
 take_step() {
+	file_exists "$1"
 	pfctl -n -f "$1"
 }
diff --git a/steps/smtpd/check b/steps/smtpd/check
index 5e54a26..eeda8c5 100644
--- a/steps/smtpd/check
+++ b/steps/smtpd/check
@@ -3,5 +3,6 @@ step_taken() {
 }
 
 take_step() {
+	file_exists "$1"
 	smtpd -n -f "$1"
 }