Files
using.cash/BuildFiles/Packaging/scripts/repackage-build-package-distro
T

107 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Directory structure is supposed to be /home/builder/swarmops/packaging/...
# Builds in /home/builder/swarmops/{buildtype}
# Home folder for script is /home/builder/swarmops/packaging
PACKAGENAME=$1
DROPFOLDER=$2
DISTROS=$3
PACKAGE=$4
BUILDID=$5
RELEASETYPE=$6
DEBCONFDIR="+b/conf"
PUBLISHSITE="packages.swarmops.com"
PACKAGESUFFIX=""
REVERSEPACKAGESUFFIX="-rc"
if [[ $2 == "internal" ]]; then
DEBCONFDIR="+b/conf-internal"
PUBLISHSITE="packages-internal.swarmops.com"
echo "Overriding default packaging config; using internal/experimental configuration"
fi
if [[ $RELEASETYPE == "candidate" ]]; then
PACKAGESUFFIX="-rc"
REVERSEPACKAGESUFFIX=""
fi
IFS=',' read -r -a distros <<< "$DISTROS"
unset IFS
for DISTRO in "${distros[@]}"
do
echo "Packaging build $BUILDID for $DISTRO..."
if [ -e dependencies/$PACKAGE-$DISTRO ]; then
DEPENDENCIESFILE=dependencies/$PACKAGE-$DISTRO
else
DEPENDENCIESFILE=dependencies/$PACKAGE-default
fi
# remove comments and roll up multiline to singleline in Dependencies field
DEPENDENCIES=$(cat ${DEPENDENCIESFILE} | grep -v '^$\|^\s*\#' | tr -d '\n' | tr -d '\r' )
# echo "Dependencies: $DEPENDENCIES"
# remove comments and empty lines in control file, make backup for next build
cat $DROPFOLDER/payload/DEBIAN/control | grep -v '^$\|^\s*\#' > $DROPFOLDER/controlbackup
cp $DROPFOLDER/controlbackup $DROPFOLDER/payload/DEBIAN/control
# replace macros in control file
sed -i "s/--Dependencies--/${DEPENDENCIES}/g" $DROPFOLDER/payload/DEBIAN/control
echo "Setting build number $BUILDID-$DISTRO..."
sed -i "s/--BuildNumber--/$BUILDID-$DISTRO/g" $DROPFOLDER/payload/DEBIAN/control
echo "Setting package name suffixes, if any..."
sed -i "s/--PackageSuffix--/$PACKAGESUFFIX/g" $DROPFOLDER/payload/DEBIAN/control
sed -i "s/--ReversePackageSuffix--/$REVERSEPACKAGESUFFIX/g" $DROPFOLDER/payload/DEBIAN/control
# make a copy for debugging purposes
mkdir -p $DROPFOLDER/debug
cp $DROPFOLDER/payload/DEBIAN/control $DROPFOLDER/debug/control-$PACKAGE-$DISTRO
# Calculating new checksums
echo "Creating MD5 checksum file ($DISTRO)..."
cd $DROPFOLDER/payload
../../scripts/create-md5
cd ../..
# read -p "Press [Enter] key to make create package..."
echo "Creating package 'swarmops-$PACKAGENAME-$DISTRO-latest.deb'..."
if [ -e swarmops-$PACKAGENAME-$DISTRO-latest.deb ]; then
rm swarmops-$PACKAGENAME-$DISTRO-latest.deb
fi
if [ -e swarmops-$PACKAGENAME-latest.deb ]; then
rm swarmops-$PACKAGENAME-latest.deb
fi
fakeroot dpkg-deb --build $DROPFOLDER/payload
mv $DROPFOLDER/payload.deb swarmops-$PACKAGENAME-$DISTRO-latest.deb
echo "Copying to '/var/www/$PUBLISHSITE'..."
cp swarmops-$PACKAGENAME-$DISTRO-latest.deb /var/www/$PUBLISHSITE
# read -p "Press [Enter] key to add package to repo..."
echo "Updating repositories ($DISTRO)..."
cd /var/www/$PUBLISHSITE
echo "Running reprepro in $(pwd)..."
reprepro --component contrib --confdir $DEBCONFDIR includedeb $DISTRO swarmops-$PACKAGENAME-$DISTRO-latest.deb
cd /home/builder/swarmops/packaging
echo "Restoring control file, cleaning up ($DISTRO)..."
cp $DROPFOLDER/controlbackup $DROPFOLDER/payload/DEBIAN/control
rm $DROPFOLDER/controlbackup
rm swarmops-$PACKAGENAME-$DISTRO-latest.deb
rm /var/www/$PUBLISHSITE/swarmops-$PACKAGENAME-$DISTRO-latest.deb
done