File kiwi_post_run of Package live-kiwi-hook

#!/bin/sh

# When a new snapshot gets released, a setrelease request is sent to OBS.
# It does $nbin =~ s/-([^-]+)(-Media(?:\d?)(?:\..*?)?)$/$setrelease$2/;
# which basically replaces -Media* with the Snapshot number.
# The isos written by KIWI (and subsequently renamed by the OBS KIWI
# build recipe) do not follow that name scheme, so we need to rename
# it manually to the expected names.

set -eu

TOPDIR=${TOPDIR:-/usr/src/packages}

cd "${TOPDIR}/KIWI"

if ! [ -f *.iso ]; then
	echo "No .iso image in here - nothing do to."
	exit 0
fi

# Linux_Kamarada_15.5.x86_64-15.5-Build7.1
# <image_name>_<version>.<arch>-<version>-<obs_build>
oldiso="$(echo *.iso | sed 's/\.iso//')"

# https://tools.lymas.com.br/regexp_br.php
# ^([a-zA-Z]+_[a-zA-Z]+)_([0-9]+\.[0-9]+)\.([0-9a-zA-Z_]+)-([0-9]+\.[0-9]+)-([0-9a-zA-Z\.]+)$

image_name='([a-zA-Z]+_[a-zA-Z]+)'
version='([0-9]+\.[0-9]+)'
arch='([0-9a-zA-Z_]+)'
obs_build='([0-9a-zA-Z\.]+)'

# https://unix.stackexchange.com/a/196534/106621
if [[ $oldiso =~ $image_name\_$version\.$arch\-$version\-$obs_build ]] ; then
    image_name=${BASH_REMATCH[1]}
    version=${BASH_REMATCH[2]}
    arch=${BASH_REMATCH[3]}
    obs_build=${BASH_REMATCH[5]}

    newiso="${image_name}-${version}-${arch}-${obs_build}"
    # Linux_Kamarada-15.5-x86_64-Build7.1

    # Use rename to also rename related files
    rename -v "${oldiso}" "${newiso}" ./*
    
    # The checksum files actually need to be recreated, because they are signed
    sha256sum "${newiso}.iso" > "${newiso}.iso.sha256"
    #gpg --clearsign -o "${newiso}.iso.sha256.signed" "${newiso}.iso.sha256"
    #rm "${newiso}.iso.sha256"
    #mv "${newiso}.iso.sha256.signed" "${newiso}.iso.sha256"
fi

# All good!
exit 0
openSUSE Build Service is sponsored by