3
## This is the script jenkins should run to provision a device in the lab
7
BASEDIR=$(dirname $(readlink -f $0))
8
export PATH=${BASEDIR}/../utils/host:${PATH}
10
RESDIR=`pwd`/clientlogs
12
NETWORK_FILE="${NETWORK_FILE-${HOME}/.ubuntu-ci/wifi.conf}"
14
IMAGE_OPT="${IMAGE_OPT---bootstrap --developer-mode --channel ubuntu-touch/devel-proposed}"
15
UUID="${UUID-$(uuidgen -r)}"
16
PHABLET_PASSWORD="${PHABLET_PASSWORD-0000}"
20
usage: $0 [-s ANDROID_SERIAL] [-n NETWORK_FILE] [-P ppa] [-p package] [-r revision] [-w]
22
Provisions the given device with the latest build
26
-s Specify the serial of the device to install
27
-n Select network file
28
-P add the ppa to the target (can be repeated)
29
-D add a debian package dir to the target (can be repeated)
30
-p add the package to the target (can be repeated)
31
-r Specify the image revision to flash
32
-w make the system writeable (implied with -p and -P arguments)
38
# mark the version we installed in /home/phablet/.ci-[uuid,flash-args]
39
# adb shell messes up \n's with \r\n's so do the whole of the regex on the target
40
IMAGEVER=$(adb shell "sudo system-image-cli -i | sed -n -e 's/version version: \([0-9]*\)/\1/p' -e 's/version ubuntu: \([0-9]*\)/\1/p' -e 's/version device: \([0-9]*\)/\1/p' | paste -s -d:")
41
CHAN=$(adb shell "sudo system-image-cli -i | sed -n -e 's/channel: \(.*\)/\1/p' | paste -s -d:")
42
REV=$(echo $IMAGEVER | cut -d: -f1)
43
echo "$IMAGE_OPT" | grep -q "\-\-revision" || IMAGE_OPT="${IMAGE_OPT} --revision $REV"
44
echo "$IMAGE_OPT" | grep -q "\-\-channel" || IMAGE_OPT="${IMAGE_OPT} --channel $CHAN"
45
adb shell "echo '${IMAGEVER}' > /home/phablet/.ci-version"
46
echo $UUID > $RESDIR/.ci-uuid
47
adb push $RESDIR/.ci-uuid /home/phablet/
48
cat > $RESDIR/.ci-flash-args <<EOF
51
adb push $RESDIR/.ci-flash-args /home/phablet/.ci-flash-args
52
echo $CUSTOMIZE > $RESDIR/.ci-customizations
53
adb push $RESDIR/.ci-customizations /home/phablet/.ci-customizations
61
log "SETTING HWCLOCK TO CURRENT TIME"
62
# Use ip for ntp.ubuntu.com in case resolving doesn't work yet
63
adb-shell sudo ntpdate 91.189.94.4 || log "WARNING: could not set ntpdate"
64
# hwclock sync has to happen after we set writable image
65
adb-shell sudo hwclock -w || log "WARNING: could not sync hwclock"
66
log "Current date on device is:"
68
log "Current hwclock on device is:"
69
adb shell sudo hwclock
81
if [ $loopcnt -lt $loops ] ; then
83
echo "Retry [$loopcnt/$loops] after $timeout seconds..."
86
echo Failed on \'$cmd\' after $loops retries
94
# In CI, we've seen cases whre 'adb reboot bootloader' will just
95
# reboot the device and not enter the bootloader. Adding another
96
# reboot and retrying was found to be a successful workaround:
97
# https://bugs.launchpad.net/ubuntu/+source/android-tools/+bug/1359488
99
# We only want to do this if we know ANDROID_SERIAL. Attempting
100
# to guess might end up flashing the wrong device.
102
log "Attempting adb reboot bootloader"
103
adb reboot bootloader
104
if [ -n "${ANDROID_SERIAL}" ] ; then
105
# Entering the bootloader should take < 10 seconds, add some
106
# padding for device variance.
108
if ! fastboot devices | grep -q "${ANDROID_SERIAL}"; then
109
log "Device not in fastboot after adb reboot bootloader"
110
# After a failed 'reboot bootloader' attempt, a reboot
111
# is used to get the device back to a saner state.
120
log "FLASHING DEVICE"
121
# Use a 60 second retry loop for reboot_bootloader.
122
# If the attempt failed, it may take nearly 60 seconds to complete
123
# the reboot cycle to get the device back to a sane state.
124
retry 60 3 reboot_bootloader
125
# Use a 10 second retry loop for ubuntu-device-flash.
126
# Most failures appear to be transient and work with an immediate
128
retry 10 3 ubuntu-device-flash touch --password $PHABLET_PASSWORD $IMAGE_OPT
130
sleep 60 #give the system a little time
133
while getopts i:s:n:P:D:p:r:wh opt; do
143
export ANDROID_SERIAL=$OPTARG
149
# making this a non-zero length string enables the logic
153
CUSTOMIZE="$CUSTOMIZE --ppa $OPTARG"
156
CUSTOMIZE="$CUSTOMIZE --package-dir $OPTARG"
159
CUSTOMIZE="$CUSTOMIZE -p $OPTARG"
162
IMAGE_OPT="$IMAGE_OPT --revision $OPTARG"
168
if [ -z $ANDROID_SERIAL ] ; then
169
# ensure we only have one device attached
170
lines=$(adb devices | wc -l)
171
if [ $lines -gt 3 ] ; then
172
echo "ERROR: More than one device attached, please use -s option"
179
if [ ! -f $NETWORK_FILE ] && [ -z $USE_EMULATOR ] ; then
180
echo "ERROR: NETWORK_FILE, $NETWORK_FILE, not found"
185
[ -d $RESDIR ] && rm -rf $RESDIR
188
if [ -z $USE_EMULATOR ] ; then
191
log "CREATING EMULATOR"
192
ubuntu-emulator destroy --yes $ANDROID_SERIAL || true
193
sudo ubuntu-emulator create $ANDROID_SERIAL $IMAGE_OPT
194
${BASEDIR}/reboot-and-wait
197
if [ -z $USE_EMULATOR ] ; then
198
log "SETTING UP WIFI"
199
retry 60 5 adb-shell 'sudo -iu phablet env |grep UPSTART_SESSION=unix'
200
retry 60 5 phablet-network -n $NETWORK_FILE
203
phablet-config welcome-wizard --disable
205
if [ -n "$CUSTOMIZE" ] ; then
206
log "CUSTOMIZING IMAGE"
207
phablet-config writable-image -r ${PHABLET_PASSWORD} $CUSTOMIZE
210
log "SETTING UP SUDO"
211
adb shell "echo ${PHABLET_PASSWORD} |sudo -S bash -c 'echo phablet ALL=\(ALL\) NOPASSWD: ALL > /etc/sudoers.d/phablet && chmod 600 /etc/sudoers.d/phablet'"
213
# FIXME: Can't do this through phablet-config for now because it needs auth
214
# phablet-config edges-intro --disable
215
adb shell "sudo dbus-send --system --print-reply --dest=org.freedesktop.Accounts /org/freedesktop/Accounts/User32011 org.freedesktop.DBus.Properties.Set string:com.canonical.unity.AccountsService string:demo-edges variant:boolean:false"
217
if [ -n "${SKIP_CLICK}" ]; then
218
log "SKIPPING CLICK PACKAGE SETUP AS REQUESTED"
220
log "SETTING UP CLICK PACKAGES"
222
channel_name=$(adb shell "sudo system-image-cli -i | sed -n -e 's/channel: \(.*\)/\1/p' | paste -s -d:")
223
# Before running phablet-click-test setup, we need to make sure the
224
# session is available
225
retry 60 5 adb-shell 'sudo -iu phablet env |grep UPSTART_SESSION=unix'
227
# FIXME: workaround for phablet-click-test-setup to pull the right sources
228
if [[ $channel_name == *rtm* ]] ; then
229
CLICK_TEST_OPTS="--distribution ubuntu-rtm --series 14.09"
231
phablet-click-test-setup $CLICK_TEST_OPTS
234
# get our target-based utilities into our PATH
235
adb push ${BASEDIR}/../utils/target /home/phablet/bin