forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmconfig
executable file
·83 lines (76 loc) · 3.2 KB
/
mmconfig
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
73
74
75
76
77
78
79
80
81
82
83
#!/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=("OUTDIR_INGESTFILE" "OUTDIR_INGESTXDCAM" "OUTDIR_PAPER" "AIP_STORAGE" "PODCASTDELIVER" "YOUTUBEDELIVER" "TMPDIR" "REGEX4PODCAST" "DVDLABELPREFIX" "OMNEONIP" "OMNEONPATH" "CUSTOM_LOG_DIR" "LTO_INDEX_DIR" "LOCAL_MM_DIR" "EMAIL_FROM" "MAKEYOUTUBE_DELIVERY_EMAIL_TO" "MAKEBROADCAST_DELIVERY_EMAIL_TO" "FILEMAKER_DB" "FILEMAKER_XML_URL" "VOLADJUST")
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 OUTDIR_INGESTFILE OUTDIR_INGESTXDCAM OUTDIR_PAPER AIP_STORAGE PODCASTDELIVER YOUTUBEDELIVER TMPDIR CUSTOM_LOG_DIR LTO_INDEX_DIR ; do
if [ ! -d "${!directoryvariable}" ] ; then
report -w "${directoryvariable} is NOT a valid directory"
fi
done
for booleanvariable in VOLADJUST ; do
if [[ ! "${!booleanvariable}" = "Y" && ! "${!booleanvariable}" = "N" ]] ; then
report -w "${booleanvariable} is NOT set to Y or N"
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 "(basename "${0}")"
report -d "Set system variables for ${WHAT_IS_THIS}"
echo
report -d "Notes:"
report -d "VOLADJUST must be set to 'Y' or 'N'"
echo
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
EDITOPTION1="Edit config file in nano"
EDITOPTION2="Edit config file in TextMate"
report -q "Edit a variable? "
PS3="Selection (enter by number)? "
select CONFIG_KEY in "$EDITOPTION1" "$EDITOPTION2" "${REQUIRED_VARIABLES[@]}" "Quit"
do
break
done
[ "$CONFIG_KEY" = "Quit" ] && { echo Goodbye. ; exit 1 ;};
[ "$CONFIG_KEY" = "$EDITOPTION1" ] && { nano "$CONFIG_FILE" ; exit 1 ;};
[ "$CONFIG_KEY" = "$EDITOPTION2" ] && { mate "$CONFIG_FILE" ; exit 1 ;};
echo -n "Enter the value for $CONFIG_KEY: "
read -e "CONFIG_VALUE"
echo "$CONFIG_KEY is now set to $CONFIG_VALUE"
config_edit "$CONFIG_KEY" "$CONFIG_VALUE"
done