masto-aio/configure

73 lines
1.8 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
get_default() {
V=$1
if ! [[ -e config.mk ]]; then
return ""
fi
grep "$V = " config.mk | sed -e 's/.* = \+//'
}
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="$(get_default $VARNAME)"
if [[ -z "$DEFAULT" ]]; then
DEFAULT=$(echo "$LINE" | sed -e 's/^[0-9A-Z_]\+ *= *//')
fi
# 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