16e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah#!/bin/bash 26e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah 3db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 46e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah# Use of this source code is governed by a BSD-style license that can be 56e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah# found in the LICENSE file. 66e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah 76e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah# Changes the channel on a Chrome OS image. 86e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah 96e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah# Load common constants and variables. 106e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah. "$(dirname "$0")/common.sh" 116e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah 126e567a10e29fb4e23d394388064a6304072b6daaGaurav Shahset -e 136e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah 146e567a10e29fb4e23d394388064a6304072b6daaGaurav Shahif [ $# -ne 2 ]; then 156e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah cat <<EOF 166e567a10e29fb4e23d394388064a6304072b6daaGaurav ShahUsage: $PROG <image.bin> <channel> 176e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah 186e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah<image.bin>: Path to image. 196e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah<channel>: The new channel of the image. 206e567a10e29fb4e23d394388064a6304072b6daaGaurav ShahEOF 216e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah exit 1 226e567a10e29fb4e23d394388064a6304072b6daaGaurav Shahfi 236e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah 246e567a10e29fb4e23d394388064a6304072b6daaGaurav Shahmain() { 256e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah local image=$1 266e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah local to=$2 27db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger local rootfs lsb 28db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger 296e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah rootfs=$(make_temp_dir) 30db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger lsb="${rootfs}/etc/lsb-release" 316e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah mount_image_partition "${image}" 3 "${rootfs}" 326e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah # Get the current channel on the image. 33db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger local from=$(grep '^CHROMEOS_RELEASE_TRACK=' "${lsb}" | cut -d '=' -f 2) 346e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah from=${from%"-channel"} 356e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah echo "Current channel is '${from}'. Changing to '${to}'." 36db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger 37db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger local sudo 38db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger if [[ ! -w ${lsb} ]] ; then 39db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger sudo="sudo" 40db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger fi 41db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger ${sudo} sed -i "s/\b${from}\b/${to}/" "${lsb}" && 426e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah echo "Channel change successful." 43db1d5b20f890c2109a19e7626321c3d51e13e813Mike Frysinger cat "${lsb}" 446e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah} 456e567a10e29fb4e23d394388064a6304072b6daaGaurav Shah 466e567a10e29fb4e23d394388064a6304072b6daaGaurav Shahmain "$@" 47