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# Changes the channel on a Chrome OS image.
8
9# Load common constants and variables.
10. "$(dirname "$0")/common.sh"
11
12set -e
13
14if [ $# -ne 2 ]; then
15  cat <<EOF
16Usage: $PROG <image.bin> <channel>
17
18<image.bin>: Path to image.
19<channel>: The new channel of the image.
20EOF
21  exit 1
22fi
23
24main() {
25  local image=$1
26  local to=$2
27  local rootfs lsb
28
29  rootfs=$(make_temp_dir)
30  lsb="${rootfs}/etc/lsb-release"
31  mount_image_partition "${image}" 3 "${rootfs}"
32  # Get the current channel on the image.
33  local from=$(grep '^CHROMEOS_RELEASE_TRACK=' "${lsb}" | cut -d '=' -f 2)
34  from=${from%"-channel"}
35  echo "Current channel is '${from}'. Changing to '${to}'."
36
37  local sudo
38  if [[ ! -w ${lsb} ]] ; then
39    sudo="sudo"
40  fi
41  ${sudo} sed -i "s/\b${from}\b/${to}/" "${lsb}" &&
42    echo "Channel change successful."
43  cat "${lsb}"
44}
45
46main "$@"
47