aboutsummaryrefslogtreecommitdiff
path: root/multiconfig.sh
blob: e85f0c01994c863b4982569738b5775c24765520 (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
74
75
76
77
78
#!/bin/sh
set -e

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
			;;
		*)
			MODS="$MODS $1"
			;;
	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"
	# Update git repository
	git fetch
	git reset --hard origin/master
	git clean -xdf
	# Verify trunk
	# TODO gpg home?
	#git verify-commit HEAD
fi

MODDIR="/usr/lib/multiconfig"
# No modules given means to process all modules
if [ -z "$MODS" ]; then
	for M in $(find "$MODDIR" -executable); do
		MODS="$MODS $M"
	done
else
	# Go trough all given modules and check if we have such module
	NMODS=""
	for M in $MODS; do
		if [ ! -x "$M" ]; then # Is not path directly to script
			if [ ! -x "$MODDIR/$M" ]; then
				echo "No such mode: $M"
				exit 1
			else
				NMODS="$NMODS $MODDIR/$M"
			fi
		else
			NMODS="$NMODS $M"
		fi
	done
	MODS="$NMODS"
fi

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