mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 14:41:31 +02:00
Cleans up image_to_live changes and handles errors more gracefully
TEST=Tested by running image_to_live with correct formated images as well as images that are missing either /var or dev_image directories. Review URL: http://codereview.chromium.org/1705023
This commit is contained in:
parent
b75eee3d67
commit
257117d2cc
@ -31,10 +31,13 @@ function cleanup {
|
|||||||
echo "Killing dev server."
|
echo "Killing dev server."
|
||||||
kill_all_devservers
|
kill_all_devservers
|
||||||
cleanup_remote_access
|
cleanup_remote_access
|
||||||
./mount_gpt_image.sh -mu
|
|
||||||
rm -rf "${TMP}"
|
rm -rf "${TMP}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unmount_gpt {
|
||||||
|
./mount_gpt_image.sh -mu
|
||||||
|
}
|
||||||
|
|
||||||
function remote_reboot_sh {
|
function remote_reboot_sh {
|
||||||
rm -f "${TMP_KNOWN_HOSTS}"
|
rm -f "${TMP_KNOWN_HOSTS}"
|
||||||
remote_sh "$@"
|
remote_sh "$@"
|
||||||
@ -55,24 +58,35 @@ function start_dev_server {
|
|||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Copys new stateful var and developer directories to updating system.
|
||||||
|
# chromeos_startup checks for .update_available on next boot and updates
|
||||||
|
# the stateful directories.
|
||||||
function copy_stateful_tarball {
|
function copy_stateful_tarball {
|
||||||
echo "Starting stateful update."
|
echo "Starting stateful update."
|
||||||
# Mounts most recent image stateful dir to /tmp/s
|
# Mounts most recent image stateful dir to /tmp/s
|
||||||
./mount_gpt_image.sh -m
|
./mount_gpt_image.sh -m
|
||||||
|
trap "unmount_gpt && cleanup" EXIT
|
||||||
|
|
||||||
# Create tar files for the stateful partition.
|
# Create tar files for the stateful partition.
|
||||||
cd /tmp/s/var && sudo tar -cf /tmp/var.tar . && cd -
|
if [ ! -d /tmp/s/var ] || [ ! -d /tmp/s/dev_image ] ; then
|
||||||
cd /tmp/s/dev_image && sudo tar -cf /tmp/developer.tar . && cd -
|
echo "No stateful directories found to copy. Continuing update."
|
||||||
# Copy over tar files.
|
else
|
||||||
remote_cp /tmp/var.tar /tmp
|
pushd /tmp/s/var && sudo tar -czf /tmp/var.tgz . && popd
|
||||||
remote_cp /tmp/developer.tar /tmp
|
pushd /tmp/s/dev_image && sudo tar -czf /tmp/developer.tgz . && popd
|
||||||
remote_sh "mkdir /mnt/stateful_partition/var_new &&\
|
# Copy over tar files.
|
||||||
mkdir /mnt/stateful_partition/dev_image_new &&\
|
local s_dir="/mnt/stateful_partition"
|
||||||
tar -xf /tmp/var.tar -C /mnt/stateful_partition/var_new &&\
|
remote_cp /tmp/var.tgz /tmp
|
||||||
tar -xf /tmp/developer.tar \
|
remote_cp /tmp/developer.tgz /tmp
|
||||||
-C /mnt/stateful_partition/dev_image_new &&\
|
remote_sh "rm -rf $s_dir/var_new $s_dir/dev_image_new &&\
|
||||||
touch /mnt/stateful_partition/.update_available"
|
mkdir $s_dir/var_new $s_dir/dev_image_new &&\
|
||||||
|
tar -xzf /tmp/var.tgz -C $s_dir/var_new &&\
|
||||||
|
tar -xzf /tmp/developer.tgz -C $s_dir/dev_image_new &&\
|
||||||
|
touch $s_dir/.update_available"
|
||||||
|
fi
|
||||||
# unmounts stateful partition
|
# unmounts stateful partition
|
||||||
./mount_gpt_image.sh -mu
|
./mount_gpt_image.sh -mu
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare_update_metadata {
|
function prepare_update_metadata {
|
||||||
@ -202,7 +216,6 @@ function main() {
|
|||||||
|
|
||||||
if ! copy_stateful_tarball; then
|
if ! copy_stateful_tarball; then
|
||||||
echo "Stateful update was not successful."
|
echo "Stateful update was not successful."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
remote_reboot
|
remote_reboot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user