J. Richard Barnette | f5b0e87 | 2012-10-17 17:12:23 | [diff] [blame] | 1 | #!/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 | |
| 6 | if [ $# -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 |
| 11 | fi |
| 12 | |
| 13 | set -e |
| 14 | |
| 15 | cd ~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 |
| 21 | select_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") |
| 45 | deploy_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 Barnette | 0c7f2ae | 2012-10-30 23:56:17 | [diff] [blame] | 65 | rm -f "$zip" |
J. Richard Barnette | f5b0e87 | 2012-10-17 17:12:23 | [diff] [blame] | 66 | |
| 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 | |
| 84 | BUILD="$1" |
| 85 | shift |
| 86 | |
| 87 | for BOARD in "$@"; do |
| 88 | deploy_image "$BUILD" "$BOARD" |
| 89 | done |