summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2012-04-11 16:56:00 -0400
committerGerrit <chrome-bot@google.com>2012-04-12 16:06:58 -0700
commitdb1d5b20f890c2109a19e7626321c3d51e13e813 (patch)
treed4948c91c2054a4cc964032bc89bdc1958760dd6
parent7437af134edf66d6c7b5c927a15d8b38958517b3 (diff)
downloadvboot-db1d5b20f890c2109a19e7626321c3d51e13e813.tar.gz
signer scripts: use `sudo` if need be when modifying /etc/lsb-release
If we try to run the signing_poller daemon as non-root, it fails to set the channel. Detect if the lsb file is writable, and if not, switch to using sudo on the fly. BUG=None TEST=`./signer/signing_poller.py` as non-root and setting the channel works Change-Id: Iadb10ae68582edfb332f33d3b101c83949ee9502 Reviewed-on: https://gerrit.chromium.org/gerrit/20089 Reviewed-by: Gaurav Shah <gauravsh@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org> Commit-Ready: Mike Frysinger <vapier@chromium.org>
-rwxr-xr-xscripts/image_signing/set_channel.sh18
-rwxr-xr-xscripts/image_signing/tag_image.sh17
2 files changed, 24 insertions, 11 deletions
diff --git a/scripts/image_signing/set_channel.sh b/scripts/image_signing/set_channel.sh
index 064d737f..bb0927ac 100755
--- a/scripts/image_signing/set_channel.sh
+++ b/scripts/image_signing/set_channel.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+# 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.
@@ -24,17 +24,23 @@ 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=' \
- "${rootfs}/etc/lsb-release" | cut -d '=' -f 2)
+ local from=$(grep '^CHROMEOS_RELEASE_TRACK=' "${lsb}" | cut -d '=' -f 2)
from=${from%"-channel"}
echo "Current channel is '${from}'. Changing to '${to}'."
- sed -i "s/\b${from}\b/${to}/" "${rootfs}/etc/lsb-release" &&
+
+ local sudo
+ if [[ ! -w ${lsb} ]] ; then
+ sudo="sudo"
+ fi
+ ${sudo} sed -i "s/\b${from}\b/${to}/" "${lsb}" &&
echo "Channel change successful."
- cat "${rootfs}/etc/lsb-release"
+ cat "${lsb}"
}
main "$@"
diff --git a/scripts/image_signing/tag_image.sh b/scripts/image_signing/tag_image.sh
index aa19871c..0059f931 100755
--- a/scripts/image_signing/tag_image.sh
+++ b/scripts/image_signing/tag_image.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# 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.
@@ -173,22 +173,29 @@ process_all_tags() {
process_all_lsb_mods() {
local rootfs="$1"
local do_modifications="$2"
+ local lsb="${rootfs}/etc/lsb-release"
+ local sudo
+
+ if [ ! -w "${lsb}" ]; then
+ sudo="sudo"
+ fi
+
if [ ${FLAGS_remove_test_label} = ${FLAGS_TRUE} ]; then
- if grep -wq "test" ${rootfs}/etc/lsb-release; then
+ if grep -wq "test" "${lsb}"; then
g_modified=${FLAGS_TRUE}
fi
if [ ${do_modifications} = ${FLAGS_TRUE} ]; then
- sed -i 's/\btest\b//' "${rootfs}/etc/lsb-release" &&
+ ${sudo} sed -i 's/\btest\b//' "${lsb}" &&
echo "Test Label removed from /etc/lsb-release"
fi
fi
if [ ${FLAGS_change_dev_to_beta} = ${FLAGS_TRUE} ]; then
- if grep -wq "dev" ${rootfs}/etc/lsb-release; then
+ if grep -wq "dev" "${lsb}"; then
g_modified=${FLAGS_TRUE}
fi
if [ ${do_modifications} = ${FLAGS_TRUE} ]; then
- sed -i 's/\bdev\b/beta/' "${rootfs}/etc/lsb-release" &&
+ ${sudo} sed -i 's/\bdev\b/beta/' "${lsb}" &&
echo "Dev Channel Label was changed to Beta"
fi
fi