blob: 1084a07acf4c01dbfeddc56be8d9108b260e853a [file] [log] [blame]
Chris Sosacf1b0682012-06-08 19:58:59 -07001#!/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
15DEFAULT_IMAGE_ROOT=/home/chrome-test/images
16APACHE_CONFIG=/etc/apache2
17ARCHIVE_ROOT=/var/www
18MY_DIR="$(dirname $0)"
19
20set -e
21
22main () {
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"
28 cp -f "${MY_DIR}"/ports.conf "${APACHE_CONFIG}"
29 cp -f "${MY_DIR}"/devserver "${APACHE_CONFIG}"/sites-available
30
31 sudo chmod a+r -R ${ARCHIVE_ROOT}
32
33 # Enable configurations.
34 ln -sf "${APACHE_CONFIG}"/sites-available/devserver \
35 "${APACHE_CONFIG}"/sites-enabled
36
37 ln -sf "${APACHE_CONFIG}"/mods-available/proxy.load \
38 "${APACHE_CONFIG}"/mods-enabled
39 ln -sf "${APACHE_CONFIG}"/mods-available/proxy_http.load \
40 "${APACHE_CONFIG}"/mods-enabled
41
42 # Setup devserver archive location.
43 local image_root="${DEFAULT_IMAGE_ROOT}"
44 [ -n "${1}" ] && image_root="${1}"
45
46 local static_dir="${ARCHIVE_ROOT}"/static
47 if [ -e "${static_dir}" ]; then
48 unlink "${static_dir}"
49 fi
50
51 ln -sf "${image_root}" "${static_dir}"
52
53 /etc/init.d/apache2 restart
54}
55
56main $@