summary refs log tree commit diff
path: root/bin/os-conf
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-04-29 23:43:51 +0200
committerRobert Günzler <r@gnzler.io>2020-04-29 23:43:51 +0200
commit0ca054ba6760f51c612669061c465f3c6a365d15 (patch)
treed507ce4f51792e7130980e3fd5bd9cfa181c7755 /bin/os-conf
parent2c126599bab14d053d07956e35cf550e93fd1a31 (diff)
Add initial implemention of etc manifest and os-conf
Diffstat (limited to 'bin/os-conf')
-rwxr-xr-xbin/os-conf56
1 files changed, 56 insertions, 0 deletions
diff --git a/bin/os-conf b/bin/os-conf
new file mode 100755
index 0000000..94f60a4
--- /dev/null
+++ b/bin/os-conf
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+OS_DIR=${OS_DIR:-$HOME/os}
+OS_MANIFEST=$OS_DIR/manifest
+
+noop="echo "
+total=0
+
+copy_file() {
+	path=$1
+	if [ -f "$path" ]; then
+		# check that the file in the manifest matches
+		# skip if it does
+		if cmp "$path" "$OS_DIR$path" >/dev/null; then
+			return
+		fi
+		# mkdir base path
+		mkdir -p "$(dirname "$OS_DIR$path")"
+		# copy
+		cp -v "$path" "$OS_DIR$path"
+		# tally
+		total=$((total + 1))
+	elif [ -d "$path" ]; then
+		# handle dir
+		for file in "$path"/*; do
+			copy_file "$file"
+		done
+	else
+		# noop
+		echo "noop: $path"
+		return
+	fi
+}
+
+main() {
+	while IFS="\r" read -r line
+	do
+		[ -z "$line" ] && continue
+		echo "$line" | awk '/#.*/{exit 1}' || continue
+
+		# check that the file in the manifest exists
+		if [ ! -e "$line" ]; then
+			echo "error: $line not found" >&2
+			continue
+		fi
+		copy_file "$line"
+
+	done
+}
+
+uniq "$OS_MANIFEST" \
+	| grep -v '^$' \
+	| grep -v '^#' \
+	| main
+
+echo "$total files."