summaryrefslogtreecommitdiff
path: root/scripts/image_signing/set_channel.sh
blob: bb0927acf60cb61657ffbb7a6ed05e1f720b7481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash

# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Changes the channel on a Chrome OS image.

# Load common constants and variables.
. "$(dirname "$0")/common.sh"

set -e

if [ $# -ne 2 ]; then
  cat <<EOF
Usage: $PROG <image.bin> <channel>

<image.bin>: Path to image.
<channel>: The new channel of the image.
EOF
  exit 1
fi

main() {
  local image=$1
  local to=$2
  local rootfs lsb

  rootfs=$(make_temp_dir)
  lsb="${rootfs}/etc/lsb-release"
  mount_image_partition "${image}" 3 "${rootfs}"
  # Get the current channel on the image.
  local from=$(grep '^CHROMEOS_RELEASE_TRACK=' "${lsb}" | cut -d '=' -f 2)
  from=${from%"-channel"}
  echo "Current channel is '${from}'. Changing to '${to}'."

  local sudo
  if [[ ! -w ${lsb} ]] ; then
    sudo="sudo"
  fi
  ${sudo} sed -i "s/\b${from}\b/${to}/" "${lsb}" &&
    echo "Channel change successful."
  cat "${lsb}"
}

main "$@"