mirror of
https://src.koozali.org/infra/smeserver-koji.git
synced 2024-11-30 04:37:31 +01:00
124 lines
4.3 KiB
Bash
124 lines
4.3 KiB
Bash
#!/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
|
|
|
|
# if no build server given, deploy locally
|
|
if [ -z $KOJI_BUILD_FQDN ] ; then
|
|
KOJI_BUILD_FQDN=$KOJI_HUB_FQDN
|
|
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
|
|
|
|
# check that the target exists
|
|
RESP=$(nc -z $KOJI_BUILD_FQDN 22 2>&1 | grep succeeded)
|
|
if [[ -z $RESP ]] ; 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
|
|
# Add server capacity
|
|
sudo -u kojiadmin koji edit-host --capacity="$KOJID_CAPACITY" "$KOJI_BUILD_FQDN"
|
|
# 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
|
|
chmod a+x $SCRIPT_DIR/koji-gencert.sh
|
|
fi
|
|
pushd "$KOJI_PKI_DIR"
|
|
$SCRIPT_DIR/koji-gencert.sh "$KOJI_BUILD_FQDN" "/C=$COUNTRY_CODE/ST=$STATE/L=$LOCATION/O=$ORGANIZATION/CN=$KOJI_BUILD_FQDN"
|
|
popd
|
|
# check if local install or remote
|
|
if [[ $KOJI_BUILD_FQDN = $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
|
|
$SCRIPT_DIR/koji-deploy-builder.sh $DEBUG
|
|
else
|
|
# deploy to specified server
|
|
|
|
## 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
|
|
$SCRIPT_DIR/koji-deploy-nfs-server.sh $DEBUG
|
|
fi
|
|
|
|
# add build server to nfs exports line for /mnt/koji
|
|
sed '/^\/mnt\/koji/ s/$/ $KOJI_BUILD_FQDN(ro,no_root_squash)/' /etc/exports
|
|
|
|
# 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
|