#!/bin/bash set -e DEBUG= SILENT="-s" QUIET="-q" for param in $1 $2 ; do if [ $param ] ; then case $param in debug ) DEBUG="debug" ;; * ) KOJI_BUILD_FQDN=$param ;; esac else break fi done if [ $DEBUG ] ; then set -xe SILENT= QUIET="-v" fi # load required parameters SCRIPT_DIR="$(echo ~)/bin" if [ ! -f "$SCRIPT_DIR"/koji-parameters.sh ] ; then echo "$SCRIPT_DIR/koji-parameters.sh NOT found - aborting" exit 1 fi source "$SCRIPT_DIR"/koji-parameters.sh KOJI_HUB_FQDN="$(hostname -f)" # pull down any required scripts curl $SILENT $SCRIPT_GIT/koji-deploy-hub.sh > $SCRIPT_DIR/koji-deploy-hub.sh if [ ! -d $SCRIPT_DIR ] ; then mkdir -p $SCRIPT_DIR ; fi # install any required packages 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 # if no build server given, deploy locally if [ -z $KOJI_BUILD_FQDN ] ; then KOJI_BUILD_FQDN=$KOJI_HUB_FQDN fi if [ ! nc -z $KOJI_BUILD_FQDN 22 2>/dev/null ] ; then echo "I cannot connect to $KOJI_BUILD_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 ## On the HUB # Add the host entry for the koji builder to the database sudo -u kojiadmin koji add-host "$KOJI_BUILD_FQDN" "$RPM_ARCH" # Add the host to the createrepo channel sudo -u kojiadmin koji add-host-to-channel "$KOJI_BUILD_FQDN" createrepo # A note on capacity sudo -u kojiadmin koji edit-host --capacity="$KOJID_CAPACITY" "$KOJI_BUILD_FQDN" # check if local install or remote if [ $KOJI_BUILD_FQDN eq $KOJI_HUB_FQDN ] ; then # deploy locally echo "All-in-one: Hub will now be a build server as well" if [ ! -f $SCRIPT_DIR/koji-deploy-builder.sh ] ; then curl $SILENT $SCRIPT_GIT/koji-deploy-builder.sh > $SCRIPT_DIR/koji-deploy-builder.sh chmod o+x $SCRIPT_DIR/koji-deploy-builder.sh fi koji-deploy-builder.sh $DEBUG else ## On the HUB # 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 build server to nfs exports line sed '/^\/mnt\/koji/ s/$/ $KOJI_BUILD_FQDN(ro,no_root_squash)/' /etc/exports # Generate a certificate for the builder if [ ! -f $SCRIPT_DIR/koji-gencert.sh ] ; then curl $SILENT $SCRIPT_GIT/koji-gencert.sh > $SCRIPT_DIR/koji-gencert.sh fi cp $SCRIPT_DIR/koji-gencert.sh $KOJI_PKI_DIR/. pushd "$KOJI_PKI_DIR" ./koji-gencert.sh "$KOJI_BUILD_FQDN" "/C=$COUNTRY_CODE/ST=$STATE/L=$LOCATION/O=$ORGANIZATION/CN=$KOJI_BUILD_FQDN" popd # generate a hub ssl key if there isn't one already (for scp & ssh to builder) 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 ## On the BUILDER # copy the server key into authorized keys on the build server ssh-copy-id -i ~/.ssh/id_rsa.pub $KOJI_BUILD_FQDN # copy across the ssl keys ssh $QUIET root@$KOJI_BUILD_FQDN mkdir $KOJI_PKI_DIR scp $QUIET $KOJI_PKI_DIR/$KOJI_BUILD_FQDN.pem root@$KOJI_BUILD_FQDN:$KOJI_PKI_DIR/. scp $QUIET $KOJI_PKI_DIR/koji_ca_cert.crt root@$KOJI_BUILD_FQDN:$KOJI_PKI_DIR/. # copy across the parameter files (we built them on the hub) ssh $QUIET root@$KOJI_BUILD_FQDN mkdir -p $SCRIPT_DIR scp $QUIET $SCRIPT_DIR/koji-parameters.sh root@$KOJI_BUILD_FQDN:$SCRIPT_DIR/koji-parameters.sh # pull down the required scripts ssh $QUIET root@$KOJI_BUILD_FQDN "curl $SILENT $SCRIPT_GIT/koji-deploy-nfs-client.sh > $SCRIPT_DIR/koji-deploy-nfs-client.sh" ssh $QUIET root@$KOJI_BUILD_FQDN "curl $SILENT $SCRIPT_GIT/koji-deploy-builder.sh > $SCRIPT_DIR/koji-deploy-builder.sh" # make them executeable ssh $QUIET root@$KOJI_BUILD_FQDN "chmod o+x $SCRIPT_DIR/*" # connect to nfs share ssh $QUIET root@$KOJI_BUILD_FQDN $SCRIPT_DIR/koji-deploy-nfs-client.sh $DEBUG # deploy koji builder ssh $QUIET root@$KOJI_BUILD_FQDN $SCRIPT_DIR/koji-deploy-builder.sh $DEBUG fi