Annotation of buildman/bm, revision 1.8
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: # bm - primary BuildMan script
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:
1.4 snw 47: #if [ $EUID -ne ${BUILDMAN_UID} ]
48: #then
49: # echo "${PROGN} error: must be run as user \"${BUILDMAN_USER}\""
50: # exit 1
51: #fi
1.1 snw 52:
53: ACTION=""
54: PROJECT=""
55: BUILD_HOST=""
56: OS=`uname`
1.2 snw 57: PYES="no"
1.1 snw 58:
59: if [ "$OS" = "SCO_SV" ] ; then
60: THOST=`hostname -s`
61: PATH=/usr/gnu/bin:$PATH
62: export PATH
63: else
64: if [ "$OS" = "SunOS" ] ; then
65: THOST=`hostname`
66: else
67: THOST=`hostname -s`
68: fi
69: fi
70:
71: tmphost=`echo ${THOST} | cut -d. -f1`
72: THOST="${tmphost}"
73:
1.2 snw 74: while getopts ':p:h:a:bl:o:y' OPTION
1.1 snw 75: do
76: case $OPTION in
77:
1.2 snw 78: y)
79: PYES="yes"
80: ;;
81:
1.1 snw 82: l)
83: ACTION="list"
84: TOLIST="${OPTARG}"
85: ;;
86:
87: o)
88: OPTIONS="${OPTARG}"
89: ;;
90:
91: p)
92: PROJECT="${OPTARG}"
93: ;;
94:
95: a)
96: ACTION="add"
97: TOADD="${OPTARG}"
98: ;;
99:
100: b)
101: ACTION="build"
102: ;;
103:
104: h)
105: BUILD_HOST="${OPTARG}"
106: ;;
107:
108: esac
109: done
110:
1.6 snw 111: if [ "${ACTION}" = "" ]
112: then
113: echo "${PROGN}: no action specified"
114: exit 1
115: fi
116:
1.1 snw 117: if [ ! -z "${PROJECT}" ]
118: then
119: PROJECT_BASE="${BUILDMAN_BASE}/projects/${PROJECT}"
1.3 snw 120: if [ "${ACTION}" = "add" -a ! -d ${PROJECT_BASE} ]
1.1 snw 121: then
122: echo "$PROGN: creating ${PROJECT} in ${PROJECT_BASE}..."
123: mkdir -p "${PROJECT_BASE}"
124: fi
125:
126: if [ ! -d "${PROJECT_BASE}" ]
127: then
1.5 snw 128: echo "$PROGN error: project ${PROJECT} not defined [${PROJECT_BASE}]"
1.1 snw 129: exit 1
130: fi
131: fi
132:
133: case $ACTION in
134:
135: list)
136: case $TOLIST in
137:
138: p|projects)
139: ls -d -1 ${BUILDMAN_BASE}/projects/*
140: ;;
141:
142: h|hosts)
1.6 snw 143: BHOSTS=`ls -1 "${BUILDMAN_BASE}/projects/${PROJECT}/hosts"`
144: for BHOST in ${BHOSTS}
145: do
146: echo ${BHOST}
147: done
1.1 snw 148: ;;
149:
150: *)
151: echo "$PROGN error: invalid list specifier \"${TOLIST}\""
152: exit 1
153: ;;
154: esac
155: ;;
156:
157: add)
158: case $TOADD in
159:
160: p|project)
161: if [ -z "${PROJECT}" ]
162: then
163: echo "$PROGN error: no project specified (use -p)"
164: exit 1
165: fi
166:
167: PBASE="${BUILDMAN_BASE}/projects/${PROJECT}"
168: if [ -d "${PBASE}" ]
169: then
170: echo "$PROGN error: project \"${PROJECT}\" already exists"
171: exit 1
172: fi
173:
174: echo "$PROGN: creating directory structure for project \"${PROJECT}\""
175: mkdir -p "${PBASE}/hosts"
1.2 snw 176: mkdir -p "${PBASE}/scripts"
1.1 snw 177: ;;
178:
179:
180: h|host)
181: if [ -z "${PROJECT}" ]
182: then
183: echo "$PROGN error: no project specified (use -p)"
184: exit 1
185: fi
186:
187: PBASE="${BUILDMAN_BASE}/projects/${PROJECT}"
1.2 snw 188:
1.1 snw 189: if [ ! -d "${PBASE}" ]
190: then
191: echo "$PROGN error: project \"${PROJECT}\" does not exist"
192: exit 1
193: fi
194:
195: if [ -z "${BUILD_HOST}" ]
196: then
197: echo "$PROGN error: no host specified (use -h)"
198: exit 1
199: fi
200:
201: HBASE="${PBASE}/hosts/${BUILD_HOST}"
202: if [ -d "${HBASE}" ]
203: then
204: echo "$PROGN error: build host \"${BUILD_HOST}\" already exists"
205: exit 1
206: fi
207:
1.2 snw 208: if [ -z "${OPTIONS}" ]
209: then
210: echo "$PROGN error: must pass -o \"os:version:arch\""
211: exit 1
212: fi
213:
1.6 snw 214: PLSTR="${BUILD_HOST}:${OPTIONS}:buildman::"
1.2 snw 215: H_PLATFORM=`echo ${PLSTR} | cut -d: -f2`
216: H_VERSION=`echo ${PLSTR} | cut -d: -f3`
217: H_ARCH=`echo ${PLSTR} | cut -d: -f4`
218:
1.3 snw 219: if [ "${PYES}" = "no" ]
1.2 snw 220: then
221: echo
222: echo "Host Details"
223: echo "============"
224: echo "Project: ${PROJECT}"
225: echo "Hostname: ${BUILD_HOST}"
226: echo "Platform: ${H_PLATFORM}"
227: echo "Version: ${H_VERSION}"
228: echo "Architecture: ${H_ARCH}"
229: echo
230:
231: read -n 1 -p "OK to create? (y/n) " YORN
232: echo
233:
1.3 snw 234: if [ "${YORN}" = "y" -o "${YORN}" = "Y" ]
1.2 snw 235: then
236: CONF=1
237: else
238: echo "$PROGN: aborted"
239: exit 2
240: fi
241: fi
242:
1.1 snw 243: echo "$PROGN: adding host \"${BUILD_HOST}\" to project \"${PROJECT}\""
244: mkdir -p "${HBASE}"
1.2 snw 245: mkdir -p "${HBASE}/jobs"
246: mkdir -p "${HBASE}/logs"
247:
248: PFILE="${PBASE}/${H_PLATFORM}-platform.list"
249: echo
250: echo "=================================================="
251: echo " Don't forget to add the BuildMan cron job"
252: echo " to ${BUILDMAN_USER}@${BUILD_HOST}"
253: echo "=================================================="
254: echo
255: echo "${PLSTR}" >> "${PFILE}"
256: cd ${PBASE}
257: ls -1 *-platform.list | cut -d- -f1 | sort | uniq > platforms.list
1.1 snw 258: ;;
259:
260: esac
261: ;;
262:
1.2 snw 263:
1.1 snw 264:
265: build)
266: if [ -z "${BUILD_HOST}" ]
267: then
268: echo "$PROGN error: no build host specified"
269: exit 1
270: fi
271:
1.6 snw 272: if [ "${BUILD_HOST}" != '*' ]
273: then
274: BUILD_BASE="${PROJECT_BASE}/hosts/${BUILD_HOST}"
275:
276: if [ ! -d "${BUILD_BASE}" ]
277: then
278: echo "$PROGN error: build host ${BUILD_HOST} not configured"
279: exit 1
280: fi
281:
282: BUILD_WANTED="${PROJECT_BASE}/hosts/${BUILD_HOST}/build-wanted"
1.1 snw 283:
1.6 snw 284: if [ -f "${BUILD_WANTED}" ]
285: then
1.7 snw 286: echo "$PROGN error: build already requested on host ${BUILD_HOST}"
1.6 snw 287: exit 1
288: fi
1.1 snw 289:
1.6 snw 290: touch "${BUILD_WANTED}"
1.7 snw 291: echo "$PROGN: build of project ${PROJECT} requested on ${BUILD_HOST}"
1.6 snw 292: else
293: BHOSTS=`ls -1 "${BUILDMAN_BASE}/projects/${PROJECT}/hosts"`
294: for BUILD_HOST in ${BHOSTS}
295: do
296: BUILD_BASE="${PROJECT_BASE}/hosts/${BUILD_HOST}"
297:
298: if [ ! -d "${BUILD_BASE}" ]
299: then
1.8 ! snw 300: echo "$PROGN error: build host ${BUILD_HOST} not configured"
1.6 snw 301: fi
302:
303: BUILD_WANTED="${PROJECT_BASE}/hosts/${BUILD_HOST}/build-wanted"
304:
305: if [ -f "${BUILD_WANTED}" ]
306: then
1.8 ! snw 307: echo "$PROGN error: build already requested on ${BUILD_HOST}"
1.6 snw 308: fi
309:
310: touch "${BUILD_WANTED}" > /dev/null 2>&1
311: if [ $? = 0 ]
312: then
313: echo "$PROGN: build of project ${PROJECT} requested on build host ${BUILD_HOST}"
314: else
315: echo "$PROGN: error requesting build of ${PROJECT} on build host ${BUILD_HOST}"
316: fi
317: done
1.1 snw 318: fi
319: ;;
320:
321: esac
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>