masto-aio/configure
2023-11-12 16:50:05 -08:00

62 lines
1.6 KiB
Bash
Executable file

#!/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
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/ *=.*//')
DEFAULT=$(echo "$LINE" | sed -e 's/^[0-9A-Z_]\+ *= *//')
# 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
echo "All done! Putting your configuration into config.mk"
mv $TEMPFILE config.mk