build 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # SPDX-FileCopyrightText: 2014,2015,2020,2021,2023 Leah Rowe <leah@libreboot.org>
  4. # SPDX-FileCopyrightText: 2015 Patrick "P. J." McDermott <pj@pehjota.net>
  5. # SPDX-FileCopyrightText: 2015, 2016 Klemens Nanni <contact@autoboot.org>
  6. # SPDX-FileCopyrightText: 2022, Caleb La Grange <thonkpeasant@protonmail.com>
  7. set -u -e
  8. . "include/err.sh"
  9. . "include/option.sh"
  10. eval "$(setvars "" option aur_notice)"
  11. err="fail"
  12. linkpath="${0}"
  13. linkname="${linkpath##*/}"
  14. buildpath="./script/${linkname}"
  15. main()
  16. {
  17. x_ id -u 1>/dev/null 2>/dev/null
  18. [ $# -lt 1 ] && $err "Too few arguments. Try: ${0} help"
  19. [ "$1" = "dependencies" ] && x_ install_packages $@ && lbmk_exit 0
  20. for cmd in initcmd check_git check_project git_init excmd; do
  21. eval "${cmd} \$@"
  22. done
  23. lbmk_exit 0
  24. }
  25. initcmd()
  26. {
  27. [ "$(id -u)" != "0" ] || $err "this command as root is not permitted"
  28. check_project
  29. case "${1}" in
  30. help) usage ${0} ;;
  31. list) items "${buildpath}" ;;
  32. version) mkversion ;;
  33. *)
  34. option="${1}"
  35. return 0 ;;
  36. esac
  37. lbmk_exit 0
  38. }
  39. install_packages()
  40. {
  41. if [ $# -lt 2 ]; then
  42. printf "You must specify a distro, namely:\n" 1>&2
  43. printf "Look at files under config/dependencies/\n" 1>&2
  44. printf "Example: ./build dependencies debian\n" 1>&2
  45. $err "install_packages: target not specified"
  46. fi
  47. [ -f "config/dependencies/${2}" ] || $err "Unsupported target"
  48. . "config/dependencies/${2}"
  49. x_ ${pkg_add} ${pkglist}
  50. [ -z "${aur_notice}" ] && return 0
  51. printf "You must install AUR packages: %s\n" "$aur_notice" 1>&2
  52. }
  53. # release archives contain .gitignore, but not .git.
  54. # lbmk can be run from lbmk.git, or an archive.
  55. git_init()
  56. {
  57. [ -L ".git" ] && $err "Reference .git is a symlink"
  58. [ -e ".git" ] && return 0
  59. eval "$(setvars "$(date -Rd @${versiondate})" cdate _nogit)"
  60. git init || $err "${PWD}: cannot initialise Git repository"
  61. git add -A . || $err "${PWD}: cannot add files to Git repository"
  62. git commit -m "${projectname} ${version}" --date "${cdate}" \
  63. --author="lbmk <lbmk@libreboot.org>" || \
  64. $err "$PWD: can't commit ${projectname}/${version}, date $cdate"
  65. git tag -a "${version}" -m "${projectname} ${version}" || \
  66. $err "${PWD}: cannot git-tag ${projectname}/${version}"
  67. }
  68. excmd()
  69. {
  70. lbmkcmd="${buildpath}/${option}"
  71. [ -f "${lbmkcmd}" ] || $err "Invalid command. Run: ${linkpath} help"
  72. shift 1; "$lbmkcmd" $@ || $err "excmd: ${lbmkcmd} ${@}"
  73. }
  74. usage()
  75. {
  76. progname=${0}
  77. cat <<- EOF
  78. $(mkversion)
  79. USAGE: ${progname} <OPTION>
  80. possible values for 'OPTION':
  81. $(items "${buildpath}")
  82. To know what ${projectname} version you're on, type:
  83. ${progname} version
  84. Refer to ${projectname} documentation for more info.
  85. EOF
  86. }
  87. mkversion()
  88. {
  89. printf "revision: %s %s\n" "$projectname" "$version"
  90. printf "revision date: %s\n" "$(date -Rud @${versiondate})"
  91. }
  92. lbmk_exit()
  93. {
  94. tmp_cleanup || err_ "lbmk_exit: can't rm tmpdir upon exit $1: $tmpdir"
  95. exit $1
  96. }
  97. fail()
  98. {
  99. tmp_cleanup || printf "WARNING: can't rm tmpdir: %s\n" "$tmpdir" 1>&2
  100. err_ "${1}"
  101. }
  102. tmp_cleanup()
  103. {
  104. [ "${tmpdir_was_set}" = "n" ] || return 0
  105. rm -Rf "${tmpdir}" || return 1
  106. }
  107. main $@