buildrelease.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. set -e
  3. usage() {
  4. _exit_code=${1-1}
  5. echo "usage: $0 [-d DEST_MOUTPOINT] [-o RELEASEDIR]"
  6. exit ${_exit_code}
  7. }
  8. _check_packages() {
  9. local _arch=${1} _req_pkgs _pkg
  10. case "${_arch}" in
  11. arm | aarch64)
  12. set -A _req_pkgs sysutils/{dtb,u-boot\,${_arch}}
  13. ;;
  14. *)
  15. echo ${_arch}
  16. set -A _req_pkgs
  17. ;;
  18. esac
  19. echo "Checking for prerequisite packages..."
  20. for _pkg in ${_req_pkgs[@]} ; do
  21. pkg_info -q -e ${_pkg} || {
  22. echo "Missing package ${_pkg}, aborting..." >&2
  23. exit 1
  24. }
  25. echo "Found ${_pkg}"
  26. done
  27. }
  28. _setup_destdir() {
  29. mount | cut -d ' ' -f 3 | grep -q "^${1}$" && {
  30. echo "Mountpoint ${1} already mounted..." >&2
  31. exit 1
  32. }
  33. test -d "${1}" || {
  34. echo "Mountpoint ${1} does not exist..." >&2
  35. exit 1
  36. }
  37. mount_mfs -o noperm -s $((712 * 512 * 4)) swap "${1}"
  38. chown build "${1}"
  39. chmod 700 "${1}"
  40. }
  41. _cleanup_destdir() {
  42. local _mp_destdir=$1
  43. test -n ${_mp_destdir} && umount "${_mp_destdir}"
  44. }
  45. unset DESTDIR RELEASEDIR
  46. while getopts "d:ho:" c; do
  47. case "$c" in
  48. d) DESTDIR=$OPTARG
  49. ;;
  50. h) usage 0
  51. ;;
  52. o) RELEASEDIR=$OPTARG
  53. ;;
  54. *) usage
  55. ;;
  56. esac
  57. done
  58. # Required packages for release building on arm64
  59. _uboot_arch=$(arch -s)
  60. _check_packages ${_uboot_arch}
  61. # Only root
  62. _uid=$(id -u)
  63. if [ ${_uid} -ne 0 ]; then
  64. echo "Requires root credentials to go on..." >&2
  65. exit 1
  66. fi
  67. # Find the system source tree, default to /usr/src
  68. if [ -e /etc/mk.conf ]; then
  69. BSDSRCDIR=$(make -f /etc/mk.conf -V BSDSRCDIR)
  70. fi
  71. BSDSRCDIR=${BSDSRCDIR:=/usr/src}
  72. # Find out which release directory we are going to use
  73. _release=$(uname -r)
  74. # Must be on a snapshot if no Tag file exists in CVS
  75. if [ \! -e "${BSDSRCDIR}/CVS/Tag" ]; then
  76. _release=snapshots
  77. fi
  78. _arch=$(uname -m)
  79. DESTDIR=${DESTDIR-/release}
  80. RELEASEDIR=${RELEASEDIR-/var/www/htdocs/pub/OpenBSD/${_release}/${_arch}}
  81. export DESTDIR
  82. export RELEASEDIR
  83. mkdir -p "${RELEASEDIR}"
  84. chown build.wheel "${RELEASEDIR}"
  85. _setup_destdir "${DESTDIR}"
  86. trap "_cleanup_destdir '${DESTDIR}'" EXIT
  87. cd "${BSDSRCDIR}"/etc && nice make release
  88. if [ $? -ne 0 ]; then
  89. unset RELEASEDIR DESTDIR
  90. exit 1
  91. fi
  92. cd "${BSDSRCDIR}"/distrib/sets && sh checkflist
  93. RESULT=$?
  94. [[ -f ${RELEASEDIR}/SHA256 ]] && cp ${RELEASEDIR}/SHA256{,.base}
  95. unset RELEASEDIR DESTDIR
  96. exit ${RESULT}