Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to takeover upgrade script in preparation for release #408

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions upgrade-takeover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function cleanup_work_dir() {
# Ensure takover path is not just '/' because deletion command is
if [[ -n "${work_dir}" && "${#work_dir}" -gt 3 ]]; then
if [[ -d "${work_dir}" ]]; then
rm -rf "${work_dir:?}/*"
rm -rf "${work_dir:?}/"*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need the globbing character outside the parentheses to work.

fi
fi
}
Expand Down Expand Up @@ -300,6 +300,11 @@ starttime=$(date +%s)
if [ -d "/mnt/data/resinhup" ] && [ ! -e "/mnt/data/balenahup" ]; then
ln -s "/mnt/data/resinhup" "/mnt/data/balenahup"
fi
# Directory for downloaded/temporary files. MUST be in data partition since stores
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved up higher in the script so always defined for users.

# sizable downloaded OS image. Conserves memory for takeover binary. Must define
# before a call to 'log ERROR'.
work_dir="/mnt/data/takeover"

# LOGFILE init and header
logtime=$(date +"%Y%m%d_%H%M%S")
LOGFILE="/mnt/data/balenahup/$SCRIPTNAME.${logtime}.log"
Expand Down Expand Up @@ -454,9 +459,6 @@ case $VERSION in
;;
esac

# Ensure working directory is empty; takeover binary does not cleanup on failure.
cleanup_work_dir

# Verify data partition filesystem/storage is clean. Flashing over bad sectors
# may brick device.
data_device=$(mount |grep /mnt/data |awk '{print $1}' |head -n 1)
Expand All @@ -467,28 +469,29 @@ if [ -n "${data_device}" ]; then
fi
fi

# Ensure takeover environment is prepared. We'll add files here. MUST be in
# data partition since stores sizable downloaded OS image. Conserves memory for
# takeover binary.
work_dir="/mnt/data/takeover"
# Ensure any already existing working directory is empty; takeover binary does
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved closer to where directory is created for clarity.

# not clean it up on failure.
cleanup_work_dir
mkdir -p "${work_dir}"

# Retrieve target hostOS image and takeover binary
download_target_image
download_takeover_binary "v0.9.0-dev.1"
download_takeover_binary latest

progress 50 "Running OS update"

# Run takeover
# Must run from a writable directory; takeover creates temp files there
cd ${work_dir}

# No need to specify config.json path; defaults to /mnt/boot.
# API check fails on BoB, so disabled
# We do *not* expect takeover to return on success; it flashes the device with
# the new balenaOS.
res=$(./takeover -i balenaos.img.gz \
# Takeover returns '1' on failure in stage 1, so handled by the ERR trap defined
# above.
# Takeover reboots on failure in stage 2 and on eventual success, and so does
# not return here. Takeover itself reports failure/success to balenaCloud when
# it reboots due to the --report-hup-progress option below.
# No need to specify config.json path to takeover; defaults to /mnt/boot.
./takeover -i balenaos.img.gz \
--no-ack --no-nwmgr-check --no-os-check \
--log-level debug --fallback-log --fallback-log-file "advanced.${logtime}.log" \
--s2-log-level debug --report-hup-progress)
log ERROR "Takeover result ${res}; OS not updated"
--log-level debug --fallback-log --fallback-log-dir balenahup \
--fallback-log-filename "advanced.${logtime}.log" \
--s2-log-level debug --report-hup-progress
Loading