#!/bin/ksh # 2021-04-07 Olaf Bohlen # 2021-11-30 Till Wegmueller # instead of putting all this into the Jenkinsfile I decided to put the actual code in this script set -ex # global config HTTPCONF="/etc/apache2/2.4/conf.d/pkgdepotd.conf" # just run prepare once to initially set up the environment # this must be run as root prepare() { echo "jenkinshelper: preparing..." pkg install web/server/apache-24 mkdir -p /etc/apache2/2.4/conf.d && chown root:sys /etc/apache2/2.4/conf.d grep "#ProxyPassMatch /default/(.*)\$ http://127.0.0.1:10000/\$1 nocanon max=200" "${HTTPCONF}" >/dev/null 2>&1 if [ $? -gt 0 ]; then echo "jenkinshelper: Initializing a new apache config at ${HTTPCONF}" echo "#ProxyPassMatch /default/(.*)\$ http://127.0.0.1:10000/\$1 nocanon max=200" >"${HTTPCONF}" else echo "jenkinshelper: Preserving an existing ${HTTPCONF}" fi cat >/etc/apache2/2.4/conf.d/00-proxy.conf </dev/null 2>&1; then # get highest port from ${HTTPCONF} to figure out the next free one nextport=$(($(nawk -F '[/:]' '{ print $7 }' <"${HTTPCONF}" | sort -n | tail -1) + 1)) # set-up a new pkg/server instance svccfg -s pkg/server <>"${HTTPCONF}" fi # we need to refresh the repo: pkgrepo refresh -s ${WORKSPACE}/${platform}/repo # also restarting pkg.depotd does not hurt svcadm restart pkg/server:${BRANCH_NAME} # graceful restart apache to reload config svcadm refresh svc:/network/http:apache24 } # cleanup the pkg.depotd server instance stage_cleanup_pr() { # we need the platform for the path to the repo platform=$(uname -p) if ! "svcs pkg/server:${BRANCH_NAME}" >/dev/null 2>&1; then # disable the instance svcadm disable pkg/server:${BRANCH_NAME} # svcadm is a async operation thus sleep here sleep 1 # remove instance from SMF svccfg delete pkg/server:${BRANCH_NAME} # Remove apache port sed "/^ProxyPassMatch /${BRANCH_NAME}/d" # graceful restart apache to reload config svcadm refresh svc:/network/http:apache24 fi } usage() { cat < ] -h show this help -p run only ONCE to initialize your environment -s followed by the stage to run, currently: setup, build_changed, prepare_pkgdepotd EOF exit 0 } ## MAIN ## # call this script with the stage as an argument to -s while getopts s:hp argv; do case ${argv} in s) stage="stage_${OPTARG}" ;; p) stage="prepare" ;; h) usage ;; esac done shift $(expr ${OPTIND} - 1) # run requested stage rt=0 ${stage} || rt=$? # we are done exit ${rt}