diff options
| author | Robert Günzler <r@gnzler.io> | 2020-04-29 23:43:51 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2020-04-29 23:43:51 +0200 |
| commit | 0ca054ba6760f51c612669061c465f3c6a365d15 (patch) | |
| tree | d507ce4f51792e7130980e3fd5bd9cfa181c7755 /bin/os-conf | |
| parent | 2c126599bab14d053d07956e35cf550e93fd1a31 (diff) | |
Add initial implemention of etc manifest and os-conf
Diffstat (limited to 'bin/os-conf')
| -rwxr-xr-x | bin/os-conf | 56 |
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." |