build 3.1 KB

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