#!/bin/sh # SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC # SPDX-FileCopyrightText: (C) 2025 Serena Willis # # SPDX-License-Identifier: AGPL-3.0 # # BuildMan 0.0.1 # Distributed CI/CD system with portability to older UNIX systems # # bma - buildman agent # # Copyright (C) 2025 Coherent Logic Development LLC # # Author: Serena Willis # PROGN=`basename $0` if [ -f "/etc/default/bm" ] then . /etc/default/bm else echo "${PROGN} error: no /etc/default/bm" exit 1 fi if [ -z ${BUILDMAN_BASE} ] then echo "${PROGN} error: BUILDMAN_BASE undefined" exit 1 fi if [ -z ${BUILDMAN_UID} ] then echo "${PROGN} error: BUILDMAN_UID undefined" exit 1 fi if [ -z ${BUILDMAN_GID} ] then echo "${PROGN} error: BUILDMAN_GID undefined" exit 1 fi #if [ $EUID -ne ${BUILDMAN_UID} ] #then # echo "${PROGN} error: must be run as user \"${BUILDMAN_USER}\"" # exit 1 #fi OS=`uname` DT=`date +"%Y%m%d"` if [ "$OS" = "SCO_SV" ] ; then THOST=`hostname -s` PATH=/usr/gnu/bin:$PATH export PATH else if [ "$OS" = "SunOS" ] ; then THOST=`hostname` else THOST=`hostname -s` fi fi tmphost=`echo ${THOST} | cut -d. -f1` THOST="${tmphost}" cd "${BUILDMAN_BASE}/projects" PROJECTS=`ls -1 -d *` for PROJECT in $PROJECTS do HOSTDIR="${BUILDMAN_BASE}/projects/${PROJECT}/hosts/${THOST}" BUILD_WANTED="${HOSTDIR}/build-wanted" if [ -d "${HOSTDIR}" ] then echo "$PROGN: project ${PROJECT} references build host ${THOST}" if [ -f "${BUILD_WANTED}" ] then echo "$PROGN: project ${PROJECT} has a build request pending" rm -f "${BUILD_WANTED}" DT=`date +"%Y%m%d%H%M%S"` JOBID="$$-${DT}" echo "$PROGN: creating job ${JOBID}" JOBDIR="${HOSTDIR}/jobs/${JOBID}" JLOG="${JOBDIR}/job.log" JSCR="${BUILDMAN_BASE}/project/${PROJECT}/scripts/build.sh" mkdir -p "${JOBDIR}" cd "${JOBDIR}" echo "${JOBID}" > "${HOSTDIR}/build-running" echo "${JOBID}" > "${JOBDIR}/running" if [ -f "${JSCR}" ] then echo "$PROGN: running build script ${JSCR} for project ${PROJECT} [job id ${JOBID}]" sh "${JSCR}" > ${JLOG} RETCODE=$? rm -f "${HOSTDIR}/build-running" rm -f "${JOBDIR}/running" case $RETCODE in 0) echo "${JOBID}" > "${HOSTDIR}/build-passing" echo "${JOBID}" > "${JOBDIR}/passing" ;; *) echo "${JOBID}" > "${HOSTDIR}/build-failing" echo "${JOBID}" > "${JOBDIR}/failing" ;; esac else echo "$PROGN: build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" echo "$PROGN: build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" > "${HOSTDIR}/build-failing" echo "$PROGN: build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" > "${JOBDIR}/failing" echo "$PROGN: build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" >> "${JLOG}" rm -f "${HOSTDIR}/build-running" rm -f "${JOBDIR}/running" fi fi fi done