File:  [Coherent Logic Development] / buildman / bm
Revision 1.1: download - view: text, annotated - select for diffs
Mon Jan 20 22:40:23 2025 UTC (2 months, 1 week ago) by snw
Branches: MAIN
CVS tags: HEAD
Initial revision

#!/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
#
#  bm - primary BuildMan script
#
# Copyright (C) 2025 Coherent Logic Development LLC
#
# Author: Serena Willis <snw@coherent-logic.com>
#

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

ACTION=""
PROJECT=""
BUILD_HOST=""
OS=`uname`

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}"


while getopts ':p:h:a:bl:o:' OPTION
do
    case $OPTION in

        l)
            ACTION="list"
            TOLIST="${OPTARG}"
            ;;

        o)
            OPTIONS="${OPTARG}"
            ;;
        
        p)
            PROJECT="${OPTARG}"
            ;;

        a)
            ACTION="add"
            TOADD="${OPTARG}"
            ;;

        b)
            ACTION="build"
            ;;

        h)
            BUILD_HOST="${OPTARG}"
            ;;

    esac
done

if [ ! -z "${PROJECT}" ]
then
    PROJECT_BASE="${BUILDMAN_BASE}/projects/${PROJECT}"
    if [ "${ACTION}" == "add" -a ! -d ${PROJECT_BASE} ]
    then
        echo "$PROGN:  creating ${PROJECT} in ${PROJECT_BASE}..."
        mkdir -p "${PROJECT_BASE}"
    fi

    if [ ! -d "${PROJECT_BASE}" ]
    then
        echo "$PROGN error:  project ${PROJECT} not defined"
        exit 1
    fi
fi

case $ACTION in

    list)
        case $TOLIST in

            p|projects)
                ls -d -1 ${BUILDMAN_BASE}/projects/*
                ;;

            h|hosts)
                ls -l "${BUILDMAN_BASE}/projects/${PROJECT}/hosts"
                ;;

            *)
                echo "$PROGN error:  invalid list specifier \"${TOLIST}\""
                exit 1
                ;;
        esac
        ;;

    add)
        case $TOADD in

            p|project)
                if [ -z "${PROJECT}" ]
                then
                    echo "$PROGN error:  no project specified (use -p)"
                    exit 1
                fi

                PBASE="${BUILDMAN_BASE}/projects/${PROJECT}"
                if [ -d "${PBASE}" ]
                then
                    echo "$PROGN error:  project \"${PROJECT}\" already exists"
                    exit 1
                fi

                echo "$PROGN:  creating directory structure for project \"${PROJECT}\""
                mkdir -p "${PBASE}/hosts"
                
                ;;
            

            h|host)
                if [ -z "${PROJECT}" ]
                then
                    echo "$PROGN error:  no project specified (use -p)"
                    exit 1
                fi

                PBASE="${BUILDMAN_BASE}/projects/${PROJECT}"
                if [ ! -d "${PBASE}" ]
                then
                    echo "$PROGN error:  project \"${PROJECT}\" does not exist"
                    exit 1
                fi
                
                if [ -z "${BUILD_HOST}" ]
                then
                    echo "$PROGN error:  no host specified (use -h)"
                    exit 1
                fi

                HBASE="${PBASE}/hosts/${BUILD_HOST}"
                if [ -d "${HBASE}" ]
                then
                    echo "$PROGN error:  build host \"${BUILD_HOST}\" already exists"
                    exit 1
                fi

                echo "$PROGN:  adding host \"${BUILD_HOST}\" to project \"${PROJECT}\""
                mkdir -p "${HBASE}"
                ;;

        esac
        ;;
            
                
    
    build)
        if [ -z "${BUILD_HOST}" ]
        then
            echo "$PROGN error:  no build host specified"
            exit 1
        fi

        BUILD_BASE="${PROJECT_BASE}/hosts/${BUILD_HOST}"

        if [ ! -d "${BUILD_BASE}" ]
        then
            echo "$PROGN error:  build host ${BUILD_HOST} not configured"
            exit 1
        fi
        
        BUILD_WANTED="${PROJECT_BASE}/${HOST}/build-wanted"

        if [ -f "${BUILD_WANTED}" ]
        then
            echo "$PROGN error:  build already requested"
            exit 1
        fi

        touch "${BUILD_WANTED}"
        echo "$PROGN:  build of project ${PROJECT} requested on build host ${HOST}"
        ;;

esac
        

    
        

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