Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Unified Diff: src/scripts/image_to_live.sh

Issue 519041: Simple way to run client/server autotest(s) from server (Closed)
Patch Set: No longer necessary to graft Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/scripts/remote_access.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scripts/image_to_live.sh
diff --git a/src/scripts/image_to_live.sh b/src/scripts/image_to_live.sh
index 17c15146567b4a5e68630201181d74df48f91286..72f8ddacea2c3824681a652156ae51807bbd2829 100755
--- a/src/scripts/image_to_live.sh
+++ b/src/scripts/image_to_live.sh
@@ -4,39 +4,20 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-# Script to convert the output of build_image.sh to a usb image.
+# Script to update an image onto a live running ChromiumOS instance.
# Load common constants. This should be the first executable line.
# The path to common.sh should be relative to your script's location.
-. "$(dirname "$0")/common.sh"
-assert_outside_chroot
+. "$(dirname $0)/common.sh"
+. "$(dirname $0)/remote_access.sh"
-cd $(dirname "$0")
-
-DEFAULT_PRIVATE_KEY="$SRC_ROOT/platform/testing/testing_rsa"
-
-DEFINE_string ip "" "IP address of running Chromium OS instance"
-DEFINE_boolean ignore_version $FLAGS_TRUE \
+DEFINE_boolean ignore_version ${FLAGS_TRUE} \
"Ignore existing version on running instance and always update"
-DEFINE_boolean ignore_hostname $FLAGS_TRUE \
+DEFINE_boolean ignore_hostname ${FLAGS_TRUE} \
"Ignore existing AU hostname on running instance use this hostname"
-DEFINE_string private_key "$DEFAULT_PRIVATE_KEY" \
- "Private key of root account on instance"
-
-FLAGS "$@" || exit 1
-eval set -- "${FLAGS_ARGV}"
-
-set -e
-
-if [ -z "$FLAGS_ip" ]; then
- echo "Please specify the IP of the Chromium OS instance"
- exit 1
-fi
-
-TMP=$(mktemp -d /tmp/image_to_live.XXXX)
-TMP_PRIVATE_KEY=$TMP/private_key
-TMP_KNOWN_HOSTS=$TMP/known_hosts
+DEFINE_boolean update_known_hosts ${FLAGS_FALSE} \
+ "Update your known_hosts with the new remote instance's key"
function kill_all_devservers {
! pkill -f 'python devserver.py'
@@ -44,36 +25,14 @@ function kill_all_devservers {
function cleanup {
kill_all_devservers
- rm -rf $TMP
-}
-
-trap cleanup EXIT
-
-function remote_sh {
- # Disable strict host checking so that we don't prompt the user when
- # the host key file is removed and just go ahead and add it.
- REMOTE_OUT=$(ssh -o StrictHostKeyChecking=no -o \
- UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_ip "$@")
- return ${PIPESTATUS[0]}
+ rm -rf "${TMP}"
}
function remote_reboot_sh {
- rm -f $TMP_KNOWN_HOSTS
+ rm -f "${TMP_KNOWN_HOSTS}"
remote_sh "$@"
}
-function set_up_remote_access {
- if [ -z "$SSH_AGENT_PID" ]; then
- eval `ssh-agent`
- fi
- cp $FLAGS_private_key $TMP_PRIVATE_KEY
- chmod 0400 $TMP_PRIVATE_KEY
- ssh-add $TMP_PRIVATE_KEY
-
- # Verify the client is reachable before continuing
- remote_sh "true"
-}
-
function start_dev_server {
kill_all_devservers
sudo -v
@@ -89,7 +48,7 @@ function start_dev_server {
function prepare_update_metadata {
remote_sh "mount -norw,remount /"
- if [ $FLAGS_ignore_version -eq $FLAGS_TRUE ]; then
+ if [[ ${FLAGS_ignore_version} -eq ${FLAGS_TRUE} ]]; then
echo "Forcing update independent of the current version"
remote_sh "cat /etc/lsb-release |\
grep -v CHROMEOS_RELEASE_VERSION > /etc/lsb-release~;\
@@ -97,8 +56,8 @@ function prepare_update_metadata {
echo 'CHROMEOS_RELEASE_VERSION=0.0.0.0' >> /etc/lsb-release"
fi
- if [ $FLAGS_ignore_hostname -eq $FLAGS_TRUE ]; then
- echo "Forcing update from $HOSTNAME"
+ if [ ${FLAGS_ignore_hostname} -eq ${FLAGS_TRUE} ]; then
+ echo "Forcing update from ${HOSTNAME}"
remote_sh "cat /etc/lsb-release |\
grep -v '^CHROMEOS_AUSERVER=' |\
grep -v '^CHROMEOS_DEVSERVER=' > /etc/lsb-release~;\
@@ -112,12 +71,12 @@ function prepare_update_metadata {
}
function run_auto_update {
- echo "Starting update and clear away prior"
- UPDATE_FILE=/var/log/softwareupdate.log
+ echo "Starting update"
+ local update_file=/var/log/softwareupdate.log
# Clear it out so we don't see a prior run and make sure it
# exists so the first tail below can't fail if it races the
# memento updater first write and wins.
- remote_sh "rm -f $UPDATE_FILE; touch $UPDATE_FILE; \
+ remote_sh "rm -f ${update_file}; touch ${update_file}; \
/opt/google/memento_updater/memento_updater.sh</dev/null>&/dev/null&"
local update_error
@@ -125,50 +84,52 @@ function run_auto_update {
local progress
update_error=1
- output_file=$TMP/output
+ output_file="${TMP}/output"
while true; do
# The softwareupdate.log gets pretty bit with download progress
# lines so only look in the last 100 lines for status.
- remote_sh "tail -100 $UPDATE_FILE"
- echo "$REMOTE_OUT" > $output_file
- progress=$(tail -4 $output_file | grep 0K | head -1)
- if [ -n "$progress" ]; then
- echo "Image fetching progress: $progress"
+ remote_sh "tail -100 ${update_file}"
+ echo "${REMOTE_OUT}" > "${output_file}"
+ progress=$(tail -4 "${output_file}" | grep 0K | head -1)
+ if [ -n "${progress}" ]; then
+ echo "Image fetching progress: ${progress}"
fi
- if grep -q 'updatecheck status="noupdate"' $output_file; then
+ if grep -q 'updatecheck status="noupdate"' "${output_file}"; then
echo "devserver is claiming there is no update available."
echo "Consider setting --ignore_version."
break
fi
- if grep -q 'Autoupdate applied. You should now reboot' $output_file; then
+ if grep -q 'Autoupdate applied. You should now reboot' "${output_file}"
+ then
echo "Autoupdate was successful."
update_error=0
fi
- if grep -q 'Memento AutoUpdate terminating' $output_file; then
+ if grep -q 'Memento AutoUpdate terminating' "${output_file}"; then
break
fi
# Sleep for a while so that ssh handling doesn't slow down the install
sleep 2
done
- return $update_error
+ return ${update_error}
}
function remote_reboot {
echo "Rebooting."
remote_sh "touch /tmp/awaiting_reboot; reboot"
local output_file
- output_file=$TMP/output
+ output_file="${TMP}/output"
while true; do
REMOTE_OUT=""
# This may fail while the machine is done so generate output and a
# boolean result to distinguish between down/timeout and real failure
- ! remote_reboot_sh "echo 0; [ -e /tmp/awaiting_reboot ] && echo '1'; true"
- echo "$REMOTE_OUT" > $output_file
- if grep -q "0" $output_file; then
- if grep -q "1" $output_file; then
+ ! remote_sh_allow_changed_host_key \
+ "echo 0; [ -e /tmp/awaiting_reboot ] && echo '1'; true"
+ echo "${REMOTE_OUT}" > "${output_file}"
+ if grep -q "0" "${output_file}"; then
+ if grep -q "1" "${output_file}"; then
echo "Not yet rebooted"
else
echo "Rebooted and responding"
@@ -179,26 +140,54 @@ function remote_reboot {
done
}
-set_up_remote_access
+function main() {
+ assert_outside_chroot
-if remote_sh [ -e /tmp/memento_autoupdate_completed ]; then
- echo "Machine has been updated but not yet rebooted. Rebooting it now."
- echo "Rerun this script if you still wish to update it."
- remote_reboot
- exit 1
-fi
+ cd $(dirname "$0")
-start_dev_server
+ FLAGS "$@" || exit 1
+ eval set -- "${FLAGS_ARGV}"
-prepare_update_metadata
+ set -e
-if ! run_auto_update; then
- echo "Update was not successful."
- exit
-fi
+ trap cleanup EXIT
-remote_reboot
+ TMP=$(mktemp -d /tmp/image_to_live.XXXX)
+
+ remote_access_init
+
+ if remote_sh [ -e /tmp/memento_autoupdate_completed ]; then
+ echo "Machine has been updated but not yet rebooted. Rebooting it now."
+ echo "Rerun this script if you still wish to update it."
+ remote_reboot
+ exit 1
+ fi
+
+ start_dev_server
+
+ prepare_update_metadata
+
+ if ! run_auto_update; then
+ echo "Update was not successful."
+ exit
+ fi
+
+ remote_reboot
+
+ if [[ ${FLAGS_update_hostkey} -eq ${FLAGS_TRUE} ]]; then
+ local known_hosts="${HOME}/.ssh/known_hosts"
+ cp "${known_hosts}" "${known_hosts}~"
+ grep -v "^${FLAGS_remote} " "${known_hosts}" > "${TMP}/new_known_hosts"
+ cat "${TMP}/new_known_hosts" "${TMP_KNOWN_HOSTS}" > "${known_hosts}"
+ chmod 0640 "${known_hosts}"
+ echo "New updated in ${known_hosts}, backup made."
+ fi
+
+ remote_sh "grep ^CHROMEOS_RELEASE_DESCRIPTION= /etc/lsb-release"
+ local release_description=$(echo $REMOTE_OUT | cut -d '=' -f 2)
+ echo "Update was successful and rebooted to $release_description"
+
+ return 0
+}
-remote_sh "grep ^CHROMEOS_RELEASE_DESCRIPTION= /etc/lsb-release"
-RELEASE_DESCRIPTION=$(echo $REMOTE_OUT | cut -d '=' -f 2)
-echo "Update was successful and rebooted to $RELEASE_DESCRIPTION"
+main $@
« no previous file with comments | « no previous file | src/scripts/remote_access.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698