blob: 910d1eaac5de1763708e43f73b9bc902c2bba2b2 [file] [log] [blame]
J. Richard Barnettef5b0e872012-10-17 17:12:231#!/bin/bash
2# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6if [ $# -lt 2 ]; then
7 echo "usage: $(basename $0) <build> <board> ..." >&2
8 echo "Example:" >&2
9 echo " $(basename $0) R24-3052.0.0 lumpy lucas" >&2
10 exit 1
11fi
12
13set -e
14
15cd ~chromeos-test/images/servo-images
16
17# Determine the URL for the source image in googlestorage.
18# arg 1: Name of build (e.g. "R24-3052.0.0")
19# arg 2: Name of board (e.g. "lumpy")
20# output: URL of the image for gsutil
21select_source_url() {
22 local build="$1"
23 local board="$2"
24
25 # Older builds keep a collection of files in a ZIP archive named
26 # "image.zip". More recent builds also have an archive named
27 # "chromiumos_test_image.zip" with just the test image in it. The
28 # individual test image ZIP archive is smaller, so we prefer that
29 # one when we have a choice.
30 #
31 local url_base="gs://chromeos-image-archive/$board-release/$build"
32 local url_fullzip="$url_base/image.zip"
33 local url_singlezip="$url_base/chromiumos_test_image.zip"
34
35 if gsutil getacl "$url_singlezip" >/dev/null 2>&1; then
36 echo "$url_singlezip"
37 else
38 echo "$url_fullzip"
39 fi
40}
41
42# Deploy a single image for a single board.
43# arg 1: Name of build (e.g. "R24-3052.0.0")
44# arg 2: Name of board (e.g. "lumpy")
45deploy_image() {
46 local build="$1"
47 local board="$2"
48
49 local image_dir="$build-$board"
50 local deployed_image="${board}_test_image.bin"
51
52 local old_image
53 if [ -h "$deployed_image" ]; then
54 old_image=$(readlink "$deployed_image")
55 fi
56
57 local url=$(select_source_url "$build" "$board")
58 local zip="$image_dir/image.zip"
59 local bin=chromiumos_test_image.bin
60
61 mkdir -p "$image_dir"
62 gsutil cp "$url" "$zip"
63 unzip -o -d "$image_dir" "$zip" "$bin"
64 ln -sf "$image_dir/$bin" "$deployed_image"
J. Richard Barnette0c7f2ae2012-10-30 23:56:1765 rm -f "$zip"
J. Richard Barnettef5b0e872012-10-17 17:12:2366
67 if [ -n "$old_image" ]; then
68 local digits='[0-9][0-9]*'
69 local pattern="\(R$digits-$digits\.$digits\.$digits-[^/][^/]*\)/..*"
70 old_image_dir=$(expr "$old_image" : "$pattern" || true)
71 if [ -z "$old_image_dir" ]; then
72 echo >&2
73 echo "Warning: Previous image $old_image wasn't created" >&2
74 echo "Warning: by this script. You need to manually remove the" >&2
75 echo "Warning: obsolete image and any associated .zip files." >&2
76 echo >&2
77 elif [ -d "$old_image_dir" -a "$old_image_dir" != "$image_dir" ]; then
78 echo "Cleaning up $old_image_dir" >&2
79 rm -rf "$old_image_dir"
80 fi
81 fi
82}
83
84BUILD="$1"
85shift
86
87for BOARD in "$@"; do
88 deploy_image "$BUILD" "$BOARD"
89done