setup_dev_autotest.sh revision e61dd81426d6a83f975ae8ef4c5af6e12c8508e3
1cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar#!/bin/bash 2d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov# 3d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 4d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov# Use of this source code is governed by a BSD-style license that can be 5d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov# found in the LICENSE file. 6d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov 7d5047cb9f7f207798e1729911daa6d3752b668e3Anton KorobeynikovUSAGE="Usage: setup_dev_autotest.sh [-p <password>] [-a </path/to/autotest>]" 8d5047cb9f7f207798e1729911daa6d3752b668e3Anton KorobeynikovHELP="${USAGE}\n\n\ 9d5047cb9f7f207798e1729911daa6d3752b668e3Anton KorobeynikovInstall and configure software needed to run autotest locally.\n\ 10d5047cb9f7f207798e1729911daa6d3752b668e3Anton KorobeynikovIf you're just working on tests, you do not need to run this.\n\n\ 11d5047cb9f7f207798e1729911daa6d3752b668e3Anton KorobeynikovOptions:\n\ 12d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov -p Desired Autotest DB password\n\ 13d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov -a Absolute path to autotest source tree.\n" 1437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 1537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen HinesAUTOTEST_DIR= 16d5047cb9f7f207798e1729911daa6d3752b668e3Anton KorobeynikovPASSWD= 17d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikovwhile getopts ":p:a:h" opt; do 18d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov case $opt in 19d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov a) 20d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov AUTOTEST_DIR=$OPTARG 21d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov ;; 22d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov p) 23d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov PASSWD=$OPTARG 242d24e2a396a1d211baaeedf32148a3b657240170David Blaikie ;; 252d24e2a396a1d211baaeedf32148a3b657240170David Blaikie h) 26d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov echo -e "${HELP}" >&2 27d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov exit 0 28d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov ;; 29d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov \?) 3006ccca5f70ef5f9c3e4add60b6fc842916705029Anton Korobeynikov echo "Invalid option: -$OPTARG" >&2 3106ccca5f70ef5f9c3e4add60b6fc842916705029Anton Korobeynikov echo "${USAGE}" >&2 3206ccca5f70ef5f9c3e4add60b6fc842916705029Anton Korobeynikov exit 1 330ae61240341ca76e1329f251c64d2f475fa89278Anton Korobeynikov ;; 340ae61240341ca76e1329f251c64d2f475fa89278Anton Korobeynikov :) 350ae61240341ca76e1329f251c64d2f475fa89278Anton Korobeynikov echo "Option -$OPTARG requires an argument." >&2 36d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov echo "${USAGE}" >&2 37d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov exit 1 38d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov ;; 392392efef1bd2599231ab659dd6ba4233bf5df94cDan Gohman esac 4006ccca5f70ef5f9c3e4add60b6fc842916705029Anton Korobeynikovdone 41d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov 42d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikovif [ -z ${PASSWD} ]; then 43d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov read -s -p "Autotest DB password: " PASSWD 4406ccca5f70ef5f9c3e4add60b6fc842916705029Anton Korobeynikov echo 4506ccca5f70ef5f9c3e4add60b6fc842916705029Anton Korobeynikov if [ -z ${PASSWD} ]; then 4606ccca5f70ef5f9c3e4add60b6fc842916705029Anton Korobeynikov echo "Empty passwords not allowed." >&2 470ae61240341ca76e1329f251c64d2f475fa89278Anton Korobeynikov exit 1 480ae61240341ca76e1329f251c64d2f475fa89278Anton Korobeynikov fi 490ae61240341ca76e1329f251c64d2f475fa89278Anton Korobeynikov read -s -p "Re-enter password: " PASSWD2 50d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov echo 51d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov if [ ${PASSWD} != ${PASSWD2} ]; then 52d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov echo "Passwords don't match." >&2 53d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov exit 1 54d5047cb9f7f207798e1729911daa6d3752b668e3Anton Korobeynikov fi 55fi 56 57if [ -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 63fi 64 65SHADOW_CONFIG_PATH="${AUTOTEST_DIR}/shadow_config.ini" 66echo "Autotest supports local overrides of global configuration through a " 67echo "'shadow' configuration file. Setting one up for you now." 68if [ -f ${SHADOW_CONFIG_PATH} ]; then 69 clobber= 70 while read -n 1 -p "Clobber existing shadow config? [Y/n]: " clobber; do 71 echo 72 if [[ -z ${clobber} || $(echo ${clobber} | egrep -qi 'y|n') -eq 0 ]]; then 73 break 74 fi 75 echo "Please enter y or n." 76 done 77 if [[ ${clobber} = 'n' || ${clobber} = 'N' ]]; then 78 echo "Refusing to clobber existing shadow_config.ini." 79 exit 0 80 fi 81 echo "Clobbering existing shadow_config.ini." 82fi 83 84cat > "${SHADOW_CONFIG_PATH}" <<EOF 85[AUTOTEST_WEB] 86host: localhost 87password: ${PASSWD} 88readonly_host: localhost 89readonly_user: chromeosqa-admin 90readonly_password: ${PASSWD} 91 92[SERVER] 93hostname: localhost 94EOF 95echo -e "Done!\n" 96 97echo "Installing needed Ubuntu packages..." 98PKG_LIST="mysql-server mysql-common libapache2-mod-python python-mysqldb \ 99gnuplot apache2-mpm-prefork unzip python-imaging libpng12-dev libfreetype6-dev \ 100sqlite3 python-pysqlite2 git-core pbzip2 openjdk-6-jre openjdk-6-jdk \ 101python-crypto python-dev subversion build-essential python-setuptools" 102 103if ! sudo apt-get install -y ${PKG_LIST}; then 104 echo "Could not install packages: $?" 105 exit 1 106fi 107echo -e "Done!\n" 108 109echo -n "Setting up Database: chromeos_autotest_db in MySQL..." 110SQL_COMMAND="create database chromeos_autotest_db; \ 111grant all privileges on chromeos_autotest_db.* TO \ 112'chromeosqa-admin'@'%' identified by '${PASSWD}'; \ 113FLUSH PRIVILEGES;" 114 115if mysql -u root -e ';' 2> /dev/null ; then 116 PASSWD_STRING= 117elif mysql -u root -p"${PASSWD}" -e ';' 2> /dev/null ; then 118 PASSWD_STRING="-p${PASSWD}" 119else 120 PASSWD_STRING="-p" 121fi 122 123set -e 124 125mysql -u root "${PASSWD_STRING}" -e "${SQL_COMMAND}" 126echo -e "Done!\n" 127 128AT_DIR=/usr/local/autotest 129echo -n "Bind-mounting your autotest dir at ${AT_DIR}..." 130sudo mkdir -p "${AT_DIR}" 131sudo mount --bind "${AUTOTEST_DIR}" "${AT_DIR}" 132echo -e "Done!\n" 133 134EXISTING_MOUNT=$(egrep "/.+[[:space:]]${AT_DIR}" /etc/fstab || /bin/true) 135if [ -n "${EXISTING_MOUNT}" ]; then 136 echo "${EXISTING_MOUNT}" | awk '{print $1 " already automounting at " $2}' 137 echo "We won't update /etc/fstab, but you should have a line line this:" 138 echo -e "${AUTOTEST_DIR}\t${AT_DIR}\tbind defaults,bind\t0\t0" 139else 140 echo -n "Adding aforementioned bind-mount to /etc/fstab..." 141 # Is there a better way to elevate privs and do a redirect? 142 sudo su -c \ 143 "echo -e '${AUTOTEST_DIR}\t${AT_DIR}\tbind defaults,bind\t0\t0' \ 144 >> /etc/fstab" 145 echo -e "Done!\n" 146fi 147 148echo -n "Reticulating splines..." 149"${AT_DIR}"/utils/build_externals.py &> /dev/null 150"${AT_DIR}"/utils/compile_gwt_clients.py -a &> /dev/null 151echo -e "Done!\n" 152 153echo "Populating autotest mysql DB..." 154"${AT_DIR}"/database/migrate.py sync 155"${AT_DIR}"/frontend/manage.py syncdb 156# You may have to run this twice. 157"${AT_DIR}"/frontend/manage.py syncdb 158"${AT_DIR}"/utils/test_importer.py 159echo -e "Done!\n" 160 161echo "Configuring apache to run the autotest web interface..." 162sudo ln -sf "${AT_DIR}"/apache/apache-conf \ 163 /etc/apache2/sites-available/autotest-server 164# disable currently active default 165sudo a2dissite default 166# enable autotest server 167sudo a2ensite autotest-server 168# Enable rewrite module 169sudo a2enmod rewrite 170# Setup permissions so that Apache web user can read the proper files. 171chmod -R o+r "${AT_DIR}" 172find "${AT_DIR}"/ -type d | xargs chmod o+x 173chmod o+x "${AT_DIR}"/tko/*.cgi 174# restart server 175sudo /etc/init.d/apache2 restart 176 177echo "Browse to http://localhost to see if Autotest is working." 178echo "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" 179