Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- STATE="$1"
- FILES="$2"
- switch_bootpart () {
- export $(fw_printenv bootpart)
- if [ $bootpart = 1 ]; then
- fw_setenv bootpart 2
- else
- fw_setenv bootpart 1
- fi
- export $(fw_printenv bootpart)
- }
- case "$STATE" in
- ArtifactInstall)
- # This variable will trigger bootcount to increment
- fw_setenv upgrade_available 1
- switch_bootpart
- rootfs_img="$(realpath $FILES/files/*.ext4)"
- target_partition="/dev/$(lsblk | awk 'NR==2 {print $1}')p$bootpart"
- # Write, check and resize the newly flashed partition
- ddrescue $rootfs_img $target_partition --force 1> /dev/null
- e2fsck $target_partition -f -y > /dev/null 2>&1
- resize2fs $target_partition 2> /dev/null
- reboot
- ;;
- ArtifactCommit)
- # If altbootcmd was triggred, upgrade_failed will be
- # set in U-Boot. Otherwise was able to boot into new
- # partition and commit update
- export $(fw_printenv upgrade_failed)
- if [ $upgrade_failed = 0 ]; then
- fw_setenv upgrade_available 0
- fw_setenv bootcount 0
- exit 0
- else
- exit 1
- fi
- ;;
- ArtifactFailure)
- # Failure means the updated partition could not start
- # and altbootcmd was triggered in U-Boot which switched the partion
- # back
- export $(fw_printenv upgrade_failed)
- if [ $upgrade_failed = 1 ]; then
- fw_setenv upgrade_available 0
- fw_setenv upgrade_failed 0
- fw_setenv bootcount 0
- exit 1
- fi
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement