-
Notifications
You must be signed in to change notification settings - Fork 8
/
nmaahcmmconfig
executable file
·173 lines (153 loc) · 5.51 KB
/
nmaahcmmconfig
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env bash
# nmaahcmmconfig
# set up variables for microservices, has option for a graphical user interface
CONFIG="Y"
SCRIPT_PATH="${0%/*}"
. "${SCRIPT_PATH}/nmaahcmmfunctions"
[[ -f "${SCRIPT_PATH}/nmaahcmmfunctions" ]] || { echo "Missing '${SCRIPT_PATH}/nmaahcmmfunctions'. Exiting." ; exit 1 ;};
NMAAHCMM_CONFIG_FILE="${SCRIPTDIR}/nmaahcmm.conf"
if [[ "$(uname -s)" = "Darwin" ]] ; then
RUNPASHUA="Y"
fi
_usage(){
cat <<EOS
$(basename "${0}")
-a set configuration file using the GUI (default on macOS)
-t set configuration file using the CLI
EOS
}
# local variables
REQUIRED_VARIABLES=("DPX_DESTINATION" "DRIVE_CONTENTS_DESTINATION" "LOGDIR" "TMPDIR" "AIP_DESTINATION")
OPTIND=1
while getopts ":ath" OPT ; do
case "${OPT}" in
a) RUNPASHUA="Y" ;;
t) RUNPASHUA="N" ;;
h) _usage ; exit 0 ;;
*) echo "bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
_config_edit(){
[ -z "${1}" -o -z "${2}" ] && { _report -r "The config_edit function requires two arguments. Error." ; exit ;};
SEDTEMP=$(_maketemp)
sed "s:^${1}=[^ ]*:$1=$2:" "${NMAAHCMM_CONFIG_FILE}" > "${SEDTEMP}"
cp "${SEDTEMP}" "${NMAAHCMM_CONFIG_FILE}"
}
_test_config(){
for DIRECTORYVARIABLE in LOGDIR DPX_DESTINATION DRIVE_CONTENTS_DESTINATION AIP_DESTINATION ; do
if [ ! -d "${!DIRECTORYVARIABLE}" ] ; then
_report -r "${DIRECTORYVARIABLE} is NOT a valid directory"
fi
done
}
_add_key(){
KEY_TO_ADD="${1}"
grep -q "^${KEY_TO_ADD}=" "${NMAAHCMM_CONFIG_FILE}" ; GREP_CODE="$?"
if [[ ! "${GREP_CODE}" -eq "0" ]] ; then
_report -td "Adding NEW variable ${KEY_TO_ADD} to ${NMAAHCMM_CONFIG_FILE}"
echo "${KEY_TO_ADD}=" >> "${NMAAHCMM_CONFIG_FILE}"
fi
}
CONF="
# Set transparency: 0 is transparent, 1 is opaque
*.transparency=1.00
*.x = 250
*.y = 250
# Set window title
*.title = nmaahcmm config file
# intro text
intro.x = 20
intro.y = 375
intro.width = 500
intro.type = text
intro.text = Set up nmaahcmmconfig variables:
# AIP_DESTINATION
AIP_DESTINATION.x = 20
AIP_DESTINATION.y = 300
AIP_DESTINATION.type = openbrowser
AIP_DESTINATION.label = Please select the directory where your AIPs will be stored (see ingestfile and camera_cards):
AIP_DESTINATION.width = 470
AIP_DESTINATION.default = ${AIP_DESTINATION}
# DPX_DESTINATION
DPX_DESTINATION.x = 20
DPX_DESTINATION.y = 250
DPX_DESTINATION.type = openbrowser
DPX_DESTINATION.label = Please select the directory where copies of your DPX packages will go (see moveDPX):
DPX_DESTINATION.width = 470
DPX_DESTINATION.default = ${DPX_DESTINATION}
# DRIVE_CONTENTS_DESTINATION
DRIVE_CONTENTS_DESTINATION.x = 20
DRIVE_CONTENTS_DESTINATION.y = 200
DRIVE_CONTENTS_DESTINATION.type = openbrowser
DRIVE_CONTENTS_DESTINATION.label = Please select the directory where trees of your drives will be created (see makedrivetree):
DRIVE_CONTENTS_DESTINATION.width = 470
DRIVE_CONTENTS_DESTINATION.default = ${DRIVE_CONTENTS_DESTINATION}
# ask LOGDIR
LOGDIR.x = 20
LOGDIR.y = 150
LOGDIR.type = openbrowser
LOGDIR.label = Please select the directory where logs for these microservices will be created:
LOGDIR.width = 470
LOGDIR.default = ${LOGDIR}
# Add a cancel button with default label
cb.type=cancelbutton
";
# if a config file does not exist, create one using this GUI
if [[ "${RUNPASHUA}" = "Y" ]] ; then
PASHUA_CONFIGFILE=$(/usr/bin/mktemp /tmp/pashua_XXXXXXXXX)
echo "${CONF}" > "${PASHUA_CONFIGFILE}"
_pashua_run
rm "${PASHUA_CONFIGFILE}"
if [ "${PASHUAFAIL}" = "Y" ] ; then
echo "Pashua is not installed. Opening via CLI."
sleep 1
exec $(basename "${0}") -t
else
echo " AIP_DESTINATION = ${AIP_DESTINATION}"
echo " DPX_DESTINATION = ${DPX_DESTINATION}"
echo " DRIVE_CONTENTS_DESTINATION = ${DRIVE_CONTENTS_DESTINATION}"
echo " LOGDIR = ${LOGDIR}"
echo " TMPDIR = ${TMPDIR}"
echo
fi
#write to the config file
{
echo "AIP_DESTINATION=\"${AIP_DESTINATION}"\"
echo "DPX_DESTINATION=\"${DPX_DESTINATION}"\"
echo "DRIVE_CONTENTS_DESTINATION=\"${DRIVE_CONTENTS_DESTINATION}"\"
echo "LOGDIR=\"${LOGDIR}"\"
echo "TMPDIR=\"${TMPDIR}"\"
} > "${NMAAHCMM_CONFIG_FILE}"
else
# set up configuration file using the command line
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 "Testing ${NMAAHCMM_CONFIG_FILE} validity"
_test_config
echo
_report -d "Table of existing variables:"
for KEY in "${REQUIRED_VARIABLES[@]}" ; do
VALUE=$(grep "^${KEY}=" "${NMAAHCMM_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 "${NMAAHCMM_CONFIG_FILE}" ; exit 1 ;};
[ "${CONFIG_KEY}" = "${EDITOPTION2}" ] && { mate "${NMAAHCMM_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
fi