Annotation of buildman/bm, revision 1.3
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:
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: 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:
111: if [ ! -z "${PROJECT}" ]
112: then
113: PROJECT_BASE="${BUILDMAN_BASE}/projects/${PROJECT}"
1.3 ! snw 114: if [ "${ACTION}" = "add" -a ! -d ${PROJECT_BASE} ]
1.1 snw 115: then
116: echo "$PROGN: creating ${PROJECT} in ${PROJECT_BASE}..."
117: mkdir -p "${PROJECT_BASE}"
118: fi
119:
120: if [ ! -d "${PROJECT_BASE}" ]
121: then
122: echo "$PROGN error: project ${PROJECT} not defined"
123: exit 1
124: fi
125: fi
126:
127: case $ACTION in
128:
129: list)
130: case $TOLIST in
131:
132: p|projects)
133: ls -d -1 ${BUILDMAN_BASE}/projects/*
134: ;;
135:
136: h|hosts)
137: ls -l "${BUILDMAN_BASE}/projects/${PROJECT}/hosts"
138: ;;
139:
140: *)
141: echo "$PROGN error: invalid list specifier \"${TOLIST}\""
142: exit 1
143: ;;
144: esac
145: ;;
146:
147: add)
148: case $TOADD in
149:
150: p|project)
151: if [ -z "${PROJECT}" ]
152: then
153: echo "$PROGN error: no project specified (use -p)"
154: exit 1
155: fi
156:
157: PBASE="${BUILDMAN_BASE}/projects/${PROJECT}"
158: if [ -d "${PBASE}" ]
159: then
160: echo "$PROGN error: project \"${PROJECT}\" already exists"
161: exit 1
162: fi
163:
164: echo "$PROGN: creating directory structure for project \"${PROJECT}\""
165: mkdir -p "${PBASE}/hosts"
1.2 snw 166: mkdir -p "${PBASE}/scripts"
1.1 snw 167: ;;
168:
169:
170: h|host)
171: if [ -z "${PROJECT}" ]
172: then
173: echo "$PROGN error: no project specified (use -p)"
174: exit 1
175: fi
176:
177: PBASE="${BUILDMAN_BASE}/projects/${PROJECT}"
1.2 snw 178:
1.1 snw 179: if [ ! -d "${PBASE}" ]
180: then
181: echo "$PROGN error: project \"${PROJECT}\" does not exist"
182: exit 1
183: fi
184:
185: if [ -z "${BUILD_HOST}" ]
186: then
187: echo "$PROGN error: no host specified (use -h)"
188: exit 1
189: fi
190:
191: HBASE="${PBASE}/hosts/${BUILD_HOST}"
192: if [ -d "${HBASE}" ]
193: then
194: echo "$PROGN error: build host \"${BUILD_HOST}\" already exists"
195: exit 1
196: fi
197:
1.2 snw 198: if [ -z "${OPTIONS}" ]
199: then
200: echo "$PROGN error: must pass -o \"os:version:arch\""
201: exit 1
202: fi
203:
204: PLSTR="${BUILD_HOST}:${OPTIONS}"
205: H_PLATFORM=`echo ${PLSTR} | cut -d: -f2`
206: H_VERSION=`echo ${PLSTR} | cut -d: -f3`
207: H_ARCH=`echo ${PLSTR} | cut -d: -f4`
208:
1.3 ! snw 209: if [ "${PYES}" = "no" ]
1.2 snw 210: then
211: echo
212: echo "Host Details"
213: echo "============"
214: echo "Project: ${PROJECT}"
215: echo "Hostname: ${BUILD_HOST}"
216: echo "Platform: ${H_PLATFORM}"
217: echo "Version: ${H_VERSION}"
218: echo "Architecture: ${H_ARCH}"
219: echo
220:
221: read -n 1 -p "OK to create? (y/n) " YORN
222: echo
223:
1.3 ! snw 224: if [ "${YORN}" = "y" -o "${YORN}" = "Y" ]
1.2 snw 225: then
226: CONF=1
227: else
228: echo "$PROGN: aborted"
229: exit 2
230: fi
231: fi
232:
1.1 snw 233: echo "$PROGN: adding host \"${BUILD_HOST}\" to project \"${PROJECT}\""
234: mkdir -p "${HBASE}"
1.2 snw 235: mkdir -p "${HBASE}/jobs"
236: mkdir -p "${HBASE}/logs"
237:
238: PFILE="${PBASE}/${H_PLATFORM}-platform.list"
239: echo
240: echo "=================================================="
241: echo " Don't forget to add the BuildMan cron job"
242: echo " to ${BUILDMAN_USER}@${BUILD_HOST}"
243: echo "=================================================="
244: echo
245: echo "${PLSTR}" >> "${PFILE}"
246: cd ${PBASE}
247: ls -1 *-platform.list | cut -d- -f1 | sort | uniq > platforms.list
1.1 snw 248: ;;
249:
250: esac
251: ;;
252:
1.2 snw 253:
1.1 snw 254:
255: build)
256: if [ -z "${BUILD_HOST}" ]
257: then
258: echo "$PROGN error: no build host specified"
259: exit 1
260: fi
261:
262: BUILD_BASE="${PROJECT_BASE}/hosts/${BUILD_HOST}"
263:
264: if [ ! -d "${BUILD_BASE}" ]
265: then
266: echo "$PROGN error: build host ${BUILD_HOST} not configured"
267: exit 1
268: fi
269:
1.2 snw 270: BUILD_WANTED="${PROJECT_BASE}/hosts/${BUILD_HOST}/build-wanted"
1.1 snw 271:
272: if [ -f "${BUILD_WANTED}" ]
273: then
274: echo "$PROGN error: build already requested"
275: exit 1
276: fi
277:
278: touch "${BUILD_WANTED}"
1.2 snw 279: echo "$PROGN: build of project ${PROJECT} requested on build host ${BUILD_HOST}"
1.1 snw 280: ;;
281:
282: esac
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>