smeserver-koji/install-koji-farm.sh

173 lines
5.0 KiB
Bash

#!/bin/bash
set -e
DEBUG=
KOJI_HUB_FQDN="$(hostname -f)"
KOJI_WEB_FQDN=$KOJI_HUB_FQDN
KOJI_ALLOWED_SCMS="src.koozali.org:/*"
KOJI_BUILD_FQDNS=
for param in "$@"; do
if [ $param ] ; then
case $param in
-h | --help )
echo "install-koji-farm.sh [web=<web FQDN> | build=<builder FQDN> | scm=<scm:/*> | debug]" ;;
debug )
DEBUG="debug" ;;
web=* )
KOJI_WEB_FQDN=${param#*=} ;;
build=* )
KOJI_BUILD_FQDNS=$KOJI_BUILD_FQDNS" "${param#*=} ;;
scm=* )
KOJI_ALLOWED_SCMS=$KOJI_ALLOWED_SCMS" "${param#*=} ;;
esac
else
break
fi
done
SILENT="-s"
QUIET="-q"
if [ $DEBUG ] ; then
set -xe
SILENT=
QUIET="-v"
fi
echo "Checking connectivity..."
# install any required packages
if [[ "$KOJI_WEB_FQDN" != "$KOJI_HUB_FQDN" || "$KOJI_BUILD_FQDNS" ]] ; then
if [[ -z $(dnf list installed | grep epel-release) ]] ; then
dnf install -y epel-release $QUIET
fi
if [[ -z $(dnf list installed | grep netcat) ]] ; then
dnf install -y netcat $QUIET
fi
fi
if [[ "$KOJI_WEB_FQDN" != "$KOJI_HUB_FQDN" ]] ; then
# check that I can conmnect
if [[ -z $(nc -z $KOJI_WEB_FQDN 22 2>&1 | grep succeeded) ]] ; then
echo "I cannot connect to the web server at $KOJI_WEB_FQDN! Is it online? "
echo "Options:"
echo "- turn on the server"
echo "- add this server into the /etc/hosts file on this server"
exit 1
fi
fi
for FQDN in ${KOJI_BUILD_FQDNS} ; do
# check that I can conmnect
if [[ -z $(nc -z $FQDN 22 2>&1 | grep succeeded) ]] ; then
echo "I cannot connect to builder at $FQDN! Is it online? "
echo "Options:"
echo "- turn on the server"
echo "- add this server into the /etc/hosts file on this server"
exit 1
fi
done
# pull down the deploy scripts
SCRIPT_GIT="https://src.koozali.org/smedev/smeserver-koji/raw/branch/master/koji-setup"
SCRIPT_DIR="$(echo ~)/bin"
echo "Loading required scripts and packages...."
mkdir -p $SCRIPT_DIR
curl $SILENT $SCRIPT_GIT/koji-deploy-hub.sh > $SCRIPT_DIR/koji-deploy-hub.sh
curl $SILENT $SCRIPT_GIT/koji-deploy-web.sh > $SCRIPT_DIR/koji-deploy-web.sh
curl $SILENT $SCRIPT_GIT/koji-add-builder.sh > $SCRIPT_DIR/koji-add-builder.sh
curl $SILENT $SCRIPT_GIT/koji-bootstrap-build.sh > $SCRIPT_DIR/koji-bootstrap-build.sh
curl $SILENT $SCRIPT_GIT/koji-add-user.sh > $SCRIPT_DIR/koji-add-user.sh
chmod o+x $SCRIPT_DIR/*.sh
# ask for required parameters (ssh settings and build server FQDN)
echo "Please enter the following details for generating your SSL keys"
while true ; do
read -p "Country Code (eg, US): " COUNTRY_CODE
if [ ${#COUNTRY_CODE} -ne 2 ] ; then
echo "You must enter a 2 character country code"
else
break
fi
done
while true ; do
read -p "State/Region (eg. Ohio): " STATE
if [ $STATE ] ; then break ; else echo "State MUST be entered" ; fi
done
while true ; do
read -p "City/Location (eg. Columbus): " LOCATION
if [ $LOCATION ] ; then break ; else echo "City MUST be entered" ; fi
done
while true ; do
read -p "Organisation (eg. Koozali): " ORGANIZATION
if [ $ORGANIZATION ] ; then break ; else echo "Organization MUST be entered" ; fi
done
while true ; do
read -p "Org Unit (eg. Koji): " ORG_UNIT
if [ $ORG_UNIT ] ; then break ; else echo "Organizational Unit MUST be entered" ; fi
done
# setup default parameters
HTTPD_USER=apache
HTTPD_DOCUMENT_ROOT=/var/www/html
KOJI_DIR="/mnt/koji"
KOJI_PKI_DIR=/etc/pki/koji
RPM_ARCH="x86_64"
KOJID_CAPACITY=16
SRC_RPM_DIR=
BIN_RPM_DIR=
DEBUG_RPM_DIR=
POSTGRES_USER=postgres
POSTGRES_DIR=/var/lib/pgsql
# create the parameter script used by koji scripts
cat > $SCRIPT_DIR/koji-parameters.sh <<- EOT
#!/bin/bash
## HTTPD settings
export HTTPD_USER=$HTTPD_USER
export HTTPD_DOCUMENT_ROOT=$HTTPD_DOCUMENT_ROOT
## KOJI RPM BUILD AND TRACKER
export SCRIPT_GIT=$SCRIPT_GIT
export KOJI_DIR=$KOJI_DIR
export KOJI_HUB_FQDN=$KOJI_HUB_FQDN
export KOJI_URL=http://$KOJI_HUB_FQDN
export KOJI_WEB_URL=http://$KOJI_WEB_FQDN
export KOJI_ALLOWED_SCMS=$KOJI_ALLOWED_SCMS
export KOJID_CAPACITY=$KOJID_CAPACITY
# Use for koji SSL certificates
export KOJI_PKI_DIR=$KOJI_PKI_DIR
export COUNTRY_CODE='$COUNTRY_CODE'
export STATE='$STATE'
export LOCATION='$LOCATION'
export ORGANIZATION='$ORGANIZATION'
export ORG_UNIT='$ORG_UNIT'
# Use for importing existing RPMs
export RPM_ARCH='$RPM_ARCH'
export SRC_RPM_DIR=$SRC_RPM_DIR
export BIN_RPM_DIR=$BIN_RPM_DIR
export DEBUG_RPM_DIR=$DEBUG_PRM_DIR
## POSTGRESQL DATABASE
export POSTGRES_USER=$POSTGRES_USER
export POSTGRES_DIR=$POSTGRES_DIR
EOT
chmod o+x $SCRIPT_DIR/koji-parameters.sh
# deploy the central koji components
koji-deploy-hub.sh $DEBUG
# deploy the web koji components
koji-deploy-web.sh $KOJI_WEB_FQDN $DEBUG
# add builders
if [ -z $KOJI_BUILD_FQDNS ] ; then
# use hub if no builders entered
koji-add-builder.sh $KOJI_HUB_FQDN $DEBUG
else
# use builders added as command line parameters
for FQDN in ${KOJI_BUILD_FQDNS} ; do
koij-add-builder.sh $FQDN $DEBUG
done
fi
# bootstrap the targets etc.
koji-bootstrap-build.sh