smeserver-koji/install-koji-farm.sh

236 lines
8.3 KiB
Bash
Raw Normal View History

2023-09-01 00:53:11 +02:00
#!/bin/bash
set -e
2023-09-01 08:59:55 +02:00
DEBUG=
2023-09-11 05:02:10 +02:00
KOJI_HUB_FQDN="$(hostname -f)"
KOJI_WEB_FQDN=$KOJI_HUB_FQDN
2023-11-07 23:33:53 +01:00
KOJI_ALLOWED_SCMS="src.koozali.org:/*"
2023-09-11 08:57:02 +02:00
KOJI_BUILD_FQDNS=
for param in "$@"; do
2023-09-01 06:07:07 +02:00
if [ $param ] ; then
case $param in
2023-11-07 23:33:53 +01:00
-h | --help )
echo "install-koji-farm.sh [web=<web FQDN> | build=<builder FQDN> | scm=<scm:/*> | debug]" ;;
2023-09-11 05:02:10 +02:00
debug )
DEBUG="debug" ;;
web=* )
2023-09-12 01:39:06 +02:00
KOJI_WEB_FQDN=${param#*=} ;;
2023-09-11 05:02:10 +02:00
build=* )
2023-11-07 23:33:53 +01:00
KOJI_BUILD_FQDNS=$KOJI_BUILD_FQDNS" "${param#*=} ;;
scm=* )
KOJI_ALLOWED_SCMS=$KOJI_ALLOWED_SCMS" "${param#*=} ;;
2023-09-01 06:07:07 +02:00
esac
else
break
fi
done
2023-09-01 00:53:11 +02:00
2023-09-01 08:59:55 +02:00
SILENT="-s"
QUIET="-q"
2023-09-01 06:07:07 +02:00
if [ $DEBUG ] ; then
set -xe
2023-09-01 08:59:55 +02:00
SILENT=
QUIET="-v"
2023-09-01 06:07:07 +02:00
fi
2023-10-02 23:21:08 +02:00
echo "Checking connectivity..."
2023-09-02 07:39:30 +02:00
# install any required packages
2023-10-03 00:37:54 +02:00
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
2023-09-02 07:39:30 +02:00
2023-10-03 00:37:54 +02:00
if [[ "$KOJI_WEB_FQDN" != "$KOJI_HUB_FQDN" ]] ; then
# check that I can conmnect
2023-10-02 23:21:08 +02:00
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
2023-10-02 23:21:08 +02:00
for FQDN in ${KOJI_BUILD_FQDNS} ; do
# check that I can conmnect
2023-10-02 23:21:08 +02:00
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
2023-10-02 23:21:08 +02:00
# 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
2023-09-01 06:07:07 +02:00
# ask for required parameters (ssh settings and build server FQDN)
2023-09-04 13:50:21 +02:00
echo "Please enter the following details for generating your SSL keys"
2023-09-01 06:07:07 +02:00
while true ; do
2023-09-04 13:50:21 +02:00
read -p "Country Code (eg, US): " COUNTRY_CODE
2023-09-01 06:23:15 +02:00
if [ ${#COUNTRY_CODE} -ne 2 ] ; then
2023-09-01 06:07:07 +02:00
echo "You must enter a 2 character country code"
else
break
fi
done
while true ; do
2023-09-04 13:50:21 +02:00
read -p "State/Region (eg. Ohio): " STATE
2023-09-01 06:07:07 +02:00
if [ $STATE ] ; then break ; else echo "State MUST be entered" ; fi
done
while true ; do
2023-09-04 13:50:21 +02:00
read -p "City/Location (eg. Columbus): " LOCATION
2023-09-01 06:07:07 +02:00
if [ $LOCATION ] ; then break ; else echo "City MUST be entered" ; fi
done
while true ; do
2023-09-04 13:50:21 +02:00
read -p "Organisation (eg. Koozali): " ORGANIZATION
2023-09-01 06:07:07 +02:00
if [ $ORGANIZATION ] ; then break ; else echo "Organization MUST be entered" ; fi
done
while true ; do
2023-09-04 13:50:21 +02:00
read -p "Org Unit (eg. Koji): " ORG_UNIT
2023-09-01 06:07:07 +02:00
if [ $ORG_UNIT ] ; then break ; else echo "Organizational Unit MUST be entered" ; fi
done
2023-09-01 00:53:11 +02:00
# setup default parameters
2023-09-04 07:38:11 +02:00
HTTPD_USER=apache
HTTPD_DOCUMENT_ROOT=/var/www/html
KOJI_DIR="/mnt/koji"
2023-09-04 07:48:02 +02:00
KOJI_PKI_DIR=/etc/pki/koji
2023-10-06 03:02:33 +02:00
RPM_ARCH="x86_64"
KOJID_CAPACITY=16
SRC_RPM_DIR=
BIN_RPM_DIR=
DEBUG_RPM_DIR=
2023-09-05 02:56:43 +02:00
EXTERNAL_REPO='http://mirror.contribs.org/smeserver/releases/10/smeos/\$arch/'
2023-09-04 07:38:11 +02:00
POSTGRES_USER=postgres
POSTGRES_DIR=/var/lib/pgsql
2023-09-01 06:07:07 +02:00
# create the parameter script used by koji scripts
cat > $SCRIPT_DIR/koji-parameters.sh <<- EOT
#!/bin/bash
2023-09-04 07:10:17 +02:00
## HTTPD settings
2023-09-04 07:38:11 +02:00
export HTTPD_USER=$HTTPD_USER
export HTTPD_DOCUMENT_ROOT=$HTTPD_DOCUMENT_ROOT
2023-09-01 01:44:52 +02:00
## KOJI RPM BUILD AND TRACKER
export SCRIPT_GIT=$SCRIPT_GIT
2023-09-04 07:54:44 +02:00
export KOJI_DIR=$KOJI_DIR
2023-09-04 08:07:57 +02:00
export KOJI_HUB_FQDN=$KOJI_HUB_FQDN
export KOJI_URL=http://$KOJI_HUB_FQDN
export KOJI_WEB_URL=http://$KOJI_WEB_FQDN
2023-11-04 07:13:27 +01:00
export KOJI_ALLOWED_SCMS=$KOJI_ALLOWED_SCMS
2023-09-02 07:39:30 +02:00
export KOJID_CAPACITY=$KOJID_CAPACITY
2023-09-01 01:44:52 +02:00
# Use for koji SSL certificates
2023-09-04 07:38:11 +02:00
export KOJI_PKI_DIR=$KOJI_PKI_DIR
2023-09-01 01:44:52 +02:00
export COUNTRY_CODE='$COUNTRY_CODE'
export STATE='$STATE'
export LOCATION='$LOCATION'
export ORGANIZATION='$ORGANIZATION'
export ORG_UNIT='$ORG_UNIT'
# Use for importing existing RPMs
2023-09-11 10:02:38 +02:00
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
2023-09-01 01:44:52 +02:00
# Comment the following if supplying all RPMs as an upstream and not a downstream
2023-09-05 02:56:43 +02:00
export EXTERNAL_REPO=${EXTERNAL_REPO}
2023-09-01 01:44:52 +02:00
## POSTGRESQL DATABASE
2023-09-04 07:38:11 +02:00
export POSTGRES_USER=$POSTGRES_USER
export POSTGRES_DIR=$POSTGRES_DIR
2023-09-01 01:44:52 +02:00
EOT
2023-09-04 03:39:25 +02:00
chmod o+x $SCRIPT_DIR/koji-parameters.sh
2023-09-01 06:07:07 +02:00
# deploy the central koji components
koji-deploy-hub.sh $DEBUG
2023-09-01 06:07:07 +02:00
2023-09-11 05:02:10 +02:00
# deploy the web koji components
2023-10-03 00:37:54 +02:00
if [[ "$KOJI_WEB_FQDN" == "$KOJI_HUB_FQDN" ]] ; then
2023-09-11 05:02:10 +02:00
# deploy locally (default)
2023-09-11 06:39:57 +02:00
koji-deploy-web.sh $KOJI_WEB_FQDN $DEBUG
2023-09-11 05:02:10 +02:00
else
# deploy remotely to $KOJI_WEB_FQDN
# check that I can conmnect
2023-10-03 00:22:55 +02:00
if [ ! $(nc -z $KOJI_WEB_FQDN 22 2>&1 | grep succeeded) ] ; then
2023-09-11 05:02:10 +02:00
echo "I cannot connect to $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
# update hub config files to point at web server
2023-09-14 09:53:49 +02:00
sed -i 's,KojiWebURL.*,KojiWebURL = http://$KOJI_WEB_FQDN/koji,g' /etc/koji-hub/hub.conf
sed -i 's,weburl.*,weburl = http://$KOJI_WEB_FQDN/koji,g' /etc/koji.conf
# check if nfs has been installed on the hub (only need to install once)
if [[ -z $(dnf list installed | grep nfs-server) ]] ; then
# add nfs share for koji files direcory to hub
curl $SILENT $SCRIPT_GIT/koji-deploy-nfs-server.sh > $SCRIPT_DIR/koji-deploy-nfs-server.sh
chmod o+x $SCRIPT_DIR/koji-deploy-nfs-server.sh
koji-deploy-nfs-server.sh $DEBUG
fi
# add web server to nfs exports line for /mnt/koji
sed -i '/^\/mnt\/koji/ s/$/ $KOJI_WEB_FQDN(ro,no_root_squash)/g' /etc/exports
2023-09-11 05:02:10 +02:00
# generate a hub ssh key if there isn't one already (for scp & ssh to web server)
if [ ! -f /root/.ssh/id-rsa ] ; then
# create a ssh key on build server
mkdir -p ~/.ssh
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ""
fi
# copy the server key into authorized keys on the web server
ssh-copy-id -i ~/.ssh/id_rsa.pub $KOJI_WEB_FQDN
# find the IP of the web server
WEB_IP=$(ssh root@$KOJI_WEB_FQDN "hostname -I")
# add web server into allowed access to db
cat >> "$POSTGRES_DIR"/data/pg_hba.conf <<- EOF
host koji koji $WEB_IP/32 scram-sha-256
EOF
systemctl reload postgresql
# copy across the ssl keys
ssh $QUIET root@$KOJI_WEB_FQDN mkdir -p $KOJI_PKI_DIR/private
2023-09-14 01:10:15 +02:00
scp $QUIET $KOJI_PKI_DIR/kojiweb.pem root@$KOJI_WEB_FQDN:$KOJI_PKI_DIR/.
2023-09-11 05:02:10 +02:00
scp $QUIET $KOJI_PKI_DIR/kojihub.pem root@$KOJI_WEB_FQDN:$KOJI_PKI_DIR/.
scp $QUIET $KOJI_PKI_DIR/private/kojihub.key root@$KOJI_WEB_FQDN:$KOJI_PKI_DIR/private/.
scp $QUIET $KOJI_PKI_DIR/koji_ca_cert.crt root@$KOJI_WEB_FQDN:$KOJI_PKI_DIR/.
# copy across the parameter files (we built them on the hub)
ssh $QUIET root@$KOJI_WEB_FQDN mkdir -p $SCRIPT_DIR
scp $QUIET $SCRIPT_DIR/koji-parameters.sh root@$KOJI_WEB_FQDN:$SCRIPT_DIR/koji-parameters.sh
# pull down the required scripts
2023-09-14 01:19:15 +02:00
ssh $QUIET root@$KOJI_WEB_FQDN "curl $SILENT $SCRIPT_GIT/koji-deploy-nfs-client.sh > $SCRIPT_DIR/koji-deploy-nfs-client.sh"
2023-09-11 05:02:10 +02:00
ssh $QUIET root@$KOJI_WEB_FQDN "curl $SILENT $SCRIPT_GIT/koji-deploy-web.sh > $SCRIPT_DIR/koji-deploy-web.sh"
# make them executeable
ssh $QUIET root@$KOJI_WEB_FQDN "chmod o+x $SCRIPT_DIR/*"
# connect to nfs share
ssh $QUIET root@$KOJI_WEB_FQDN $SCRIPT_DIR/koji-deploy-nfs-client.sh $DEBUG
# deploy koji builder
ssh $QUIET root@$KOJI_WEB_FQDN $SCRIPT_DIR/koji-deploy-web.sh $KOJI_WEB_FQDN $DEBUG
fi
# 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
2023-09-11 07:39:19 +02:00
fi
# bootstrap the targets etc.
2023-09-11 07:39:19 +02:00
koji-bootstrap-build.sh