Richard Brown 2024-05-10 12:42:09 +00:00 committed by Git OBS Bridge
parent 0aa3161cb1
commit f6026698aa
2 changed files with 73 additions and 22 deletions

View File

@ -1,22 +1,79 @@
#!/bin/sh -eu
pkg_dir="/usr/src/packages"
BUILD_DISTURL=
# To get BUILD_DISTURL
test -f /.buildenv && . /.buildenv
top_dir="/usr/src/packages"
img_dir="${top_dir}/KIWI"
build_dir="/usr/lib/build"
spec_in="${build_dir}/image.spec.in"
arch="$(uname -m)"
log() {
echo "[tik-img-to-rpm] $@"
}
log "Creating RPM from any tik-osimage-*.raw.xz images produced"
log "Check for tik-osimage-*.raw.xz in KIWI output directory"
if ! ls ${pkg_dir}/KIWI/tik-osimage-*.raw.xz; then
if ! ls ${img_dir}/tik-osimage-*.raw.xz; then
log "No tik-osimage found" && exit 0
fi
for f in ${pkg_dir}/KIWI/*.raw.xz; do
log "DEBUG: $f"
done
log "tik-osimage-* found: Creating RPM from any tik-osimage-*.raw.xz images"
log "Using ${spec_in} as spec file template"
log "Generating metadata for spec file template"
for f in ${img_dir}/*.raw.xz; do
base_f=basename ${f} .raw.xz
image=${base_f}.raw.xz
json_f=${img_dir}/${base_f}.cdx.json
log "[${base_f}] Parsing ${json_f} to populate variables for RPM .spec"
pkg_version=$(jq '.components[] | select(.name | endswith("-release")) | .version' ${json_f} | tr -d '"' | cut -f 1 -d '-')
pkg_release=$(jq '.components[] | select(.name | endswith("-release")) | .version' ${json_f} | tr -d '"' | cut -f 2 -d '-')
pkg_name=$(echo ${base_f} | awk -F ".${arch}" '{print $1}')
os_name=$(echo ${pkg_name} | awk -F 'tik-osimage-' '{print $2}')
cd ${build_dir}
sed -e "s@__PKG_NAME__@${pkg_name}@g" \
-e "s@__VERSION__@${pkg_version}@g" \
-e "s@__RELEASE__@${pkg_release}@g" \
-e "s@__SOURCE0__@${image}@g" \
-e "s@__OS_NAME__@${os_name}@g" \
< ${spec_in} \
> ${build_dir}/image.spec
touch ${build_dir}/image.changes
# Local builds have the file already in place, that's not true on IBS
if [ ! -f ${top_dir}/SOURCES/${image} ]; then
ln ${image} ${top_dir}/SOURCES
fi
# Make sure /usr/src/packages/* dirs exist
if [ ! -f ${top_dir}/BUILD ]; then
log "Create BUILD dir"
mkdir -p ${top_dir}/BUILD
fi
if [ ! -f ${top_dir}/SRPMS ]; then
log "Create SRPMS dir"
mkdir -p ${top_dir}/SRPMS
fi
if [ ! -f ${top_dir}/RPMS/${arch} ]; then
log "Create ARCH RPMS dir"
mkdir -p ${top_dir}/RPMS/${arch}
fi
log "Starting build"
if [ -z "$BUILD_DISTURL" ]; then
rpmbuild --target ${arch} -ba ${build_dir}/image.spec
else
rpmbuild --target ${arch} -ba --define "disturl $BUILD_DISTURL" ${build_dir}/image.spec
fi
# required for the BS to find the rpm, because it is
# a "non-standard result file for KIWI"
mkdir -p ${top_dir}/OTHER
mv ${top_dir}/RPMS/${arch}/${pkg_name}-${pkg_version}-${pkg_release}.${arch}.rpm ${top_dir}/OTHER/
mv ${top_dir}/SRPMS/${pkg_name}-${pkg_version}-${pkg_release}.src.rpm ${top_dir}/OTHER/
done

View File

@ -1,38 +1,32 @@
# needsrootforbuild
Url: http://www.aeondeskop.org/
Name: __NAME__
Summary: Package with __SUSE_PRODUCT_NAME__ __SUSE_VERSION__ tik OS image
Name: __PKG_NAME__
Summary: Package with __OS_NAME__ tik OS image
Version: __VERSION__
Release: __RELEASE__
Group: System/Management
License: GPL-2.0+
Source0: __SOURCE0__
Source1: __SOURCE1__
Source2: __SOURCE2__
Requires: tik
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Obsoletes: __OLD_NAME__
%description
This package contains the official __SUSE_PRODUCT_NAME__ __SUSE_VERSION__
image for Docker.
This package contains the __OS_NAME__ image for tik.
%prep
%build
%install
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native
install -p -D -m 644 %{SOURCE0} $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/
install -p -D -m 644 %{SOURCE1} $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/
install -p -D -m 644 %{SOURCE2} $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/
ln -s ./$(basename %{SOURCE0}) $RPM_BUILD_ROOT%{_datadir}/suse-docker-images/native/__PKG_NAME__
install -d -m 644 $RPM_BUILD_ROOT%{_prefix}/lib/tik/img
install -p -D -m 644 %{SOURCE0} $RPM_BUILD_ROOT%{_prefix}/lib/tik/img/%{name}.%{version}.raw.xz
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-, root, root)
%{_datadir}/suse-docker-images/native
%{_prefix}/lib/tik/img/%{name}.%{version}.raw.xz
%changelog