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. |
| 6 | |
| 7 | USAGE="Usage: setup_dev_autotest.sh [-p <password>] [-a </path/to/autotest>]" |
| 8 | HELP="${USAGE}\n\n\ |
| 9 | Install and configure software needed to run autotest locally.\n\ |
| 10 | If you're just working on tests, you do not need to run this.\n\n\ |
| 11 | Options:\n\ |
| 12 | -p Desired Autotest DB password\n\ |
| 13 | -a Absolute path to autotest source tree.\n" |
| 14 | |
| 15 | AUTOTEST_DIR= |
| 16 | PASSWD= |
| 17 | while getopts ":p:a:h" opt; do |
| 18 | case $opt in |
| 19 | a) |
| 20 | AUTOTEST_DIR=$OPTARG |
| 21 | ;; |
| 22 | p) |
| 23 | PASSWD=$OPTARG |
| 24 | ;; |
| 25 | h) |
| 26 | echo -e "${HELP}" >&2 |
| 27 | exit 0 |
| 28 | ;; |
| 29 | \?) |
| 30 | echo "Invalid option: -$OPTARG" >&2 |
| 31 | echo "${USAGE}" >&2 |
| 32 | exit 1 |
| 33 | ;; |
| 34 | :) |
| 35 | echo "Option -$OPTARG requires an argument." >&2 |
| 36 | echo "${USAGE}" >&2 |
| 37 | exit 1 |
| 38 | ;; |
| 39 | esac |
| 40 | done |
| 41 | |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 42 | if [ -z "${PASSWD}" ]; then |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 43 | read -s -p "Autotest DB password: " PASSWD |
| 44 | echo |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 45 | if [ -z "${PASSWD}" ]; then |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 46 | echo "Empty passwords not allowed." >&2 |
| 47 | exit 1 |
| 48 | fi |
| 49 | read -s -p "Re-enter password: " PASSWD2 |
| 50 | echo |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 51 | if [ "${PASSWD}" != "${PASSWD2}" ]; then |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 52 | echo "Passwords don't match." >&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | fi |
| 56 | |
| 57 | if [ -z "${AUTOTEST_DIR}" ]; then |
| 58 | CANDIDATE=$(dirname "$(readlink -f "$0")" | egrep -o '(/[^/]+)*/files') |
| 59 | read -p "Enter autotest dir [${CANDIDATE}]: " AUTOTEST_DIR |
| 60 | if [ -z "${AUTOTEST_DIR}" ]; then |
| 61 | AUTOTEST_DIR="${CANDIDATE}" |
| 62 | fi |
| 63 | fi |
| 64 | |
| 65 | SHADOW_CONFIG_PATH="${AUTOTEST_DIR}/shadow_config.ini" |
| 66 | echo "Autotest supports local overrides of global configuration through a " |
| 67 | echo "'shadow' configuration file. Setting one up for you now." |
| 68 | if [ -f ${SHADOW_CONFIG_PATH} ]; then |
| 69 | clobber= |
| 70 | while read -n 1 -p "Clobber existing shadow config? [Y/n]: " clobber; do |
| 71 | echo |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 72 | if [[ -z "${clobber}" || $(echo ${clobber} | egrep -qi 'y|n') -eq 0 ]]; then |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 73 | break |
| 74 | fi |
| 75 | echo "Please enter y or n." |
| 76 | done |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 77 | if [[ "${clobber}" = 'n' || "${clobber}" = 'N' ]]; then |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 78 | echo "Refusing to clobber existing shadow_config.ini." |
| 79 | exit 0 |
| 80 | fi |
| 81 | echo "Clobbering existing shadow_config.ini." |
| 82 | fi |
| 83 | |
| 84 | cat > "${SHADOW_CONFIG_PATH}" <<EOF |
| 85 | [AUTOTEST_WEB] |
| 86 | host: localhost |
| 87 | password: ${PASSWD} |
Chris Masone | e61dd81 | 2012-01-10 18:04:21 -0800 | [diff] [blame] | 88 | readonly_host: localhost |
| 89 | readonly_user: chromeosqa-admin |
| 90 | readonly_password: ${PASSWD} |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 91 | |
| 92 | [SERVER] |
| 93 | hostname: localhost |
Chris Sosa | e418124 | 2012-09-10 16:54:30 -0700 | [diff] [blame] | 94 | |
| 95 | [SCHEDULER] |
| 96 | drones: localhost |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 97 | EOF |
| 98 | echo -e "Done!\n" |
| 99 | |
| 100 | echo "Installing needed Ubuntu packages..." |
| 101 | PKG_LIST="mysql-server mysql-common libapache2-mod-python python-mysqldb \ |
| 102 | gnuplot apache2-mpm-prefork unzip python-imaging libpng12-dev libfreetype6-dev \ |
| 103 | sqlite3 python-pysqlite2 git-core pbzip2 openjdk-6-jre openjdk-6-jdk \ |
Simran Basi | 3d18208 | 2012-09-07 10:15:25 -0700 | [diff] [blame] | 104 | python-crypto python-dev subversion build-essential python-setuptools \ |
| 105 | python-numpy python-scipy" |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 106 | |
| 107 | if ! sudo apt-get install -y ${PKG_LIST}; then |
| 108 | echo "Could not install packages: $?" |
| 109 | exit 1 |
| 110 | fi |
| 111 | echo -e "Done!\n" |
| 112 | |
Alex Miller | da3ecf4 | 2012-07-25 11:51:13 -0700 | [diff] [blame] | 113 | echo "Setting up Database: chromeos_autotest_db in MySQL..." |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 114 | if mysql -u root -e ';' 2> /dev/null ; then |
| 115 | PASSWD_STRING= |
| 116 | elif mysql -u root -p"${PASSWD}" -e ';' 2> /dev/null ; then |
| 117 | PASSWD_STRING="-p${PASSWD}" |
| 118 | else |
| 119 | PASSWD_STRING="-p" |
| 120 | fi |
| 121 | |
Alex Miller | da3ecf4 | 2012-07-25 11:51:13 -0700 | [diff] [blame] | 122 | CLOBBERDB= |
| 123 | EXISTING_DATABASE=$(mysql -u root "${PASSWD_STRING}" -e "SELECT SCHEMA_NAME \ |
| 124 | FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'chromeos_autotest_db'") |
| 125 | if [ -n "${EXISTING_DATABASE}" ]; then |
| 126 | while read -n 1 -p "Clobber existing MySQL database? [y/N]: " CLOBBERDB; do |
| 127 | echo |
Richard Barnette | 23ef442 | 2012-11-02 13:46:20 -0700 | [diff] [blame] | 128 | if [[ -z "${CLOBBERDB}" || |
| 129 | $(echo ${CLOBBERDB} | egrep -qi 'y|n') -eq 0 ]]; then |
Alex Miller | da3ecf4 | 2012-07-25 11:51:13 -0700 | [diff] [blame] | 130 | break |
| 131 | fi |
| 132 | echo "Please enter y or n." |
| 133 | done |
| 134 | else |
| 135 | CLOBBERDB='y' |
| 136 | fi |
| 137 | |
| 138 | SQL_COMMAND="drop database if exists chromeos_autotest_db; \ |
| 139 | create database chromeos_autotest_db; \ |
| 140 | grant all privileges on chromeos_autotest_db.* TO \ |
Simran Basi | 3d18208 | 2012-09-07 10:15:25 -0700 | [diff] [blame] | 141 | 'chromeosqa-admin'@'localhost' identified by '${PASSWD}'; \ |
Alex Miller | da3ecf4 | 2012-07-25 11:51:13 -0700 | [diff] [blame] | 142 | FLUSH PRIVILEGES;" |
| 143 | |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 144 | set -e |
| 145 | |
Alex Miller | da3ecf4 | 2012-07-25 11:51:13 -0700 | [diff] [blame] | 146 | if [[ "${CLOBBERDB}" = 'y' || "${CLOBBERDB}" = 'Y' ]]; then |
| 147 | mysql -u root "${PASSWD_STRING}" -e "${SQL_COMMAND}" |
| 148 | fi |
Chris Masone | 2aa5533 | 2011-12-30 14:41:07 -0800 | [diff] [blame] | 149 | echo -e "Done!\n" |
| 150 | |
| 151 | AT_DIR=/usr/local/autotest |
| 152 | echo -n "Bind-mounting your autotest dir at ${AT_DIR}..." |
| 153 | sudo mkdir -p "${AT_DIR}" |
| 154 | sudo mount --bind "${AUTOTEST_DIR}" "${AT_DIR}" |
| 155 | echo -e "Done!\n" |
| 156 | |
| 157 | EXISTING_MOUNT=$(egrep "/.+[[:space:]]${AT_DIR}" /etc/fstab || /bin/true) |
| 158 | if [ -n "${EXISTING_MOUNT}" ]; then |
| 159 | echo "${EXISTING_MOUNT}" | awk '{print $1 " already automounting at " $2}' |
| 160 | echo "We won't update /etc/fstab, but you should have a line line this:" |
| 161 | echo -e "${AUTOTEST_DIR}\t${AT_DIR}\tbind defaults,bind\t0\t0" |
| 162 | else |
| 163 | echo -n "Adding aforementioned bind-mount to /etc/fstab..." |
| 164 | # Is there a better way to elevate privs and do a redirect? |
| 165 | sudo su -c \ |
| 166 | "echo -e '${AUTOTEST_DIR}\t${AT_DIR}\tbind defaults,bind\t0\t0' \ |
| 167 | >> /etc/fstab" |
| 168 | echo -e "Done!\n" |
| 169 | fi |
| 170 | |
| 171 | echo -n "Reticulating splines..." |
| 172 | "${AT_DIR}"/utils/build_externals.py &> /dev/null |
| 173 | "${AT_DIR}"/utils/compile_gwt_clients.py -a &> /dev/null |
| 174 | echo -e "Done!\n" |
| 175 | |
| 176 | echo "Populating autotest mysql DB..." |
| 177 | "${AT_DIR}"/database/migrate.py sync |
| 178 | "${AT_DIR}"/frontend/manage.py syncdb |
| 179 | # You may have to run this twice. |
| 180 | "${AT_DIR}"/frontend/manage.py syncdb |
| 181 | "${AT_DIR}"/utils/test_importer.py |
| 182 | echo -e "Done!\n" |
| 183 | |
| 184 | echo "Configuring apache to run the autotest web interface..." |
| 185 | sudo ln -sf "${AT_DIR}"/apache/apache-conf \ |
| 186 | /etc/apache2/sites-available/autotest-server |
| 187 | # disable currently active default |
| 188 | sudo a2dissite default |
| 189 | # enable autotest server |
| 190 | sudo a2ensite autotest-server |
| 191 | # Enable rewrite module |
| 192 | sudo a2enmod rewrite |
| 193 | # Setup permissions so that Apache web user can read the proper files. |
| 194 | chmod -R o+r "${AT_DIR}" |
| 195 | find "${AT_DIR}"/ -type d | xargs chmod o+x |
| 196 | chmod o+x "${AT_DIR}"/tko/*.cgi |
| 197 | # restart server |
| 198 | sudo /etc/init.d/apache2 restart |
| 199 | |
| 200 | echo "Browse to http://localhost to see if Autotest is working." |
| 201 | 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" |