fwupdate 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/sh
  2. # This file is part of the OpenADK project.
  3. # Do update.
  4. PART0="/dev/sda2"
  5. PART1="/dev/sda3"
  6. # Name of the archive, which is the firmware. For this file is the checksum calculated and
  7. # checked against the one from the tar archive.
  8. FW_NAME="openadk.tar.xz"
  9. CHECK_SUM_FILE="sha256.txt"
  10. TMP_MOUNT="/mnt"
  11. if [ -z $1 ]; then
  12. echo "Usage: $0 <full path to update filename>"
  13. exit 1
  14. fi
  15. if [ ! -f $1 ]; then
  16. echo "File $1 not found"
  17. exit 1
  18. fi
  19. FIRMWARE=$1
  20. echo "Validate new firmware $FIRMWARE"
  21. echo "Extract checksum file ..."
  22. cmd="tar -xf $FIRMWARE $CHECK_SUM_FILE"
  23. $cmd
  24. if [ ! -f $CHECK_SUM_FILE ];then
  25. echo "No checksum file found! $CHECK_SUM_FILE"
  26. exit 3
  27. fi
  28. if [ $(wc -m $CHECK_SUM_FILE | cut -d\ -f1) -eq 65 ];then
  29. echo "Found a checksum in file $CHECK_SUM_FILE"
  30. else
  31. echo "No checksum found in archive! $(wc -m $CHECK_SUM_FILE | cut -d\ -f1)"
  32. exit 4
  33. fi
  34. CHECK_SUM_UPDATE_FILE="$(cat $CHECK_SUM_FILE)"
  35. echo "Calculate the checksum of the new firmware ..."
  36. CHECK_SUM_NEW_SYSTEM=$(tar -xf $FIRMWARE $FW_NAME -O | sha256sum - |cut -d\ -f1)
  37. echo "Compare the checksums ..."
  38. if [ "X$CHECK_SUM_NEW_SYSTEM" = "X$CHECK_SUM_UPDATE_FILE" ]; then
  39. echo "Checksum verified (they match) ..."
  40. else
  41. echo "Checksum does not match!"
  42. echo "${CHECK_SUM_UPDATE_FILE} "
  43. echo "${CHECK_SUM_NEW_SYSTEM}"
  44. fi
  45. echo "First unmount $TMP_MOUNT the spare partition just in case ..."
  46. umount $TMP_MOUNT 2>/dev/null
  47. # create the mkfs options depending on which is the active partition
  48. CURRENT_SYS="$(rdev /|awk '{ print $1 }')"
  49. case "$CURRENT_SYS" in
  50. "$PART0")
  51. MOUNTPART="$PART1"
  52. OS=OpenADK2
  53. ;;
  54. "$PART1")
  55. MOUNTPART="$PART0"
  56. OS=OpenADK1
  57. ;;
  58. *)
  59. echo "Current partition $CURRENT_SYS not recognized"
  60. exit 5
  61. ;;
  62. esac
  63. echo "Currently the system is running on $CURRENT_SYS"
  64. # Create filesystem on inactive partition
  65. echo "The partition $MOUNTPART is going to be prepared for the new system."
  66. echo "Creating the filesystem ..."
  67. mkfs.ext2 -j -q -F $MOUNTPART
  68. if [ $? -ne 0 ];then
  69. echo "It was not possible to create the new filesystem on $MOUNTPART"
  70. exit 6
  71. fi
  72. echo "Mount the new partition $MOUNTPART ..."
  73. mount -t ext4 $MOUNTPART $TMP_MOUNT
  74. if [ $? -ne 0 ];then
  75. echo "It was not possible to mount the partition for the new system!"
  76. echo "Please reboot the system and try to update again."
  77. exit 7
  78. fi
  79. cd $TMP_MOUNT
  80. echo "The new system is going to be extracted into the partition $MOUNTPART ..."
  81. tar -xf $FIRMWARE $FW_NAME -O|tar -xJf -
  82. if [ $? -ne 0 ]; then
  83. echo "The extraction of the new system failed!"
  84. echo "Please reboot the system and try to update again."
  85. cd /
  86. umount $MOUNTPART
  87. exit 8
  88. fi
  89. echo "Checking the new system on next boot"
  90. touch $TMP_MOUNT/firmware_check
  91. if [ $? -ne 0 ]; then
  92. echo "General ERROR"
  93. echo "Please reboot the system and try to update again."
  94. cd /
  95. umount $MOUNTPART
  96. exit 9
  97. fi
  98. # echo "DD.MM.YYYY hh:mm:hh\n$(date '+%d.%m.%Y %H:%M:%S')" > install_date.txt
  99. date '+%d.%B.%Y %H:%M:%S' > $TMP_MOUNT/installation_date.txt
  100. if [ $? -ne 0 ]; then
  101. echo "General ERROR"
  102. echo "Please reboot the system and try to update again."
  103. cd /
  104. umount $MOUNTPART
  105. exit 9
  106. fi
  107. echo "$CHECK_SUM_NEW_FW" >> $TMP_MOUNT/installation_date.txt
  108. if [ $? -ne 0 ]; then
  109. echo "General ERROR"
  110. echo "Please reboot the system and try to update again."
  111. cd /
  112. umount $MOUNTPART
  113. exit 9
  114. fi
  115. cd /
  116. umount $MOUNTPART
  117. grep /boot /proc/mounts 2>/dev/null
  118. if [ $? -eq 0 ]; then
  119. mount -o remount,rw /boot
  120. else
  121. mount /dev/sda1 /boot
  122. fi
  123. grub-reboot $OS
  124. grep /boot /proc/mounts 2>/dev/null
  125. if [ $? -eq 0 ]; then
  126. mount -o remount,ro /boot
  127. else
  128. umount /boot
  129. fi
  130. sync
  131. echo "Reboot now to the updated system $OS"