Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 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. |
Simran Basi | 79b1a7b | 2013-02-13 11:16:00 -0800 | [diff] [blame] | 6 | set -e |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 7 | |
Prathmesh Prabhu | 864de13 | 2015-04-08 14:45:13 -0700 | [diff] [blame] | 8 | USAGE='Usage: setup_dev_autotest.sh [-pavnm]' |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 9 | HELP="${USAGE}\n\n\ |
| 10 | Install and configure software needed to run autotest locally.\n\ |
| 11 | If you're just working on tests, you do not need to run this.\n\n\ |
| 12 | Options:\n\ |
Prathmesh Prabhu | 864de13 | 2015-04-08 14:45:13 -0700 | [diff] [blame] | 13 | -p Desired Autotest DB password. Must be non-empty.\n\ |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 14 | -a Absolute path to autotest source tree.\n\ |
| 15 | -v Show info logging from build_externals.py and compile_gwt_clients.py \n\ |
Jakob Juelich | 1c53ae7 | 2014-09-10 11:32:16 -0700 | [diff] [blame] | 16 | -n Non-interactive mode, doesn't ask for any user input. |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 17 | Requires -p and -a to be set.\n\ |
MK Ryu | 50ab33e | 2015-08-28 14:28:37 -0700 | [diff] [blame] | 18 | -m Allow remote access for database." |
Jakob Juelich | 1c53ae7 | 2014-09-10 11:32:16 -0700 | [diff] [blame] | 19 | |
| 20 | function get_y_or_n_interactive { |
| 21 | local ret |
| 22 | while true; do |
| 23 | read -p "$2" yn |
| 24 | case $yn in |
| 25 | [Yy]* ) ret="y"; break;; |
| 26 | [Nn]* ) ret="n"; break;; |
| 27 | * ) echo "Please enter y or n.";; |
| 28 | esac |
| 29 | done |
| 30 | eval $1="'$ret'" |
| 31 | } |
| 32 | |
| 33 | function get_y_or_n { |
| 34 | local ret=$3 |
| 35 | if [ "${noninteractive}" = "FALSE" ]; then |
| 36 | get_y_or_n_interactive sub "$2" |
| 37 | ret=$sub |
| 38 | fi |
| 39 | eval $1="'$ret'" |
| 40 | } |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 41 | |
| 42 | AUTOTEST_DIR= |
| 43 | PASSWD= |
Michael Liang | b6a78f4 | 2014-07-11 15:05:30 -0700 | [diff] [blame] | 44 | verbose="FALSE" |
Jakob Juelich | 1c53ae7 | 2014-09-10 11:32:16 -0700 | [diff] [blame] | 45 | noninteractive="FALSE" |
MK Ryu | 50ab33e | 2015-08-28 14:28:37 -0700 | [diff] [blame] | 46 | remotedb="FALSE" |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 47 | while getopts ":p:a:vnmh" opt; do |
MK Ryu | 50ab33e | 2015-08-28 14:28:37 -0700 | [diff] [blame] | 48 | case ${opt} in |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 49 | a) |
| 50 | AUTOTEST_DIR=$OPTARG |
| 51 | ;; |
| 52 | p) |
| 53 | PASSWD=$OPTARG |
| 54 | ;; |
Michael Liang | b6a78f4 | 2014-07-11 15:05:30 -0700 | [diff] [blame] | 55 | v) |
| 56 | verbose="TRUE" |
| 57 | ;; |
Jakob Juelich | 1c53ae7 | 2014-09-10 11:32:16 -0700 | [diff] [blame] | 58 | n) |
| 59 | noninteractive="TRUE" |
| 60 | ;; |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 61 | m) |
MK Ryu | 50ab33e | 2015-08-28 14:28:37 -0700 | [diff] [blame] | 62 | remotedb="TRUE" |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 63 | ;; |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 64 | h) |
| 65 | echo -e "${HELP}" >&2 |
| 66 | exit 0 |
| 67 | ;; |
| 68 | \?) |
| 69 | echo "Invalid option: -$OPTARG" >&2 |
Prathmesh Prabhu | 864de13 | 2015-04-08 14:45:13 -0700 | [diff] [blame] | 70 | echo -e "${HELP}" >&2 |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 71 | exit 1 |
| 72 | ;; |
| 73 | :) |
| 74 | echo "Option -$OPTARG requires an argument." >&2 |
Prathmesh Prabhu | 864de13 | 2015-04-08 14:45:13 -0700 | [diff] [blame] | 75 | echo -e "${HELP}" >&2 |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 76 | exit 1 |
| 77 | ;; |
| 78 | esac |
| 79 | done |
| 80 | |
Prathmesh Prabhu | 864de13 | 2015-04-08 14:45:13 -0700 | [diff] [blame] | 81 | if [[ $EUID -eq 0 ]]; then |
| 82 | echo "Running with sudo / as root is not recommended" |
| 83 | get_y_or_n verify "Continue as root? [y/N]: " "n" |
| 84 | if [[ "${verify}" = 'n' ]]; then |
| 85 | echo "Bailing!" |
| 86 | exit 1 |
| 87 | fi |
| 88 | fi |
Jakob Juelich | 1c53ae7 | 2014-09-10 11:32:16 -0700 | [diff] [blame] | 89 | |
| 90 | if [ "${noninteractive}" = "TRUE" ]; then |
| 91 | if [ -z "${AUTOTEST_DIR}" ]; then |
| 92 | echo "-a must be specified in non-interactive mode." >&2 |
| 93 | exit 1 |
| 94 | fi |
| 95 | if [ -z "${PASSWD}" ]; then |
| 96 | echo "-p must be specified in non-interactive mode." >&2 |
| 97 | exit 1 |
| 98 | fi |
| 99 | fi |
| 100 | |
| 101 | |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 102 | if [ -z "${PASSWD}" ]; then |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 103 | read -s -p "Autotest DB password: " PASSWD |
| 104 | echo |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 105 | if [ -z "${PASSWD}" ]; then |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 106 | echo "Empty passwords not allowed." >&2 |
| 107 | exit 1 |
| 108 | fi |
| 109 | read -s -p "Re-enter password: " PASSWD2 |
| 110 | echo |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 111 | if [ "${PASSWD}" != "${PASSWD2}" ]; then |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 112 | echo "Passwords don't match." >&2 |
| 113 | exit 1 |
| 114 | fi |
| 115 | fi |
| 116 | |
| 117 | if [ -z "${AUTOTEST_DIR}" ]; then |
| 118 | CANDIDATE=$(dirname "$(readlink -f "$0")" | egrep -o '(/[^/]+)*/files') |
| 119 | read -p "Enter autotest dir [${CANDIDATE}]: " AUTOTEST_DIR |
| 120 | if [ -z "${AUTOTEST_DIR}" ]; then |
| 121 | AUTOTEST_DIR="${CANDIDATE}" |
| 122 | fi |
| 123 | fi |
| 124 | |
Aviv Keshet | 2c603d8 | 2013-05-24 10:31:59 -0700 | [diff] [blame] | 125 | |
| 126 | # Sanity check AUTOTEST_DIR. If it's null, or doesn't exist on the filesystem |
| 127 | # then die. |
| 128 | if [ -z "${AUTOTEST_DIR}" ]; then |
| 129 | echo "No AUTOTEST_DIR. Aborting script." |
| 130 | exit 1 |
| 131 | fi |
| 132 | |
| 133 | if [ ! -d "${AUTOTEST_DIR}" ]; then |
| 134 | echo "Directory " ${AUTOTEST_DIR} " does not exist. Aborting script." |
| 135 | exit 1 |
| 136 | fi |
| 137 | |
| 138 | |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 139 | SHADOW_CONFIG_PATH="${AUTOTEST_DIR}/shadow_config.ini" |
| 140 | echo "Autotest supports local overrides of global configuration through a " |
| 141 | echo "'shadow' configuration file. Setting one up for you now." |
Chris Sosa | 18c70b3 | 2013-02-15 14:12:43 -0800 | [diff] [blame] | 142 | CLOBBER=0 |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 143 | if [ -f ${SHADOW_CONFIG_PATH} ]; then |
Jakob Juelich | 1c53ae7 | 2014-09-10 11:32:16 -0700 | [diff] [blame] | 144 | get_y_or_n clobber "Clobber existing shadow config? [Y/n]: " "n" |
| 145 | if [[ "${clobber}" = 'n' ]]; then |
Chris Sosa | 18c70b3 | 2013-02-15 14:12:43 -0800 | [diff] [blame] | 146 | CLOBBER=1 |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 147 | echo "Refusing to clobber existing shadow_config.ini." |
Chris Sosa | 18c70b3 | 2013-02-15 14:12:43 -0800 | [diff] [blame] | 148 | else |
| 149 | echo "Clobbering existing shadow_config.ini." |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 150 | fi |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 151 | fi |
| 152 | |
Aviv Keshet | 2c603d8 | 2013-05-24 10:31:59 -0700 | [diff] [blame] | 153 | CROS_CHECKOUT=$(readlink -f ${AUTOTEST_DIR}/../../../..) |
| 154 | |
Chris Sosa | 18c70b3 | 2013-02-15 14:12:43 -0800 | [diff] [blame] | 155 | # Create clean shadow config if we're replacing it/creating a new one. |
| 156 | if [ $CLOBBER -eq 0 ]; then |
| 157 | cat > "${SHADOW_CONFIG_PATH}" <<EOF |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 158 | [AUTOTEST_WEB] |
| 159 | host: localhost |
| 160 | password: ${PASSWD} |
Chris Masone | e61dd81 | 2012-01-10 18:04:21 -0800 | [diff] [blame] | 161 | readonly_host: localhost |
| 162 | readonly_user: chromeosqa-admin |
| 163 | readonly_password: ${PASSWD} |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 164 | |
| 165 | [SERVER] |
| 166 | hostname: localhost |
Chris Sosa | e418124 | 2012-09-10 16:54:30 -0700 | [diff] [blame] | 167 | |
| 168 | [SCHEDULER] |
| 169 | drones: localhost |
Aviv Keshet | 2c603d8 | 2013-05-24 10:31:59 -0700 | [diff] [blame] | 170 | |
| 171 | [CROS] |
| 172 | source_tree: ${CROS_CHECKOUT} |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 173 | EOF |
Chris Sosa | 18c70b3 | 2013-02-15 14:12:43 -0800 | [diff] [blame] | 174 | echo -e "Done!\n" |
| 175 | fi |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 176 | |
| 177 | echo "Installing needed Ubuntu packages..." |
Shuqian Zhao | 13470bb | 2016-02-18 16:25:45 -0800 | [diff] [blame] | 178 | PKG_LIST="libapache2-mod-wsgi gnuplot apache2-mpm-prefork unzip \ |
| 179 | python-imaging libpng12-dev libfreetype6-dev \ |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 180 | sqlite3 python-pysqlite2 git-core pbzip2 openjdk-6-jre openjdk-6-jdk \ |
Simran Basi | 3d18208 | 2012-09-07 10:15:25 -0700 | [diff] [blame] | 181 | python-crypto python-dev subversion build-essential python-setuptools \ |
Justin Giorgi | 1214c77 | 2016-07-04 22:43:37 -0700 | [diff] [blame^] | 182 | python-numpy python-scipy libmysqlclient-dev" |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 183 | |
| 184 | if ! sudo apt-get install -y ${PKG_LIST}; then |
| 185 | echo "Could not install packages: $?" |
| 186 | exit 1 |
| 187 | fi |
| 188 | echo -e "Done!\n" |
| 189 | |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 190 | AT_DIR=/usr/local/autotest |
| 191 | echo -n "Bind-mounting your autotest dir at ${AT_DIR}..." |
| 192 | sudo mkdir -p "${AT_DIR}" |
| 193 | sudo mount --bind "${AUTOTEST_DIR}" "${AT_DIR}" |
| 194 | echo -e "Done!\n" |
| 195 | |
Fang Deng | af82bca | 2014-11-18 17:19:06 -0800 | [diff] [blame] | 196 | sudo chown -R "$(whoami)" "${AT_DIR}" |
| 197 | |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 198 | EXISTING_MOUNT=$(egrep "/.+[[:space:]]${AT_DIR}" /etc/fstab || /bin/true) |
| 199 | if [ -n "${EXISTING_MOUNT}" ]; then |
| 200 | echo "${EXISTING_MOUNT}" | awk '{print $1 " already automounting at " $2}' |
| 201 | echo "We won't update /etc/fstab, but you should have a line line this:" |
| 202 | echo -e "${AUTOTEST_DIR}\t${AT_DIR}\tbind defaults,bind\t0\t0" |
| 203 | else |
| 204 | echo -n "Adding aforementioned bind-mount to /etc/fstab..." |
| 205 | # Is there a better way to elevate privs and do a redirect? |
| 206 | sudo su -c \ |
| 207 | "echo -e '${AUTOTEST_DIR}\t${AT_DIR}\tbind defaults,bind\t0\t0' \ |
| 208 | >> /etc/fstab" |
| 209 | echo -e "Done!\n" |
| 210 | fi |
| 211 | |
| 212 | echo -n "Reticulating splines..." |
Michael Liang | b6a78f4 | 2014-07-11 15:05:30 -0700 | [diff] [blame] | 213 | |
| 214 | if [ "${verbose}" = "TRUE" ]; then |
| 215 | "${AT_DIR}"/utils/build_externals.py |
| 216 | "${AT_DIR}"/utils/compile_gwt_clients.py -a |
| 217 | else |
| 218 | "${AT_DIR}"/utils/build_externals.py &> /dev/null |
| 219 | "${AT_DIR}"/utils/compile_gwt_clients.py -a &> /dev/null |
| 220 | fi |
| 221 | |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 222 | echo -e "Done!\n" |
| 223 | |
Shuqian Zhao | 13470bb | 2016-02-18 16:25:45 -0800 | [diff] [blame] | 224 | echo "Start setting up Database..." |
| 225 | get_y_or_n clobberdb "Clobber MySQL database if it exists? [Y/n]: " "n" |
| 226 | opts_string="-p ${PASSWD} -a ${AT_DIR}" |
| 227 | if [[ "${clobberdb}" = 'y' ]]; then |
| 228 | opts_string="${opts_string} -c" |
| 229 | fi |
| 230 | if [[ "${remotedb}" = 'TRUE' ]]; then |
| 231 | opts_string="${opts_string} -m" |
| 232 | fi |
| 233 | "${AT_DIR}"/site_utils/setup_db.sh ${opts_string} |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 234 | |
Dan Shi | 7f0c183 | 2014-10-27 16:05:57 -0700 | [diff] [blame] | 235 | echo -e "Done!\n" |
| 236 | |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 237 | echo "Configuring apache to run the autotest web interface..." |
Simran Basi | 508ee92 | 2013-11-18 13:43:40 -0800 | [diff] [blame] | 238 | if [ ! -d /etc/apache2/run ]; then |
| 239 | sudo mkdir /etc/apache2/run |
| 240 | fi |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 241 | sudo ln -sf "${AT_DIR}"/apache/apache-conf \ |
Dan Shi | 1880849 | 2014-11-05 10:25:26 -0800 | [diff] [blame] | 242 | /etc/apache2/sites-available/autotest-server.conf |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 243 | # Disable currently active default |
Michael Janssen | a742761 | 2014-11-14 15:44:39 -0800 | [diff] [blame] | 244 | sudo a2dissite 000-default default || true |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 245 | # Enable autotest server |
Dan Shi | 1880849 | 2014-11-05 10:25:26 -0800 | [diff] [blame] | 246 | sudo a2ensite autotest-server.conf |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 247 | # Enable rewrite module |
| 248 | sudo a2enmod rewrite |
Scott Zawalski | a5745e9 | 2013-05-09 10:42:27 -0400 | [diff] [blame] | 249 | # Enable wsgi |
| 250 | sudo a2enmod wsgi |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 251 | # Enable version |
Michael Janssen | a742761 | 2014-11-14 15:44:39 -0800 | [diff] [blame] | 252 | # built-in on trusty |
| 253 | sudo a2enmod version || true |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 254 | # Enable headers |
Dan Shi | a85f6d8 | 2014-10-01 08:58:01 -0700 | [diff] [blame] | 255 | sudo a2enmod headers |
MK Ryu | c96e959 | 2015-03-05 14:09:03 -0800 | [diff] [blame] | 256 | # Enable cgid |
| 257 | sudo a2enmod cgid |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 258 | # Setup permissions so that Apache web user can read the proper files. |
| 259 | chmod -R o+r "${AT_DIR}" |
Alex Miller | 5e7b254 | 2013-02-13 14:24:04 -0800 | [diff] [blame] | 260 | find "${AT_DIR}"/ -type d -print0 | xargs --null chmod o+x |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 261 | chmod o+x "${AT_DIR}"/tko/*.cgi |
| 262 | # restart server |
| 263 | sudo /etc/init.d/apache2 restart |
| 264 | |
Dan Shi | dca745a | 2015-05-07 13:36:26 -0700 | [diff] [blame] | 265 | # Setup lxc and base container for server-side packaging support. |
| 266 | sudo apt-get install lxc -y |
| 267 | sudo python "${AT_DIR}"/site_utils/lxc.py -s |
| 268 | |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 269 | echo "Browse to http://localhost to see if Autotest is working." |
| 270 | echo "For further necessary set up steps, see https://sites.google.com/a/chromium.org/dev/chromium-os/testing/autotest-developer-faq/setup-autotest-server?pli=1" |