aboutsummaryrefslogtreecommitdiffstats
path: root/test/sys_req/set_system_parameters.sh
blob: 533a02edbaa48f9cc8c01631a170df64f0f3ee47 (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
#!/bin/bash

file="$1"

usage(){
	echo "Usage: $0 <requirements file>"
}

if [ "$file" == "" ]
then
	echo "Invalid parameters specified."
	usage
	exit 1
fi

if [ ! -f $file ]
then
	echo "File '$file' does not exist."
	usage
	exit 1
fi

cat $file | grep -v -e '^#.*$' | grep -v -e '^ *$' | while read line
do
	value_file=`echo $line | awk '{print $1}'`
	operator=`echo $line | awk '{print $2}'`
	value=`echo $line | awk '{print $3}'`
	set_value=`echo $line | awk '{print $4}'`
	if [[ "$value_file" == "" || "$operator" == "" || "$value" == "" || "$set_value" == "" ]]
	then
		echo "Syntax error in requirements file."
		exit 1
	fi
	current_value=`cat $value_file`
	if test "$current_value" $operator "$value"
	then
		if test "$V" = "2"
		then
			echo "Requirement '$value_file $operator $value' satisfied."
		fi
	else
		echo "Requirement '$value_file $operator $value' not satisfied."
		echo "Writing '$set_value' to '$value_file'."
		echo "$set_value" | tee "$value_file" > /dev/null
		if ! test "`cat $value_file`" = "$set_value"
		then
			echo "Repeating the write using sudo..."
			echo "$set_value" | sudo -n tee "$value_file" > /dev/null
			if ! test "`cat $value_file`" = "$set_value"
			then
				echo "Couldn't set the required value. Is that value allowed? Is sudo working?"
				exit 1
			fi
		fi
		echo "Succesfully wrote '$set_value' to '$value_file'."
	fi
done