cfgfoo

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

4cc955d2f04545333eb34fb5c44c1490e9e54a6d

Author: Vasilii Kolobkov on 12/15/2018

Committer: Vasilii Kolobkov on 12/15/2018

Yi, er, san - the server becomes one!

Stats

aliases           | 14 +++
cfgfoo            | 41 ++++++++
steps/edit/addfln | 14 +++
steps/fs/install  |  7 ++
steps/fs/mkdir    |  9 ++
steps/pf/check    |  7 ++
steps/pf/load     |  7 ++
steps/rc/enable   |  7 ++
steps/rc/reload   |  7 ++
steps/rc/start    |  7 ++
10 files changed, 120 insertions(+)

Patch

diff --git a/aliases b/aliases
new file mode 100644
index 0000000..ba59099
--- /dev/null
+++ b/aliases
@@ -0,0 +1,14 @@
+: ${CFGFOOPATH:=./cfgfoo}
+alias cfgfoo="${CFGFOOPATH}/cfgfoo"
+
+alias addfln="cfgfoo ${CFGFOOPATH}/steps/edit/addfln "
+
+alias mkdir="cfgfoo ${CFGFOOPATH}/steps/fs/mkdir "
+alias install="cfgfoo ${CFGFOOPATH}/steps/fs/install -s "
+
+alias pfcheck="cfgfoo ${CFGFOOPATH}/steps/pf/check -s "
+alias pfload="cfgfoo ${CFGFOOPATH}/steps/pf/load -s "
+
+alias rcenable="cfgfoo ${CFGFOOPATH}/steps/rc/enable "
+alias rcstart="cfgfoo ${CFGFOOPATH}/steps/rc/start "
+alias rcreload="cfgfoo ${CFGFOOPATH}/steps/rc/reload "
diff --git a/cfgfoo b/cfgfoo
new file mode 100755
index 0000000..db1d13d
--- /dev/null
+++ b/cfgfoo
@@ -0,0 +1,41 @@
+#!/bin/sh
+if [ "$#" -eq 0 ]; then
+	printf "cfgfoo: Can't do without step file.\n"
+	exit 1
+fi
+__step="$1"
+shift
+if [ ! -f "$__step" ]; then
+	printf "cfgfoo: Step file '%s' doesn't exist.\n" "$__step"
+	exit 1
+fi
+
+if [ "$#" -gt 0 -a "$1" = -s ]; then
+	__stayput=y
+	shift
+fi
+
+(
+	printf "cfgfoo: Step '%s" "${__step}"
+	[ "$#" -gt 0 ] && printf " %s'.\n" "$*" || printf "'.\n"
+
+	if [ -n "${__stayput+y}" ]; then
+		. "$__step"
+	else
+		cd "$(dirname "$__step")"
+		. "./$(basename "$__step")"
+	fi
+
+	(set -e; step_taken "$@")
+	if [ "$?" -eq 0 ]; then
+		printf 'cfgfoo: Has already been taken. Skipping.\n'
+		exit
+	fi
+
+	(set -e; take_step "$@")
+	res="$?"
+	if [ "$res" -ne 0 ]; then
+		printf "cfgfoo: Failed with exit status %d.\n" "$res"
+		exit 1
+	fi
+)
diff --git a/steps/edit/addfln b/steps/edit/addfln
new file mode 100644
index 0000000..9b7dc09
--- /dev/null
+++ b/steps/edit/addfln
@@ -0,0 +1,14 @@
+step_taken() {
+	[ -f "$1" ] &&
+	grep -Fxq "$2" "$1"
+}
+
+take_step() {
+	# some exes like to concern themselves with term caps 
+	# while -s switch is on. play dumb even if for one ln
+	{
+		printf '$a\n'
+		printf '%s\n.\n' "$2"
+		printf 'w\nq\n'
+	} | TERM=dumb ex -s "$1"
+}
diff --git a/steps/fs/install b/steps/fs/install
new file mode 100644
index 0000000..51e9909
--- /dev/null
+++ b/steps/fs/install
@@ -0,0 +1,7 @@
+step_taken() {
+	[ -f "$2" ] && diff "$1" "$2" > /dev/null
+}
+
+take_step() {
+	install -o "$3" -g "$4" -m "$5" "$1" "$2"
+}
diff --git a/steps/fs/mkdir b/steps/fs/mkdir
new file mode 100644
index 0000000..2e0d249
--- /dev/null
+++ b/steps/fs/mkdir
@@ -0,0 +1,9 @@
+step_taken() {
+	[ -d "$1" ]
+}
+
+take_step() {
+	mkdir "$1"
+	chown "$2:$3" "$1"
+	chmod "$4" "$1"
+}
diff --git a/steps/pf/check b/steps/pf/check
new file mode 100644
index 0000000..fd89c65
--- /dev/null
+++ b/steps/pf/check
@@ -0,0 +1,7 @@
+step_taken() {
+	false
+}
+
+take_step() {
+	pfctl -n -f "$1"
+}
diff --git a/steps/pf/load b/steps/pf/load
new file mode 100644
index 0000000..7ee5509
--- /dev/null
+++ b/steps/pf/load
@@ -0,0 +1,7 @@
+step_taken() {
+	false
+}
+
+take_step() {
+	pfctl -f "$1"
+}
diff --git a/steps/rc/enable b/steps/rc/enable
new file mode 100644
index 0000000..41bbc6b
--- /dev/null
+++ b/steps/rc/enable
@@ -0,0 +1,7 @@
+step_taken() {
+	rcctl get "$1" status
+}
+
+take_step() {
+	rcctl enable "$1"
+}
diff --git a/steps/rc/reload b/steps/rc/reload
new file mode 100644
index 0000000..2a97603
--- /dev/null
+++ b/steps/rc/reload
@@ -0,0 +1,7 @@
+step_taken() {
+	false
+}
+
+take_step() {
+	rcctl reload "$1"
+}
diff --git a/steps/rc/start b/steps/rc/start
new file mode 100644
index 0000000..9c6624b
--- /dev/null
+++ b/steps/rc/start
@@ -0,0 +1,7 @@
+step_taken() {
+	rcctl check "$1"
+}
+
+take_step() {
+	rcctl start "$1"
+}