forked from laurensorensen/DPDP_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdpdpconfig
More file actions
executable file
·72 lines (65 loc) · 2.4 KB
/
dpdpconfig
File metadata and controls
executable file
·72 lines (65 loc) · 2.4 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# mmconfig
# set up variables for microservices
CONFIG="Y"
CONFIG_VERSION="1.0"
scriptdir=$(dirname "$0")
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
# local variables
REQUIRED_VARIABLES=("PBCORE_USERNAME" "PBCORE_PASSWORD" "PROCESSDIR" "EMAIL_OUTCOME_TO" "CUSTOM_LOG_DIR")
config_edit(){
[ -z "$1" -o -z "$2" ] && { report -w "The config_edit function requires two arguments. Error." ; exit ;};
sedtemp=$(maketemp)
sed "s:^$1=[^ ]*:$1=$2:" "$CONFIG_FILE" > "$sedtemp"
cp "$sedtemp" "$CONFIG_FILE"
}
test_config(){
for directoryvariable in PROCESSDIR CUSTOM_LOG_DIR ; do
if [ -d "${!directoryvariable}" ] ; then
report -d "${directoryvariable} is a valid directory"
else
report -w "${directoryvariable} is NOT a valid directory"
fi
done
}
add_key(){
key_to_add="$1"
grep -q "^$key_to_add=" "$CONFIG_FILE" ; grep_code="$?"
if [[ ! "${grep_code}" -eq "0" ]] ; then
report -td "Adding NEW variable $key_to_add to $CONFIG_FILE"
echo "$key_to_add=" >> "$CONFIG_FILE"
fi
}
# set up configuration file if required
if [[ ! -f "$CONFIG_FILE" ]] ; then
echo "# $(basename $CONFIG_FILE)" > "$CONFIG_FILE"
echo "# This configuration file contains variables used throughout $WHAT_IS_THIS." >> "$CONFIG_FILE"
echo "# Edit the lines below to form KEY=VALUE. Please do not add or remove the existing KEYs. Do not edit CONFIG_FILE_VERSION." >> "$CONFIG_FILE"
echo "CONFIG_FILE_VERSION=$CONFIG_VERSION" >> "$CONFIG_FILE"
fi
for KEY in "${REQUIRED_VARIABLES[@]}" ; do
add_key "$KEY"
done
report -d "Testing $CONFIG_FILE validity"
test_config
echo
report -d "Table of existing variables:"
for KEY in "${REQUIRED_VARIABLES[@]}" ; do
VALUE=$(grep "^$KEY=" "$CONFIG_FILE" | cut -d= -f2)
printf '\t%-40s %-40s\n' "$KEY" "$VALUE"
done
while true ; do
EDITOPTION="Edit config file in nano"
report -q "Edit a variable? "
PS3="Selection (enter by number)? "
select CONFIG_KEY in "$EDITOPTION" "${REQUIRED_VARIABLES[@]}" "Quit"
do
break
done
[ "$CONFIG_KEY" = "Quit" ] && { echo Goodbye. ; exit 1 ;};
[ "$CONFIG_KEY" = "$EDITOPTION" ] && { nano "$CONFIG_FILE" ; exit 1 ;};
echo -n "Enter the value for $CONFIG_KEY: "
read "CONFIG_VALUE"
echo "$CONFIG_KEY is now set to $CONFIG_VALUE"
config_edit "$CONFIG_KEY" "$CONFIG_VALUE"
done