blob: aa23634b43558adb3b7299099fdf110fffde945f [file] [log] [blame]
Klement Sekera75e7d132017-09-20 08:26:30 +02001#!/bin/bash
2
3file="$1"
4
5usage(){
6 echo "Usage: $0 <requirements file>"
7}
8
9if [ "$file" == "" ]
10then
11 echo "Invalid parameters specified."
12 usage
13 exit 1
14fi
15
16if [ ! -f $file ]
17then
18 echo "File '$file' does not exist."
19 usage
20 exit 1
21fi
22
Klement Sekerae060ed12018-02-06 13:26:14 +010023if test "$DOCKER_TEST" = "True"
24then
25 echo "=============================================================================="
26 echo "DOCKER_TEST is set to '$DOCKER_TEST'."
27 echo "Skipping verification of some system parameters."
28 echo "Make sure these are set properly, otherwise tests might fail."
29 echo "Required values/criteria are in '`readlink -e $file`'."
30 echo "=============================================================================="
31 exit 0
32fi
33
Klement Sekera75e7d132017-09-20 08:26:30 +020034cat $file | grep -v -e '^#.*$' | grep -v -e '^ *$' | while read line
35do
36 value_file=`echo $line | awk '{print $1}'`
37 operator=`echo $line | awk '{print $2}'`
38 value=`echo $line | awk '{print $3}'`
39 set_value=`echo $line | awk '{print $4}'`
40 if [[ "$value_file" == "" || "$operator" == "" || "$value" == "" || "$set_value" == "" ]]
41 then
42 echo "Syntax error in requirements file."
43 exit 1
44 fi
45 current_value=`cat $value_file`
46 if test "$current_value" $operator "$value"
47 then
48 if test "$V" = "2"
49 then
50 echo "Requirement '$value_file $operator $value' satisfied."
51 fi
52 else
53 echo "Requirement '$value_file $operator $value' not satisfied."
54 echo "Writing '$set_value' to '$value_file'."
55 echo "$set_value" | tee "$value_file" > /dev/null
56 if ! test "`cat $value_file`" = "$set_value"
57 then
58 echo "Repeating the write using sudo..."
59 echo "$set_value" | sudo -n tee "$value_file" > /dev/null
60 if ! test "`cat $value_file`" = "$set_value"
61 then
62 echo "Couldn't set the required value. Is that value allowed? Is sudo working?"
63 exit 1
64 fi
65 fi
66 echo "Succesfully wrote '$set_value' to '$value_file'."
67 fi
68done