platform.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. platform_check_image() {
  2. [ "$#" -gt 1 ] && return 1
  3. case "$(get_magic_word "$1")" in
  4. eb48|eb63) return 0;;
  5. *)
  6. echo "Invalid image type"
  7. return 1
  8. ;;
  9. esac
  10. }
  11. platform_copy_config() {
  12. local partdev
  13. if export_partdevice partdev 1; then
  14. mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
  15. cp -af "$CONF_TAR" /mnt/
  16. umount /mnt
  17. fi
  18. }
  19. platform_do_upgrade() {
  20. local diskdev partdev diff
  21. if export_bootdevice && export_partdevice diskdev 0; then
  22. sync
  23. if [ "$SAVE_PARTITIONS" = "1" ]; then
  24. get_partitions "/dev/$diskdev" bootdisk
  25. #extract the boot sector from the image
  26. get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b
  27. get_partitions /tmp/image.bs image
  28. #compare tables
  29. diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)"
  30. if [ -n "$diff" ]; then
  31. echo "Partition layout is changed. Full image will be written."
  32. ask_bool 0 "Abort" && exit
  33. get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  34. return 0
  35. fi
  36. #iterate over each partition from the image and write it to the boot disk
  37. while read part start size; do
  38. if export_partdevice partdev $part; then
  39. echo "Writing image to /dev/$partdev..."
  40. get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync
  41. else
  42. echo "Unable to find partition $part device, skipped."
  43. fi
  44. done < /tmp/partmap.image
  45. #copy partition uuid
  46. echo "Writing new UUID to /dev/$diskdev..."
  47. get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync
  48. else
  49. get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
  50. fi
  51. sleep 1
  52. fi
  53. }