/ builder.zsh
builder.zsh
  1  #!/usr/bin/env zsh
  2  #-
  3  # Copyright (c) 2023-2025 The HardenedBSD Project
  4  #
  5  # Redistribution and use in source and binary forms, with or without
  6  # modification, are permitted provided that the following conditions
  7  # are met:
  8  # 1. Redistributions of source code must retain the above copyright
  9  #    notice, this list of conditions and the following disclaimer.
 10  # 2. Redistributions in binary form must reproduce the above copyright
 11  #    notice, this list of conditions and the following disclaimer in the
 12  #    documentation and/or other materials provided with the distribution.
 13  #
 14  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 15  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 16  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 17  # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 18  # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 19  # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 20  # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 21  # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 22  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 23  # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 24  # SUCH DAMAGE.
 25  #
 26  # Author: Shawn Webb <shawn.webb@hardenedbsd.org>
 27  
 28  set -ex
 29  
 30  MYSELF="${0}"
 31  TOPDIR="$(dirname $(realpath ${MYSELF}))"
 32  
 33  GIT="/usr/local/bin/git"
 34  RSYNC="/usr/local/bin/rsync"
 35  SSH_KEYGEN="/usr/bin/ssh-keygen"
 36  SCP="/usr/bin/scp"
 37  
 38  CONFIGDIR="${TOPDIR}/config"
 39  BUILDER_TMPDIR="/data/build/tmp"
 40  CONFIG=""
 41  LOCKFILE=""
 42  LOGDIR="/data/logs"
 43  
 44  BUILD_INSTALLERS=1
 45  BUILD_UPDATE=1
 46  PKGBASE=1
 47  QUARTERLY=0
 48  
 49  PUBLISH_INSTALLERS=1
 50  PUBLISH_UPDATE=1
 51  PUBLISH_UPDATE_DNS=1
 52  
 53  INSTALLER_PUBDIR=""
 54  UPDATE_PUBDIR=""
 55  
 56  SIGNED=1
 57  SSH_KEY=""
 58  
 59  OBJDIR_TMPFS=""
 60  
 61  NJOBS=$(sysctl -n hw.ncpu)
 62  
 63  . ${TOPDIR}/lib/git.zsh
 64  . ${TOPDIR}/lib/installers.zsh
 65  . ${TOPDIR}/lib/dns.zsh
 66  . ${TOPDIR}/lib/updater.zsh
 67  . ${TOPDIR}/lib/util.zsh
 68  . ${TOPDIR}/lib/ports.zsh
 69  
 70  shell=""
 71  
 72  while getopts "C:c:d:l:" o; do
 73  	case "${o}" in
 74  		C)
 75  			CONFIGDIR="${OPTARG}"
 76  			;;
 77  		c)
 78  			CONFIG="${OPTARG}"
 79  			;;
 80  		d)
 81  			shell="${OPTARG}"
 82  			;;
 83  		l)
 84  			LOGDIR="${OPTARG}"
 85  			;;
 86  	esac
 87  done
 88  
 89  if [ -z "${CONFIG}" ]; then
 90  	echo "[-] Required argument: -c config" >&2
 91  	exit 1
 92  fi
 93  
 94  if [ ! -f "${CONFIGDIR}/${CONFIG}" ]; then
 95  	echo "[-] ${CONFIGDIR}/${CONFIG} missing" >&2
 96  	exit 1
 97  fi
 98  
 99  . ${CONFIGDIR}/${CONFIG}
100  
101  mkdir -p ${LOGDIR}/${NAME} || exit 1
102  
103  (
104  	check_sanity || exit ${?}
105  
106  	lock_build || exit ${?}
107  	prep_build || cleanup ${?} 1
108  	fetch_src || cleanup ${?} 1
109  	update_ports || cleanup ${?} 1
110  
111  	build_update || cleanup ${?} 1
112  	build_src || cleanup ${?} 1
113  	build_pkgbase || cleanup ${?} 1
114  	build_installers || cleanup ${?} 1
115  
116  	check_installers || cleanup ${?} 1
117  
118  	sign_installers || cleanup ${?} 1
119  	sign_pkgbase || cleanup ${?} 1
120  	sign_update || cleanup ${?} 1
121  
122  	if [ "${#shell}" -gt 0 ]; then
123  		${shell}
124  	fi
125  
126  	publish_update || cleanup ${?} 1
127  	publish_installers || cleanup ${?} 1
128  
129  	cleanup
130  ) 2>&1 | tee ${LOGDIR}/${NAME}/$(date '+%F_%T').log
131  exit ${?}