| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"). |
| 6 | # You may not use this file except in compliance with the License. |
| 7 | # A copy of the License is located at |
| 8 | # |
| 9 | # http://aws.amazon.com/apache2.0 |
| 10 | # |
| 11 | # or in the "license" file accompanying this file. This file is distributed |
| 12 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 13 | # express or implied. See the License for the specific language governing |
| 14 | # permissions and limitations under the License. |
| 15 | # |
| 16 | |
| 17 | set -eu |
| 18 | source codebuild/bin/s2n_setup_env.sh |
| 19 | |
| 20 | usage() { |
| 21 | echo "install_apache2.sh config_dir install_dir" |
| 22 | exit 1 |
| 23 | } |
| 24 | |
| 25 | if [ "$#" -ne "2" ]; then |
| 26 | usage |
| 27 | fi |
| 28 | |
| 29 | APACHE2_CONFIG_DIR="$1" |
| 30 | APACHE2_INSTALL_DIR="$2" |
| 31 | |
| 32 | apache_enable() { |
| 33 | item_type="$1" |
| 34 | item="$2" |
| 35 | required="$3" |
| 36 | |
| 37 | source_path="/etc/apache2/${item_type}-available/${item}" |
| 38 | dest_path="${APACHE2_INSTALL_DIR}/${item_type}-enabled/${item}" |
| 39 | |
| 40 | if [ ! -f "${source_path}" ]; then |
| 41 | if [ "$required" = true ]; then |
| 42 | echo "apache item not found: ${source_path}" |
| 43 | exit 1 |
| 44 | fi |
| 45 | |
| 46 | return |
| 47 | fi |
| 48 | |
| 49 | ln -s "$source_path" "$dest_path" |
| 50 | } |
| 51 | |
| 52 | mod_enable() { |
| 53 | mod="$1" |
| 54 | apache_enable "mods" "${mod}.load" true |
| 55 | apache_enable "mods" "${mod}.conf" false |
| 56 | } |
| 57 | |
| 58 | conf_enable() { |
| 59 | conf="$1" |
| 60 | apache_enable "conf" "${conf}.conf" true |
| 61 | } |
| 62 | |
| 63 | cp -r "${APACHE2_CONFIG_DIR}" "${APACHE2_INSTALL_DIR}" |
| 64 | mkdir "${APACHE2_INSTALL_DIR}/mods-enabled" |
| 65 | mkdir "${APACHE2_INSTALL_DIR}/conf-enabled" |
| 66 | mkdir "${APACHE2_INSTALL_DIR}/run" |
| 67 | mkdir "${APACHE2_INSTALL_DIR}/lock" |
| 68 | mkdir "${APACHE2_INSTALL_DIR}/log" |
| 69 | |
| 70 | # Enable default mods |
| 71 | DEFAULT_MODS=("access_compat" "alias" "auth_basic" "authn_core" "authn_file" "authz_core" "authz_host" "authz_user" |
| 72 | "autoindex" "deflate" "dir" "env" "filter" "mime" "mpm_event" "negotiation" "reqtimeout" "setenvif" |
| 73 | "socache_shmcb" "status" "ssl") |
| 74 | for mod in "${DEFAULT_MODS[@]}"; do |
| 75 | mod_enable "$mod" |
| 76 | done |
| 77 | |
| 78 | # Enable default configuration |
| 79 | DEFAULT_CONF=("charset" "localized-error-pages" "other-vhosts-access-log" "security" "serve-cgi-bin") |
| 80 | for conf in "${DEFAULT_CONF[@]}"; do |
| 81 | conf_enable "$conf" |
| 82 | done |