2023-11-12 16:50:05 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
# I acknowledge that this is weird. Autoconf/automake are just too heavy for this task.
|
|
|
|
|
|
|
|
echo "Configuring. Please answer the following questions:"
|
|
|
|
|
|
|
|
# Read through config.mk.in. Every time a variable pops up, emit the comment
|
|
|
|
# before it and prompt the user for a value, using the setting in config.mk.in as a default
|
|
|
|
|
|
|
|
TEMPFILE=.config.temp
|
|
|
|
declare -A CONFIG
|
|
|
|
|
|
|
|
COMMENT=""
|
|
|
|
|
|
|
|
echo -n > $TEMPFILE
|
|
|
|
|
2024-01-26 16:39:30 -08:00
|
|
|
get_default() {
|
|
|
|
V=$1
|
|
|
|
if ! [[ -e config.mk ]]; then
|
|
|
|
return ""
|
|
|
|
fi
|
|
|
|
grep "$V = " config.mk | sed -e 's/.* = \+//'
|
|
|
|
}
|
|
|
|
|
2023-11-12 16:50:05 -08:00
|
|
|
while read LINE <&4; do
|
|
|
|
if echo "$LINE" | grep -q '^#'; then
|
|
|
|
COMMENT=$(echo "$LINE" | sed -e 's/^#\+ *//')
|
|
|
|
elif echo "$LINE" | grep -q '^[0-9A-Z_]\+ *= *'; then
|
|
|
|
|
|
|
|
VARNAME=$(echo "$LINE" | sed -e 's/ *=.*//')
|
2024-01-26 16:39:30 -08:00
|
|
|
DEFAULT="$(get_default $VARNAME)"
|
|
|
|
if [[ -z "$DEFAULT" ]]; then
|
|
|
|
DEFAULT=$(echo "$LINE" | sed -e 's/^[0-9A-Z_]\+ *= *//')
|
|
|
|
fi
|
2023-11-12 16:50:05 -08:00
|
|
|
|
|
|
|
# if there are prefix vars that are false, we need to skip
|
|
|
|
SKIP=0
|
|
|
|
for K in "${!CONFIG[@]}"; do
|
|
|
|
if echo "$VARNAME" | grep -q "^${K}"; then
|
|
|
|
if [[ ${CONFIG[$K]} -eq 0 ]]; then
|
|
|
|
SKIP=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ SKIP -eq 0 ]]; then
|
|
|
|
echo
|
|
|
|
echo "$COMMENT"
|
|
|
|
#echo "$LINE"
|
|
|
|
echo "(default: ${DEFAULT})"
|
|
|
|
echo -n "> "
|
|
|
|
read VALUE
|
|
|
|
|
|
|
|
if [[ -z $VALUE ]]; then
|
|
|
|
VALUE="${DEFAULT}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
CONFIG[${VARNAME}]="${VALUE}"
|
|
|
|
|
|
|
|
echo "# ${COMMENT}" >> $TEMPFILE
|
|
|
|
echo "${VARNAME} = ${VALUE}" >> $TEMPFILE
|
|
|
|
echo >> $TEMPFILE
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done 4< <(cat config.mk.in)
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
2024-01-26 16:42:37 -08:00
|
|
|
if [[ -e config.mk ]]; then
|
|
|
|
echo "Backing up your old config to config.mk.bak"
|
|
|
|
cp config.mk config.mk.bak
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "All done! Putting your configuration into config.mk."
|
2023-11-12 16:50:05 -08:00
|
|
|
mv $TEMPFILE config.mk
|
|
|
|
|