| 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2012 The ChromiumOS Authors |
| 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 | |
| 12 | set -e |
| 13 | |
| 14 | if [ $# -ne 2 ]; then |
| 15 | cat <<EOF |
| 16 | Usage: $PROG <image.bin> <channel> |
| 17 | |
| 18 | <image.bin>: Path to image. |
| 19 | <channel>: The new channel of the image. |
| 20 | EOF |
| 21 | exit 1 |
| 22 | fi |
| 23 | |
| 24 | main() { |
| 25 | local image=$1 |
| 26 | local to=$2 |
| 27 | local loopdev rootfs lsb |
| 28 | |
| 29 | if [[ -d "${image}" ]]; then |
| 30 | rootfs="${image}" |
| 31 | else |
| 32 | rootfs=$(make_temp_dir) |
| 33 | loopdev=$(loopback_partscan "${image}") |
| 34 | mount_loop_image_partition "${loopdev}" 3 "${rootfs}" |
| 35 | fi |
| 36 | lsb="${rootfs}/etc/lsb-release" |
| 37 | # Get the current channel on the image. |
| 38 | local from=$(lsbval "${lsb}" 'CHROMEOS_RELEASE_TRACK') |
| 39 | from=${from%"-channel"} |
| 40 | echo "Current channel is '${from}'. Changing to '${to}'." |
| 41 | |
| 42 | local sudo |
| 43 | if [[ ! -w ${lsb} ]] ; then |
| 44 | sudo="sudo" |
| 45 | fi |
| 46 | ${sudo} sed -i "s/\b${from}\b/${to}/" "${lsb}" && |
| 47 | restore_lsb_selinux "${lsb}" && |
| 48 | echo "Channel change successful." |
| 49 | cat "${lsb}" |
| 50 | } |
| 51 | |
| 52 | main "$@" |