aboutsummaryrefslogtreecommitdiff
path: root/multiconfig.sh
blob: 500d0deaa228efe6a5979bb451334d1c73fb9505 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
set -e
MODDIR="/usr/lib/multiconfig"

MODS=""
LOCAL=false

# TODO email notifications
# TODO version verification

while [ $# -gt 0 ]; do
	case "$1" in
		-h|--help)
			echo "Multiconfig system script"
			echo "Usage: multiconfig.sh [OPTION]... [MODULE]..."
			echo
			echo "Options:"
			echo "--local - use current working directory as source for files"
			exit 0
			;;
		--local)
			LOCAL=true
			;;
		*)
			if [ -x "$1" ]; then
				MODS="$MODS $(pwd)/$1"
			elif [ -x "$MODDIR/$1" ]; then
				MODS="$MODS $MODDIR/$1"
			else
				echo "Requested unknown mod: $1"
				exit 1
			fi
			;;
	esac
	shift
done

[ "$(id -u)" == 0 ] || {
	echo "Please run this script only as root."
	exit 1
}

if ! $LOCAL; then
	if [ ! -d "/root/.multiconfig" ]; then
		echo "No files directory. Please setup it first."
		exit 1
	fi
	cd "/root/.multiconfig"
	# Ensure that we have correct access rights on private key
	chmod 600 ssh_key
	# Update git repository
	git fetch
	git reset --hard origin/master
	git clean -xdf
	# Verify trunk
	# TODO gpg home?
	#git verify-commit HEAD
fi

# No modules given means to process all modules
if [ -z "$MODS" ]; then
	for M in $(find "$MODDIR" -executable); do
		MODS="$MODS $MODDIR/$M"
	done
fi

[ -n "$MODS" ] || exit 0

mkdir -p /var/log/multiconfig
for M in $MODS; do
	LOG="/var/log/multiconfig/$(basename "$M")"
	"$M" | logger -s -t "multiconfig-$M" | tee "$LOG" || echo "TODO send email!"
done