summary refs log tree commit diff
path: root/bin/os-conf
blob: 94f60a4fd65354256d7cba0c0442af7148856471 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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."