55_determine_extroot_sysupgrade 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. # Copyright (C) 2010 Daniel Dickinson
  3. # This is free software, licensed under the GNU General Public License v2.
  4. # See /LICENSE for more information.
  5. check_set_md5sum() {
  6. local er_md5sum_file
  7. er_md5sum_file="${ER_OVERLAY_PREFIX}/.extroot.md5sum"
  8. local er_extroot_md5sum
  9. if [ -f $md5sum_file ]; then
  10. er_extroot_md5sum="$(cat $er_md5sum_file)"
  11. fi
  12. local er_extroot_overlay_md5sum
  13. if [ -f "/overlay/etc/extroot.md5sum" ]; then
  14. er_extroot_overlay_md5sum="$(cat /overlay/.extroot.md5sum)"
  15. fi
  16. if [ -z "$er_extroot_overlay_md5sum" ]; then
  17. cat $er_md5sum_file >/overlay/.extroot.md5sum
  18. elif [ "$er_extroot_overlay_md5sum" != "$er_extroot_md5sum" ]; then
  19. pi_extroot_mount_success="false"
  20. mkdir -p /tmp/overlay-disabled
  21. mount --move /overlay /tmp/overlay-disabled
  22. fi
  23. }
  24. set_jffs_md5sum() {
  25. # We do this anytime block-extroot exists, even on the first boot with
  26. # no extroot defined.
  27. local er_md5sum_file
  28. er_md5sum_file="${ER_OVERLAY_PREFIX}/.extroot.md5sum"
  29. local er_extroot_md5sum
  30. if [ -f $er_md5sum_file ]; then
  31. er_extroot_md5sum="$(cat $er_md5sum_file)"
  32. fi
  33. if [ -z "$er_extroot_md5sum" ]; then
  34. dd if=/dev/urandom count=32 bs=1k 2>/dev/null | md5sum | cut -f1 -d\ >$er_md5sum_file
  35. fi
  36. }
  37. determine_extroot_sysupgrade() {
  38. check_skip || set_jffs_md5sum
  39. check_skip || [ "$pi_extroot_mount_success" != "true" ] || {
  40. check_set_md5sum
  41. }
  42. }
  43. boot_hook_add preinit_mount_root determine_extroot_sysupgrade