blob: 2df2540c7028e9a64e21fe80197bd33fd1e5592d [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
Chris Sosa28be7db2012-06-13 16:26:10 -070015DEFAULT_IMAGE_ROOT=/home/chromeos-test/images
Chris Sosacf1b0682012-06-08 19:58:59 -070016APACHE_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"
Chris Sosa8227c592012-06-28 16:58:15 -070028 cp -f "${MY_DIR}"/apache2.conf "${APACHE_CONFIG}"
Chris Sosacf1b0682012-06-08 19:58:59 -070029 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 Sosa28be7db2012-06-13 16:26:10 -070042 ln -sf "${APACHE_CONFIG}"/mods-available/rewrite.load \
43 "${APACHE_CONFIG}"/mods-enabled
Chris Sosacf1b0682012-06-08 19:58:59 -070044
45 # Setup devserver archive location.
46 local image_root="${DEFAULT_IMAGE_ROOT}"
Chris Sosabc5d0fa2013-07-11 14:14:45 -070047 [ -n "${1}" ] && image_root="$(readlink -f "${1}")"
Chris Sosacf1b0682012-06-08 19:58:59 -070048
49 local static_dir="${ARCHIVE_ROOT}"/static
Chris Sosabc5d0fa2013-07-11 14:14:45 -070050 if [ -h "${static_dir}" ]; then
Chris Sosacf1b0682012-06-08 19:58:59 -070051 unlink "${static_dir}"
52 fi
53
54 ln -sf "${image_root}" "${static_dir}"
55
Chris Sosa28be7db2012-06-13 16:26:10 -070056 if [ -e "${static_dir}/archive" ]; then
57 unlink "${static_dir}/archive"
58 fi
59
Chris Sosacf1b0682012-06-08 19:58:59 -070060 /etc/init.d/apache2 restart
61}
62
63main $@