Annotation of buildman/bma, revision 1.1

1.1     ! snw         1: #!/bin/sh
        !             2: 
        !             3: # SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
        !             4: # SPDX-FileCopyrightText: (C) 2025 Serena Willis
        !             5: #
        !             6: # SPDX-License-Identifier: AGPL-3.0
        !             7: 
        !             8: #
        !             9: # BuildMan 0.0.1
        !            10: #  Distributed CI/CD system with portability to older UNIX systems
        !            11: #
        !            12: #  bma - buildman agent
        !            13: #
        !            14: # Copyright (C) 2025 Coherent Logic Development LLC
        !            15: #
        !            16: # Author: Serena Willis <snw@coherent-logic.com>
        !            17: #
        !            18: 
        !            19: PROGN=`basename $0`
        !            20: 
        !            21: if [ -f "/etc/default/bm" ]
        !            22: then
        !            23:     . /etc/default/bm
        !            24: else
        !            25:     echo "${PROGN} error:  no /etc/default/bm"
        !            26:     exit 1
        !            27: fi
        !            28: 
        !            29: if [ -z ${BUILDMAN_BASE} ]
        !            30: then
        !            31:     echo "${PROGN} error:  BUILDMAN_BASE undefined"
        !            32:     exit 1
        !            33: fi
        !            34: 
        !            35: if [ -z ${BUILDMAN_UID} ]
        !            36: then
        !            37:     echo "${PROGN} error:  BUILDMAN_UID undefined"
        !            38:     exit 1
        !            39: fi
        !            40: 
        !            41: if [ -z ${BUILDMAN_GID} ]
        !            42: then
        !            43:     echo "${PROGN} error:  BUILDMAN_GID undefined"
        !            44:     exit 1
        !            45: fi
        !            46: 
        !            47: if [ $EUID -ne ${BUILDMAN_UID} ]
        !            48: then
        !            49:     echo "${PROGN} error:  must be run as user \"${BUILDMAN_USER}\""
        !            50:     exit 1
        !            51: fi
        !            52: 
        !            53: OS=`uname`
        !            54: DT=`date +"%Y%m%d"`
        !            55: 
        !            56: if [ "$OS" = "SCO_SV" ] ; then
        !            57:     THOST=`hostname -s`
        !            58:     PATH=/usr/gnu/bin:$PATH
        !            59:     export PATH
        !            60: else
        !            61:     if [ "$OS" = "SunOS" ] ; then
        !            62:         THOST=`hostname`
        !            63:     else    
        !            64:         THOST=`hostname -s`
        !            65:     fi
        !            66: fi
        !            67: 
        !            68: tmphost=`echo ${THOST} | cut -d. -f1`
        !            69: THOST="${tmphost}"
        !            70: 
        !            71: cd "${BUILDMAN_BASE}/projects"
        !            72: PROJECTS=`ls -1 -d *`
        !            73: 
        !            74: for PROJECT in $PROJECTS
        !            75: do
        !            76:     HOSTDIR="${BUILDMAN_BASE}/projects/${PROJECT}/hosts/${THOST}"
        !            77:     BUILD_WANTED="${HOSTDIR}/build-wanted"
        !            78:     
        !            79:     if [ -d "${HOSTDIR}" ]
        !            80:     then
        !            81:         echo "$PROGN:  project ${PROJECT} references build host ${THOST}"
        !            82: 
        !            83:         if [ -f "${BUILD_WANTED}" ]
        !            84:         then
        !            85:             echo "$PROGN:  project ${PROJECT} has a build request pending"
        !            86:             rm -f "${BUILD_WANTED}"
        !            87: 
        !            88:             DT=`date +"%Y%m%d%H%M%S"`
        !            89:             JOBID="$$-${DT}"
        !            90: 
        !            91:             echo "$PROGN:  creating job ${JOBID}"
        !            92:             JOBDIR="${HOSTDIR}/jobs/${JOBID}"
        !            93:             JLOG="${JOBDIR}/job.log"
        !            94:             JSCR="${BUILDMAN_BASE}/project/${PROJECT}/scripts/build.sh"
        !            95:             
        !            96:             mkdir -p "${JOBDIR}"            
        !            97: 
        !            98:             echo "${JOBID}" > "${HOSTDIR}/build-running"
        !            99:             echo "${JOBID}" > "${JOBDIR}/running"
        !           100:             
        !           101:             if [ -f "${JSCR}" ]
        !           102:             then
        !           103:                 echo "$PROGN:  running build script ${JSCR} for project ${PROJECT} [job id ${JOBID}]"
        !           104:                 sh "${JSCR}" > ${JLOG}
        !           105:                 RETCODE=$?
        !           106: 
        !           107:                 rm -f "${HOSTDIR}/build-running"
        !           108:                 rm -f "${JOBDIR}/running"
        !           109:     
        !           110:                 case $RETCODE in
        !           111: 
        !           112:                     0)
        !           113:                         echo "${JOBID}" > "${HOSTDIR}/build-passing"
        !           114:                         echo "${JOBID}" > "${JOBDIR}/passing"
        !           115:                         ;;
        !           116:                     *)
        !           117:                         echo "${JOBID}" > "${HOSTDIR}/build-failing"
        !           118:                         echo "${JOBID}" > "${JOBDIR}/failing"
        !           119:                         ;;
        !           120: 
        !           121:                 esac
        !           122:             else
        !           123:                 echo "$PROGN:  build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]"
        !           124:                 echo "$PROGN:  build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" > "${HOSTDIR}/build-failing"
        !           125:                 echo "$PROGN:  build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" > "${JOBDIR}/failing"
        !           126:                 echo "$PROGN:  build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" >> "${JLOG}"
        !           127:                 rm -f "${HOSTDIR}/build-running"
        !           128:                 rm -f "${JOBDIR}/running"
        !           129: 
        !           130:             fi
        !           131:         fi
        !           132:     fi
        !           133:     
        !           134: done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>