-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
setenv.sh
executable file
·48 lines (40 loc) · 1.1 KB
/
setenv.sh
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
#!/bin/bash
base_path="/var/nebra/envvars"
# Create necessary folder if it doesn't exist
if [ ! -d $base_path ]; then
mkdir -p $base_path
fi
create_file_if_not_exists() {
local name="$1"
local contents="$2"
local fullpath="${base_path}/${name}"
if [ ! -f "${fullpath}" ]; then
echo "${name} parameter file doesn't exist. Setting it as ${contents} now.";
echo "${contents}" > "${fullpath}"
fi
}
export_param_if_not_exists() {
local name="$1"
local fullpath="${base_path}/${name}"
if [ -f "${fullpath}" ]; then
contents=$(<"${fullpath}");
export "${name}"="${contents}"
echo "${name} is set as ${contents}.";
else
echo "Error: Cannot set ${name} variable.";
fi
}
#FREQ
if [ -z ${FREQ+x} ]; then
export_param_if_not_exists FREQ
else
echo "FREQ variable is already set as ${FREQ}.";
create_file_if_not_exists FREQ "${FREQ}"
fi
#VARIANT
if [ -z ${VARIANT+x} ]; then
export_param_if_not_exists VARIANT
else
echo "VARIANT variable is already set as ${VARIANT}.";
create_file_if_not_exists VARIANT "${VARIANT}"
fi