misc: Make mkosi building suitable for different distro versions
We'd like to be able to build both Fedora N and N-1 at the same time if possible. This makes it more generally applicable for this scenario, as well as for other distros.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#!/bin/bash
|
||||
# This script packages rpm, deb, and pacman packages of mgmt with fpm. The
|
||||
# first argument is the package type, and all subsequent arguments are the
|
||||
# dependencies. Example usage: `./fpm-pack.sh deb dependency1 dependency2`
|
||||
# first argument is the distro type, and the second argument is the version. All
|
||||
# subsequent arguments are the dependencies.
|
||||
# Example usage: `./fpm-pack.sh fedora-29 0.1.2 dependency1 dependency2`
|
||||
|
||||
# the binary to package
|
||||
BINARY="mgmt"
|
||||
@@ -31,52 +32,62 @@ if [ "$TAG" == "" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$2" == "" ]; then
|
||||
echo "version was not specified"
|
||||
DISTRO="$1"
|
||||
if [ "$1" == "" ]; then
|
||||
echo "distro was not specified"
|
||||
exit 1
|
||||
fi
|
||||
VERSION="$2"
|
||||
if [ "$VERSION" == "" ]; then
|
||||
echo "version was not specified"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$VERSION" != "$TAG" ]; then
|
||||
echo "you must checkout the correct version before building (${VERSION} != ${TAG})"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# make sure the package type is valid
|
||||
if [ "$1" != "rpm" ] && [ "$1" != "deb" ] && [ "$1" != "pacman" ]; then
|
||||
# make sure the distro is a known valid one
|
||||
if [[ "$DISTRO" == fedora-* ]]; then
|
||||
typ="rpm"
|
||||
elif [[ "$DISTRO" == centos-* ]]; then
|
||||
typ="rpm"
|
||||
elif [[ "$DISTRO" == debian-* ]]; then
|
||||
typ="deb"
|
||||
elif [[ "$DISTRO" == ubuntu-* ]]; then
|
||||
typ="deb"
|
||||
elif [[ "$DISTRO" == archlinux ]]; then
|
||||
typ="pacman"
|
||||
else
|
||||
echo "unknown distro: ${DISTRO}."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$typ" != "rpm" ] && [ "$typ" != "deb" ] && [ "$typ" != "pacman" ]; then
|
||||
echo "invalid package type"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# assume the file extension
|
||||
ext="$typ"
|
||||
if [ "$typ" = "pacman" ]; then # archlinux is an exception
|
||||
ext=".tar.xz"
|
||||
fi
|
||||
|
||||
# don't run if the file already exists (bad idempotent implementation)
|
||||
if [ -d "${DIR}/${VERSION}/${1}/" ]; then
|
||||
if [ "$1" = "rpm" ]; then
|
||||
if ls "${DIR}/${VERSION}/${1}/"*.rpm &>/dev/null; then
|
||||
# update timestamp so the Makefile is happy =D
|
||||
touch "${DIR}/${VERSION}/${1}/"*.rpm
|
||||
echo "a .rpm already exists"
|
||||
exit 0 # don't error, we want to be idempotent
|
||||
fi
|
||||
fi
|
||||
if [ "$1" = "deb" ]; then
|
||||
if ls "${DIR}/${VERSION}/${1}/"*.deb &>/dev/null; then
|
||||
touch "${DIR}/${VERSION}/${1}/"*.deb
|
||||
echo "a .deb already exists"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ "$1" = "pacman" ]; then
|
||||
if ls "${DIR}/${VERSION}/${1}/"*.tar.xz &>/dev/null; then
|
||||
touch "${DIR}/${VERSION}/${1}/"*.tar.xz
|
||||
echo "a .tar.xz already exists"
|
||||
exit 0
|
||||
fi
|
||||
if [ -d "${DIR}/${VERSION}/${DISTRO}/" ]; then
|
||||
if ls "${DIR}/${VERSION}/${DISTRO}/"*."${ext}" &>/dev/null; then
|
||||
# update timestamp so the Makefile is happy =D
|
||||
touch "${DIR}/${VERSION}/${DISTRO}/"*."${ext}"
|
||||
echo "a .${ext} already exists"
|
||||
exit 0 # don't error, we want to be idempotent
|
||||
fi
|
||||
fi
|
||||
|
||||
# there are no changelogs for pacman packages
|
||||
if [ "$1" != "pacman" ]; then
|
||||
CHANGELOG="--${1}-changelog=${DIR}/${VERSION}/${1}/changelog"
|
||||
if [ "$typ" != "pacman" ]; then
|
||||
CHANGELOG="--${typ}-changelog=${DIR}/${VERSION}/${DISTRO}/changelog"
|
||||
fi
|
||||
|
||||
# arguments after the first two are deps
|
||||
@@ -85,7 +96,7 @@ for i in "${@:3}"; do
|
||||
done
|
||||
|
||||
# in case the `fpm` gem bin isn't in the $PATH
|
||||
if which ruby >/dev/null && which gem >/dev/null && ! command -v fpm 2>/dev/null; then
|
||||
if command -v ruby >/dev/null && command -v gem >/dev/null && ! command -v fpm 2>/dev/null; then
|
||||
PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin:$PATH"
|
||||
fi
|
||||
|
||||
@@ -99,8 +110,8 @@ fpm \
|
||||
--description "$DESCRIPTION" \
|
||||
--license "$LICENSE" \
|
||||
--input-type dir \
|
||||
--output-type "$1" \
|
||||
--package "${DIR}/${VERSION}/${1}/" \
|
||||
--output-type "$typ" \
|
||||
--package "${DIR}/${VERSION}/${DISTRO}/" \
|
||||
${CHANGELOG} \
|
||||
${DEPS} \
|
||||
--prefix "$PREFIX" \
|
||||
|
||||
Reference in New Issue
Block a user