Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # This script can be used to set up apache to interact with the devserver. |
| 8 | # This apache server will run on port 8082 and rewrite requests to the |
| 9 | # devserver that aren't stored in the IMAGE_ROOT. |
| 10 | |
| 11 | # Usage: |
| 12 | # ./setup_apache.sh -- Sets up using default static directory. |
| 13 | # ./setup_apache.sh DIR -- Sets up apache to serve images from DIR. |
| 14 | |
Chris Sosa | 28be7db | 2012-06-13 16:26:10 -0700 | [diff] [blame] | 15 | DEFAULT_IMAGE_ROOT=/home/chromeos-test/images |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 16 | APACHE_CONFIG=/etc/apache2 |
| 17 | ARCHIVE_ROOT=/var/www |
| 18 | MY_DIR="$(dirname $0)" |
Fang Deng | ae730b6 | 2015-04-20 11:26:59 -0700 | [diff] [blame] | 19 | codename=$(cat /etc/lsb-release | grep DISTRIB_CODENAME | awk -F '=' '{print $2}') |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 20 | |
| 21 | set -e |
| 22 | |
| 23 | main () { |
| 24 | sudo apt-get install apache2 |
| 25 | |
| 26 | # Copy over configuration data. |
| 27 | mkdir -m 755 -p "${ARCHIVE_ROOT}" |
| 28 | cp -f "${MY_DIR}"/htaccess "${ARCHIVE_ROOT}/.htaccess" |
| 29 | cp -f "${MY_DIR}"/ports.conf "${APACHE_CONFIG}" |
| 30 | cp -f "${MY_DIR}"/devserver "${APACHE_CONFIG}"/sites-available |
Fang Deng | ae730b6 | 2015-04-20 11:26:59 -0700 | [diff] [blame] | 31 | if [ "$codename" = "trusty" ] ; then |
| 32 | cp -f "${MY_DIR}"/apache2.conf.trusty "${APACHE_CONFIG}"/apache2.conf |
| 33 | else |
| 34 | cp -f "${MY_DIR}"/apache2.conf "${APACHE_CONFIG}" |
| 35 | fi |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 36 | |
| 37 | sudo chmod a+r -R ${ARCHIVE_ROOT} |
| 38 | |
| 39 | # Enable configurations. |
| 40 | ln -sf "${APACHE_CONFIG}"/sites-available/devserver \ |
| 41 | "${APACHE_CONFIG}"/sites-enabled |
| 42 | |
| 43 | ln -sf "${APACHE_CONFIG}"/mods-available/proxy.load \ |
| 44 | "${APACHE_CONFIG}"/mods-enabled |
| 45 | ln -sf "${APACHE_CONFIG}"/mods-available/proxy_http.load \ |
| 46 | "${APACHE_CONFIG}"/mods-enabled |
Chris Sosa | 28be7db | 2012-06-13 16:26:10 -0700 | [diff] [blame] | 47 | ln -sf "${APACHE_CONFIG}"/mods-available/rewrite.load \ |
| 48 | "${APACHE_CONFIG}"/mods-enabled |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 49 | |
Fang Deng | ae730b6 | 2015-04-20 11:26:59 -0700 | [diff] [blame] | 50 | # Disable dir module so that it won't redirect empty path to index.html |
| 51 | if [ "$codename" = "trusty" ] ; then |
| 52 | sudo a2dismod dir |
| 53 | fi |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 54 | # Setup devserver archive location. |
| 55 | local image_root="${DEFAULT_IMAGE_ROOT}" |
Chris Sosa | bc5d0fa | 2013-07-11 14:14:45 -0700 | [diff] [blame] | 56 | [ -n "${1}" ] && image_root="$(readlink -f "${1}")" |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 57 | |
| 58 | local static_dir="${ARCHIVE_ROOT}"/static |
Chris Sosa | bc5d0fa | 2013-07-11 14:14:45 -0700 | [diff] [blame] | 59 | if [ -h "${static_dir}" ]; then |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 60 | unlink "${static_dir}" |
| 61 | fi |
| 62 | |
| 63 | ln -sf "${image_root}" "${static_dir}" |
| 64 | |
Chris Sosa | 28be7db | 2012-06-13 16:26:10 -0700 | [diff] [blame] | 65 | if [ -e "${static_dir}/archive" ]; then |
| 66 | unlink "${static_dir}/archive" |
| 67 | fi |
| 68 | |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 69 | /etc/init.d/apache2 restart |
| 70 | } |
| 71 | |
| 72 | main $@ |