blob: daa913e06c660bfaa3b37149ad76a301c099dd65 [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)"
Fang Dengae730b62015-04-20 11:26:59 -070019codename=$(cat /etc/lsb-release | grep DISTRIB_CODENAME | awk -F '=' '{print $2}')
Chris Sosacf1b0682012-06-08 19:58:59 -070020
21set -e
22
23main () {
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 Dengae730b62015-04-20 11:26:59 -070031 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 Sosacf1b0682012-06-08 19:58:59 -070036
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 Sosa28be7db2012-06-13 16:26:10 -070047 ln -sf "${APACHE_CONFIG}"/mods-available/rewrite.load \
48 "${APACHE_CONFIG}"/mods-enabled
Chris Sosacf1b0682012-06-08 19:58:59 -070049
Fang Dengae730b62015-04-20 11:26:59 -070050 # 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 Sosacf1b0682012-06-08 19:58:59 -070054 # Setup devserver archive location.
55 local image_root="${DEFAULT_IMAGE_ROOT}"
Chris Sosabc5d0fa2013-07-11 14:14:45 -070056 [ -n "${1}" ] && image_root="$(readlink -f "${1}")"
Chris Sosacf1b0682012-06-08 19:58:59 -070057
58 local static_dir="${ARCHIVE_ROOT}"/static
Chris Sosabc5d0fa2013-07-11 14:14:45 -070059 if [ -h "${static_dir}" ]; then
Chris Sosacf1b0682012-06-08 19:58:59 -070060 unlink "${static_dir}"
61 fi
62
63 ln -sf "${image_root}" "${static_dir}"
64
Chris Sosa28be7db2012-06-13 16:26:10 -070065 if [ -e "${static_dir}/archive" ]; then
66 unlink "${static_dir}/archive"
67 fi
68
Chris Sosacf1b0682012-06-08 19:58:59 -070069 /etc/init.d/apache2 restart
70}
71
72main $@