message "${PROBLEM_COLOR}On picking a Multi-Processing Module (MPM);

tl;dr choose event unless you know what you are doing and have a
specific reason to choose otherwise.

On any modern *nix system you should probably prefer the event module.
It is the most performant module but requires thread support and
thread-safe polling using kqueue and epoll functions. If your platform
supports threads but not thread-safe polling you can use the worker
module. The last resort is the prefork module for platforms that do not
support threads.${DEFAULT_COLOR}" &&
config_query_list APACHE24_MPM "Which MPM would you like?" prefork worker event &&

# Apache2 CONFIGURE script
#
# Created 2003-07-21 by Gareth Clay <g.clay@warwick.ac.uk> with a
# lot of help from the linux and init.d spells ;)
#
# Edited a bit to allow for --enable and --disable options in the module configs,
# which was required to compensate for the eternal wisdom of the apache devs
# by Arjan Bouter <abouter@sourcemage.org>
#
# Notes:
# Modules deliberately missed out:
# * mod_isapi   (win32 only)
# * mod_nw_ssl  (netware only)

# extra options, for sub dependencies
persistent_add APACHE24_EXTRA
APACHE24_EXTRA=

basic_config() {
  # Perform any configuration in here that doesn't involve modules
  local SWITCH

true

}

module_list() {
  # Return a dialog-friendly list of modules and attributes
  for NAME in $MODULELIST
  do
    source $MODULEDIR/$NAME
    echo $NAME
    echo $TYPE
    echo $STATUS
    echo $SHORT
  done
}

module_config() {

  while true
  do
    OUTPUT=$( $DIALOG --title "$TITLE" --help-button --item-help --nocancel \
    --checklist "Select the modules you would like to be compiled into your Apache2. It's generally a good idea to compile base modules. The rest are completely up to you!" \
    0 0 0 \
    $(module_list) )

    RETVAL=$?
    if [ $RETVAL == 0 ]
    then
      # OK or HELP was pressed
      FIRSTFIELD=$( echo $OUTPUT | cut -d' ' -f1 )
      REST=$( echo $OUTPUT | cut -d' ' -f2- )

      if [[ "$FIRSTFIELD" != "" ]] && [[ "$FIRSTFIELD" == "HELP" ]]
      then
        # HELP was pressed
        display_help
      else
        # OK was pressed
        # OUTPUT now contains the list of modules to build
        output_module_config
        break
      fi
    else
      # CANCEL was pressed
      break
    fi
  done
}

display_help() {
  # Display the long description of the selected item
  for MODNAME in $MODULELIST
  do
    source $MODULEDIR/$MODNAME
    if [ $SHORT = $REST ]
    then
      $DIALOG --title "Help for $MODNAME" \
      --msgbox "Description of module $MODNAME:\n\n$DESCRIPTION" 0 0
      break
    fi
  done
}

output_module_config() {
  # Function to output the configuration info to $SPELL_CONFIG

  # First we need to strip the quotes out of $OUTPUT
  OUTPUT=$( echo $OUTPUT | sed -e 's/\"//g' )

  # Iterate through all the modules. TARGET is the
  # first unmatched module in the list of modules
  # to enable. NAME is the name of the target module
  # (eg. for mod_auth, $NAME would be "mod_auth").

  local TARGET=$( echo $OUTPUT | cut -d' ' -f1 )

  for MODULE in $MODULELIST
  do
    source $MODULEDIR/$MODULE

    if [[ "$TARGET" == "" ]] || [[ "$TARGET" != "$MODULE" ]]
    then
      # Disable this module
      echo "OPTS=\"\$OPTS $DISABLE\"" >> $SPELL_CONFIG
    else
      # Enable this module
      if [[ "${APACHE24_SHARED}" == "y" ]]; then
         echo "OPTS=\"\$OPTS $ENABLE=shared\"" >> $SPELL_CONFIG
      else
         echo "OPTS=\"\$OPTS $ENABLE\"" >> $SPELL_CONFIG
      fi
      OUTPUT=$( echo $OUTPUT | cut -d' ' -f2- )
      TARGET=$( echo $OUTPUT | cut -d' ' -f1 )
    fi
  done
}



# Perform the configuration

if ! grep -q 'CONFIGURED=y' $SPELL_CONFIG; then
  local oldIFS=$IFS
  export IFS="
"

  TITLE="Apache2 Configuration"
  MODULEDIR="$SCRIPT_DIRECTORY/modules"
  MODULELIST=`ls $MODULEDIR`
  DIALOG="dialog
--backtitle
Apache2 Configuration
--stdout"

  basic_config
  module_config

  echo 'CONFIGURED=y' >> $SPELL_CONFIG

  IFS=$oldIFS

fi
