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)" |
| 19 | |
| 20 | set -e |
| 21 | |
| 22 | main () { |
| 23 | sudo apt-get install apache2 |
| 24 | |
| 25 | # Copy over configuration data. |
| 26 | mkdir -m 755 -p "${ARCHIVE_ROOT}" |
| 27 | cp -f "${MY_DIR}"/htaccess "${ARCHIVE_ROOT}/.htaccess" |
Chris Sosa | 8227c59 | 2012-06-28 16:58:15 -0700 | [diff] [blame] | 28 | cp -f "${MY_DIR}"/apache2.conf "${APACHE_CONFIG}" |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 29 | cp -f "${MY_DIR}"/ports.conf "${APACHE_CONFIG}" |
| 30 | cp -f "${MY_DIR}"/devserver "${APACHE_CONFIG}"/sites-available |
| 31 | |
| 32 | sudo chmod a+r -R ${ARCHIVE_ROOT} |
| 33 | |
| 34 | # Enable configurations. |
| 35 | ln -sf "${APACHE_CONFIG}"/sites-available/devserver \ |
| 36 | "${APACHE_CONFIG}"/sites-enabled |
| 37 | |
| 38 | ln -sf "${APACHE_CONFIG}"/mods-available/proxy.load \ |
| 39 | "${APACHE_CONFIG}"/mods-enabled |
| 40 | ln -sf "${APACHE_CONFIG}"/mods-available/proxy_http.load \ |
| 41 | "${APACHE_CONFIG}"/mods-enabled |
Chris Sosa | 28be7db | 2012-06-13 16:26:10 -0700 | [diff] [blame] | 42 | ln -sf "${APACHE_CONFIG}"/mods-available/rewrite.load \ |
| 43 | "${APACHE_CONFIG}"/mods-enabled |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 44 | |
| 45 | # Setup devserver archive location. |
| 46 | local image_root="${DEFAULT_IMAGE_ROOT}" |
Chris Sosa | bc5d0fa | 2013-07-11 14:14:45 -0700 | [diff] [blame] | 47 | [ -n "${1}" ] && image_root="$(readlink -f "${1}")" |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 48 | |
| 49 | local static_dir="${ARCHIVE_ROOT}"/static |
Chris Sosa | bc5d0fa | 2013-07-11 14:14:45 -0700 | [diff] [blame] | 50 | if [ -h "${static_dir}" ]; then |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 51 | unlink "${static_dir}" |
| 52 | fi |
| 53 | |
| 54 | ln -sf "${image_root}" "${static_dir}" |
| 55 | |
Chris Sosa | 28be7db | 2012-06-13 16:26:10 -0700 | [diff] [blame] | 56 | if [ -e "${static_dir}/archive" ]; then |
| 57 | unlink "${static_dir}/archive" |
| 58 | fi |
| 59 | |
Chris Sosa | cf1b068 | 2012-06-08 19:58:59 -0700 | [diff] [blame] | 60 | /etc/init.d/apache2 restart |
| 61 | } |
| 62 | |
| 63 | main $@ |