bringing in testkit tools
[feisty_meow.git] / testkit / library / process_configuration.sh
1 #!/bin/bash
2
3 # Processes the XSEDE tools config file to turn variables listed in the
4 # file into exported variables in the environment.
5 #
6 # Author: Chris Koeritz
7
8 ##############
9
10 # this processes the single file of input parameters at the test root and
11 # turns it into a collection of environment variables.  we then load all those
12 # variables into the current environment.  we will also automatically fill in
13 # some important variables here that we'll use later.  in some cases, we will
14 # use the existing value if the variable is already set.
15 define_and_export_variables()
16 {
17   if [ -z "$TESTKIT_SENTINEL" ]; then echo Please run prepare_tools.sh before testing.; return 3; fi
18
19   # create our output folder so we can store logs and temporaries.
20   mkdir -p "$TEST_TEMP" &>/dev/null
21
22   # start writing the environment file.
23   echo > $TEST_TEMP/env_file
24
25   # turn each useful line in input file into an environment variable declaration.
26   while read line; do
27     # match lines that are comments or blank.
28     echo "$line" | grep -e '^[#;]' -e '^[       ]*$' &>/dev/null
29     # only export non-useless lines.
30     if [ $? != 0 ]; then
31       echo "$line" | grep '[a-z0-9A-Z]=(' &>/dev/null
32       if [ $? == 0 ]; then
33         # it's an array variable so don't try to export it or bash loses it for us.
34         echo $line >> $TEST_TEMP/env_file
35       else
36         echo "export" $line >> $TEST_TEMP/env_file
37       fi
38     fi
39   done < "$TESTKIT_CFG_FILE"
40
41   # now run the environment file to add those settings to our environment.
42   chmod +x $TEST_TEMP/env_file
43   source $TEST_TEMP/env_file &>/dev/null
44 }
45