Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | file="$1" |
| 4 | |
| 5 | usage(){ |
| 6 | echo "Usage: $0 <requirements file>" |
| 7 | } |
| 8 | |
| 9 | if [ "$file" == "" ] |
| 10 | then |
| 11 | echo "Invalid parameters specified." |
| 12 | usage |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | if [ ! -f $file ] |
| 17 | then |
| 18 | echo "File '$file' does not exist." |
| 19 | usage |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
Klement Sekera | e060ed1 | 2018-02-06 13:26:14 +0100 | [diff] [blame] | 23 | if test "$DOCKER_TEST" = "True" |
| 24 | then |
| 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 |
| 32 | fi |
| 33 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 34 | cat $file | grep -v -e '^#.*$' | grep -v -e '^ *$' | while read line |
| 35 | do |
| 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 |
| 68 | done |