1
0

fwtool.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. fwtool_check_signature() {
  2. [ $# -gt 1 ] && return 1
  3. [ ! -x /usr/bin/ucert ] && {
  4. if [ "$REQUIRE_IMAGE_SIGNATURE" = 1 ]; then
  5. return 1
  6. else
  7. return 0
  8. fi
  9. }
  10. if ! fwtool -q -s /tmp/sysupgrade.ucert "$1"; then
  11. echo "Image signature not found"
  12. [ "$REQUIRE_IMAGE_SIGNATURE" = 1 -a "$FORCE" != 1 ] && {
  13. echo "Use sysupgrade -F to override this check when downgrading or flashing to vendor firmware"
  14. }
  15. [ "$REQUIRE_IMAGE_SIGNATURE" = 1 ] && return 1
  16. return 0
  17. fi
  18. fwtool -q -T -s /dev/null "$1" | \
  19. ucert -V -m - -c "/tmp/sysupgrade.ucert" -P /etc/opkg/keys
  20. return $?
  21. }
  22. fwtool_check_image() {
  23. [ $# -gt 1 ] && return 1
  24. . /usr/share/libubox/jshn.sh
  25. if ! fwtool -q -i /tmp/sysupgrade.meta "$1"; then
  26. echo "Image metadata not found"
  27. [ "$REQUIRE_IMAGE_METADATA" = 1 -a "$FORCE" != 1 ] && {
  28. echo "Use sysupgrade -F to override this check when downgrading or flashing to vendor firmware"
  29. }
  30. [ "$REQUIRE_IMAGE_METADATA" = 1 ] && return 1
  31. return 0
  32. fi
  33. json_load "$(cat /tmp/sysupgrade.meta)" || {
  34. echo "Invalid image metadata"
  35. return 1
  36. }
  37. device="$(cat /tmp/sysinfo/board_name)"
  38. json_select supported_devices || return 1
  39. json_get_keys dev_keys
  40. for k in $dev_keys; do
  41. json_get_var dev "$k"
  42. [ "$dev" = "$device" ] && return 0
  43. done
  44. echo "Device $device not supported by this image"
  45. echo -n "Supported devices:"
  46. for k in $dev_keys; do
  47. json_get_var dev "$k"
  48. echo -n " $dev"
  49. done
  50. echo
  51. return 1
  52. }