cavif/run.sh

45 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
built_dir=${COMPILED_DIR:-/compiled}/cavif
version=$(cat $built_dir/version)
repo_dir=${REPO_DIR:-/repo}
# skip if already up-to-date
# TODO: use the repo instead and check the version with dnf
# yeah this is bad; see also the cavif-aaaaaa thing below
touch $repo_dir/cavif-tmp
if $(ls $repo_dir/cavif-* | grep -q "$version"); then
rm $repo_dir/cavif-tmp
echo "package is already up to date, exiting"
exit
fi
rm $repo_dir/cavif-tmp
# prep
dnf install fedora-packager rpmdevtools createrepo_c -y
rpmdev-setuptree
# update spec file
sed -i "s/Version:.*/Version: $version/g" cavif.spec
sed -i "s/DATE_HERE/$(date '+%a %b %d %Y')/g" cavif.spec
sed -i "s/CHANGELOG_MESSAGE_HERE/Update to $version/g" cavif.spec
sed -i "s/RPM_PACKAGER_NAME/$RPM_PACKAGER_NAME/g" cavif.spec
sed -i "s/RPM_PACKAGER_EMAIL/$RPM_PACKAGER_EMAIL/g" cavif.spec
# build package and move to the repo
rpmbuild -bb cavif.spec
mv ~/rpmbuild/RPMS/x86_64/cavif-$version-* $repo_dir/
# remove old versions
cd $repo_dir
# this is the easiest way to make sure it doesn't just fail because no cavif-* exists
# (which only happens on first run)
touch cavif-0.rpm
rm $(ls cavif-*.rpm | sort --version-sort | sed '$d')
rm cavif-0.rpm || true
# update repo
createrepo_c .
echo "package is at $repo_dir/$(ls $repo_dir/cavif-*.rpm)"