Annotation of buildman/bma, revision 1.2
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}"
1.2 ! snw 97: cd "${JOBDIR}"
! 98:
1.1 snw 99: echo "${JOBID}" > "${HOSTDIR}/build-running"
100: echo "${JOBID}" > "${JOBDIR}/running"
101:
102: if [ -f "${JSCR}" ]
103: then
104: echo "$PROGN: running build script ${JSCR} for project ${PROJECT} [job id ${JOBID}]"
105: sh "${JSCR}" > ${JLOG}
106: RETCODE=$?
107:
108: rm -f "${HOSTDIR}/build-running"
109: rm -f "${JOBDIR}/running"
110:
111: case $RETCODE in
112:
113: 0)
114: echo "${JOBID}" > "${HOSTDIR}/build-passing"
115: echo "${JOBID}" > "${JOBDIR}/passing"
116: ;;
117: *)
118: echo "${JOBID}" > "${HOSTDIR}/build-failing"
119: echo "${JOBID}" > "${JOBDIR}/failing"
120: ;;
121:
122: esac
123: else
124: echo "$PROGN: build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]"
125: echo "$PROGN: build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" > "${HOSTDIR}/build-failing"
126: echo "$PROGN: build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" > "${JOBDIR}/failing"
127: echo "$PROGN: build script ${JSCR} missing for project ${PROJECT} [job id ${JOBID}]" >> "${JLOG}"
128: rm -f "${HOSTDIR}/build-running"
129: rm -f "${JOBDIR}/running"
130:
131: fi
132: fi
133: fi
134:
135: done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>