Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit b2c0558

Browse files
committed
ISSUE 42: Populate /etc/hosts for localhost usage.
1 parent 596a01b commit b2c0558

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

etc/apache-bootstrap

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
source /etc/apache-bootstrap.conf
44

5+
add_hosts_entry ()
6+
{
7+
local IP=${1:-127.0.0.1}
8+
local HOSTS
9+
local USAGE="Usage: $0 ip_address hostname [hostname ...]"
10+
11+
shift
12+
if [[ ${#} -eq 0 ]]; then
13+
echo ${USAGE}
14+
exit 1
15+
fi
16+
17+
while (( ${#} )); do
18+
if [[ ${1} != 'localhost' ]] && [[ ${1} != '127.0.0.1' ]] && [[ ${1} != ${IP} ]]; then
19+
HOSTS+=" ${1}"
20+
fi
21+
shift
22+
done
23+
24+
printf -- "%s\t%s\n" "${IP}" "${HOSTS}" >> /etc/hosts
25+
}
26+
527
get_password ()
628
{
729
echo $(head -n 4096 /dev/urandom | tr -cd '[:alnum:]' | head -c ${1})
@@ -19,9 +41,10 @@ set_apache_server_name ()
1941

2042
APP_HOME_DIR_TEMPLATE="/var/www/.app-skel"
2143

44+
OPTS_APACHE_SERVER_ALIAS="${APACHE_SERVER_ALIAS:-}"
2245
OPTS_APACHE_SERVER_NAME="${APACHE_SERVER_NAME:-$(hostname)}"
23-
OPTS_APACHE_MOD_SSL_ENABLED="${APACHE_MOD_SSL_ENABLED:-false}"
2446
OPTS_APACHE_LOAD_MODULES="${APACHE_LOAD_MODULES:-authz_user_module log_config_module expires_module deflate_module headers_module setenvif_module mime_module status_module dir_module alias_module reqtimeout_module}"
47+
OPTS_APACHE_MOD_SSL_ENABLED="${APACHE_MOD_SSL_ENABLED:-false}"
2548
OPTS_APP_HOME_DIR="${APP_HOME_DIR:-/var/www/app}"
2649
OPTS_SERVICE_USER="${SERVICE_USER:-app}"
2750
OPTS_SERVICE_USER_GROUP="${SERVICE_USER_GROUP:-app-www}"
@@ -68,6 +91,9 @@ else
6891
exit 1
6992
fi
7093

94+
# Add local hosts entries
95+
add_hosts_entry 127.0.0.1 ${OPTS_APACHE_SERVER_NAME}${OPTS_APACHE_SERVER_ALIAS:+ }${OPTS_APACHE_SERVER_ALIAS}
96+
7197
# Add ServerName
7298
set_apache_server_name ${OPTS_APACHE_SERVER_NAME} 80
7399

0 commit comments

Comments
 (0)