Advertisement
mister_kanister

Mender update module, install-system-update

Jul 7th, 2023 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.65 KB | Software | 0 0
  1. #!/bin/bash
  2.  
  3. STATE="$1"
  4. FILES="$2"
  5.  
  6. switch_bootpart () {
  7.     export $(fw_printenv bootpart)
  8.     if [ $bootpart = 1 ]; then
  9.         fw_setenv bootpart 2
  10.     else
  11.         fw_setenv bootpart 1
  12.     fi
  13.     export $(fw_printenv bootpart)
  14. }
  15.  
  16. case "$STATE" in
  17.     ArtifactInstall)
  18.         # This variable will trigger bootcount to increment
  19.         fw_setenv upgrade_available 1
  20.         switch_bootpart
  21.         rootfs_img="$(realpath $FILES/files/*.ext4)"
  22.         target_partition="/dev/$(lsblk | awk 'NR==2 {print $1}')p$bootpart"
  23.         # Write, check and resize the newly flashed partition
  24.         ddrescue $rootfs_img $target_partition --force 1> /dev/null
  25.         e2fsck $target_partition -f -y > /dev/null 2>&1
  26.         resize2fs $target_partition 2> /dev/null
  27.         reboot
  28.         ;;
  29.     ArtifactCommit)
  30.         # If altbootcmd was triggred, upgrade_failed will be
  31.         # set in U-Boot. Otherwise was able to boot into new
  32.         # partition and commit update
  33.         export $(fw_printenv upgrade_failed)
  34.         if [ $upgrade_failed = 0 ]; then
  35.             fw_setenv upgrade_available 0
  36.             fw_setenv bootcount 0
  37.             exit 0
  38.         else
  39.             exit 1
  40.         fi
  41.         ;;
  42.     ArtifactFailure)
  43.         # Failure means the updated partition could not start
  44.         # and altbootcmd was triggered in U-Boot which switched the partion
  45.         # back
  46.         export $(fw_printenv upgrade_failed)
  47.         if [ $upgrade_failed = 1 ]; then
  48.             fw_setenv upgrade_available 0
  49.             fw_setenv upgrade_failed 0
  50.             fw_setenv bootcount 0
  51.             exit 1
  52.         fi
  53.         ;;
  54. esac
  55. exit 0
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement