libreboot 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. libreboot_usage() {
  17. local action
  18. local target
  19. printf "$executable [action] [target] [arguments]\n" >&2
  20. printf "\nGeneric project actions:\n" >&2
  21. for action in $PROJECT_ACTIONS_GENERIC
  22. do
  23. printf " $action\n" >&2
  24. done
  25. printf "\nVirtual project actions:\n" >&2
  26. printf " sources\n"
  27. printf " produce\n"
  28. printf " test\n"
  29. printf "\nProject targets:\n" >&2
  30. ls -A "$root/$PROJECTS/" | while read target
  31. do
  32. if project_check "$target"
  33. then
  34. printf " $target\n" >&2
  35. fi
  36. done
  37. printf "\nGeneric tool actions:\n" >&2
  38. for action in $TOOL_ACTIONS_GENERIC
  39. do
  40. printf " $action\n" >&2
  41. done
  42. printf "\nTool targets:\n" >&2
  43. ls -A "$root/$TOOLS/" | while read target
  44. do
  45. if tool_check "$target"
  46. then
  47. printf " $target\n" >&2
  48. fi
  49. done
  50. printf "\nEnvironment variables:\n" >&2
  51. printf " PROJECTS_FORCE - Projects to always perform actions for\n" >&2
  52. printf " TOOLS_FORCE - Tools to always perform actions for\n" >&2
  53. printf " RELEASE_KEY - GPG key to use for release\n" >&2
  54. printf " VBOOT_KEYS_PATH - Path to the vboot keys\n" >&2
  55. printf " TASKS - Number of simultaneous tasks to run\n" >&2
  56. printf " VERSION - Version string to use\n" >&2
  57. printf "\nConfiguration files:\n" >&2
  58. printf " $BUILD_SYSTEM.conf - Environment variables configuration\n" >&2
  59. }
  60. libreboot_project() {
  61. action=$1
  62. shift
  63. project=$1
  64. shift
  65. case $action in
  66. "sources")
  67. (
  68. set +e
  69. project_action_arguments "extract" "$project" "$@"
  70. if [ $? -eq 0 ]
  71. then
  72. return 0
  73. fi
  74. project_action_arguments "download" "$project" "$@"
  75. if [ $? -eq 0 ]
  76. then
  77. return 0
  78. fi
  79. )
  80. ;;
  81. "produce")
  82. for action in "build" "install" "release"
  83. do
  84. project_action_arguments "$action" "$project" "$@"
  85. done
  86. ;;
  87. "test")
  88. for action in $PROJECT_ACTIONS
  89. do
  90. project_action_arguments "$action" "$project" "$@"
  91. done
  92. ;;
  93. *)
  94. if ! project_function_check "$project" "$action"
  95. then
  96. libreboot_usage
  97. exit 1
  98. fi
  99. if [ "$action" = "usage" ]
  100. then
  101. project_action "$action" "$project" "$@"
  102. else
  103. project_action_arguments "$action" "$project" "$@"
  104. fi
  105. ;;
  106. esac
  107. }
  108. libreboot_tool() {
  109. action=$1
  110. shift
  111. tool=$1
  112. shift
  113. case $action in
  114. *)
  115. if ! tool_function_check "$tool" "$action"
  116. then
  117. libreboot_usage
  118. exit 1
  119. fi
  120. if [ "$action" = "usage" ]
  121. then
  122. tool_action "$action" "$tool" "$@"
  123. else
  124. tool_action_arguments_recursive "$action" "$tool" "$@"
  125. fi
  126. ;;
  127. esac
  128. }
  129. libreboot_setup() {
  130. root=$( realpath "$( dirname "$0" )" )
  131. executable=$( basename "$0" )
  132. local requirements="git"
  133. local requirement_path
  134. libreboot_setup_include
  135. libreboot_setup_variables
  136. for requirement in $requirements
  137. do
  138. requirement_path=$( which "$requirement" || true )
  139. if [ -z "$requirement_path" ]
  140. then
  141. printf "Missing requirement: $requirement\n" >&2
  142. exit 1
  143. fi
  144. done
  145. }
  146. libreboot_setup_include() {
  147. local libs_path="$root/libs"
  148. local conf_path
  149. . "$libs_path/project"
  150. . "$libs_path/tool"
  151. . "$libs_path/common"
  152. . "$libs_path/git"
  153. conf_path="$root/$BUILD_SYSTEM.conf"
  154. if [ -f "$conf_path" ]
  155. then
  156. . "$conf_path"
  157. fi
  158. }
  159. libreboot_setup_variables() {
  160. local vboot_tools_path=$( project_install_path "vboot" "tools" )
  161. local version_path="$root/$DOTVERSION"
  162. local epoch_path="$root/$DOTEPOCH"
  163. if [ -z "$TASKS" ]
  164. then
  165. TASKS=1
  166. fi
  167. if [ -z "$VERSION" ]
  168. then
  169. if git_check "$root"
  170. then
  171. VERSION="$BUILD_SYSTEM-"$( git_describe "$root" 2> /dev/null || echo "git" )
  172. elif [ -f "$version_path" ]
  173. then
  174. VERSION=$( cat "$version_path" )
  175. else
  176. VERSION=$BUILD_SYSTEM
  177. fi
  178. fi
  179. if [ -z "$SOURCE_DATE_EPOCH" ]
  180. then
  181. if git_check "$root"
  182. then
  183. SOURCE_DATE_EPOCH=$( git log -1 --format=%ct )
  184. elif [ -f "$epoch_path" ]
  185. then
  186. SOURCE_DATE_EPOCH=$( cat "$epoch_path" )
  187. else
  188. SOURCE_DATE_EPOCH=$( date +%s )
  189. fi
  190. fi
  191. if [ -z "$VBOOT_KEYS_PATH" ] && [ -d "$vboot_tools_path/devkeys/" ]
  192. then
  193. VBOOT_KEYS_PATH="$vboot_tools_path/devkeys/"
  194. fi
  195. if [ -z "$EDITOR" ]
  196. then
  197. EDITOR="vi"
  198. fi
  199. }
  200. libreboot() {
  201. action=$1
  202. shift
  203. target=$1
  204. shift
  205. set -e
  206. libreboot_setup "$@"
  207. if [ -z "$action" ] || [ -z "$target" ]
  208. then
  209. libreboot_usage
  210. exit 1
  211. fi
  212. requirements "tar" "sed" "gpg" "sha256sum"
  213. if project_check "$target"
  214. then
  215. libreboot_project "$action" "$target" "$@"
  216. elif tool_check "$target"
  217. then
  218. libreboot_tool "$action" "$target" "$@"
  219. else
  220. libreboot_usage
  221. exit 1
  222. fi
  223. }
  224. libreboot "$@"