boot-keys 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. # Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. usage() {
  17. tool_usage_actions "$tool" "generate" "sign" "verify"
  18. }
  19. generate() {
  20. local type=$( boot_keys_type "$@" )
  21. if [ -z "$type" ]
  22. then
  23. printf "Unable to determine keys type\n" >&2
  24. return 1
  25. fi
  26. case $type in
  27. "cros"*)
  28. boot_keys_cros "cros-boot-keys" "generate"
  29. ;;
  30. esac
  31. }
  32. sign() {
  33. local project=$1
  34. local prepare_files=$( boot_keys_files "$@" )
  35. local type=$( boot_keys_type "$@" )
  36. local install_path
  37. local firmware_path
  38. local kernel_path
  39. local media
  40. if [ -z "$type" ]
  41. then
  42. printf "Unable to determine keys type\n" >&2
  43. return 1
  44. fi
  45. echo "$prepare_files" | while read install_path
  46. do
  47. case $type in
  48. "cros-firmware")
  49. firmware_path="$install_path/$project.$ROM"
  50. boot_keys_cros "$type-prepare" "sign" "$firmware_path"
  51. ;;
  52. "cros-kernel")
  53. media=$( project_action "media" "$@" )
  54. for medium in $media
  55. do
  56. kernel_path="$install_path/$KERNEL-$medium.$IMG"
  57. if [ -f "$kernel_path" ]
  58. then
  59. boot_keys_cros "$type-prepare" "sign" "$kernel_path"
  60. else
  61. boot_keys_cros "$type-prepare" "pack" "$install_path" "$medium"
  62. fi
  63. done
  64. ;;
  65. esac
  66. done
  67. }
  68. verify() {
  69. local project=$1
  70. local prepare_files=$( boot_keys_files "$@" )
  71. local type=$( boot_keys_type "$@" )
  72. local install_path
  73. local firmware_path
  74. local kernel_path
  75. local media
  76. if [ -z "$type" ]
  77. then
  78. printf "Unable to determine keys type\n" >&2
  79. return 1
  80. fi
  81. echo "$prepare_files" | while read install_path
  82. do
  83. case $type in
  84. "cros-firmware")
  85. firmware_path="$install_path/$project.$ROM"
  86. boot_keys_cros "$type-prepare" "verify" "$firmware_path"
  87. ;;
  88. "cros-kernel")
  89. media=$( project_action "media" "$@" )
  90. for medium in $media
  91. do
  92. kernel_path="$install_path/$KERNEL-$medium.$IMG"
  93. boot_keys_cros "$type-prepare" "verify" "$kernel_path"
  94. done
  95. ;;
  96. esac
  97. done
  98. }