From 594f8c79e22cd089e8fe0056eff34aef54615cd6e9d3522793e84622e3aa324f Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Tue, 2 Jul 2024 11:49:40 +0000 Subject: [PATCH] - Support also creating systemd-repart bundles OBS-URL: https://build.opensuse.org/package/show/devel:microos:aeon/containment-tik-img-to-rpm?expand=0&rev=27 --- .gitattributes | 23 +++++++++ .gitignore | 1 + containment-tik-img-to-rpm | 80 ++++++++++++++++++++++++++++++ containment-tik-img-to-rpm.changes | 25 ++++++++++ containment-tik-img-to-rpm.spec | 54 ++++++++++++++++++++ image.spec.in | 53 ++++++++++++++++++++ 6 files changed, 236 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 containment-tik-img-to-rpm create mode 100644 containment-tik-img-to-rpm.changes create mode 100644 containment-tik-img-to-rpm.spec create mode 100644 image.spec.in diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/containment-tik-img-to-rpm b/containment-tik-img-to-rpm new file mode 100644 index 0000000..c3c426a --- /dev/null +++ b/containment-tik-img-to-rpm @@ -0,0 +1,80 @@ +#!/bin/sh -eu +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 "Check for tik-osimage-*.raw.xz in KIWI output directory" +if ! ls ${img_dir}/tik-osimage-*.raw.xz; then + log "No tik-osimage found" && exit 0 +fi + +log "tik-osimage-* found: Creating RPM from any tik-osimage-*.raw.xz images" + +for f in ${img_dir}/*.raw.xz; do + base_f=$(echo ${f} | awk -F '.raw.xz' '{print $1}' | awk -F "${img_dir}/" '{print $2}') + 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 + + cp /.build-changelog ${build_dir}/image.changes + ${build_dir}/changelog2spec --target rpm --file ${build_dir}/image.changes >> ${build_dir}/image.spec + + # Local builds have the file already in place, that's not true on IBS + if [ ! -f ${top_dir}/SOURCES/${image} ]; then + ln ${f} ${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 diff --git a/containment-tik-img-to-rpm.changes b/containment-tik-img-to-rpm.changes new file mode 100644 index 0000000..b818b49 --- /dev/null +++ b/containment-tik-img-to-rpm.changes @@ -0,0 +1,25 @@ +------------------------------------------------------------------- +Tue Jul 2 11:49:14 UTC 2024 - Richard Brown + +- Support also creating systemd-repart bundles + +------------------------------------------------------------------- +Thu Jun 20 15:13:08 UTC 2024 - Richard Brown + +- Adjust for new obs-build changelog location + +------------------------------------------------------------------- +Tue May 14 09:49:57 UTC 2024 - Richard Brown + +- Handle changelog properly, to work with reproducible builds + in Factory + +------------------------------------------------------------------- +Fri May 10 18:19:04 UTC 2024 - Richard Brown + +- Conflict with containment-rpm + +------------------------------------------------------------------- +Fri May 10 10:20:40 UTC 2024 - Richard Brown + +- Initial package diff --git a/containment-tik-img-to-rpm.spec b/containment-tik-img-to-rpm.spec new file mode 100644 index 0000000..0d43dcc --- /dev/null +++ b/containment-tik-img-to-rpm.spec @@ -0,0 +1,54 @@ +# +# spec file for package containment-tik-img-to-rpm +# +# Copyright (c) 2024 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +Name: containment-tik-img-to-rpm +Version: 1.0 +Release: 0 +Summary: OBS Post check for containing tik-osimage-* images in RPM +License: MIT +Source: containment-tik-img-to-rpm +Source1: image.spec.in +BuildRequires: filesystem +BuildArch: noarch +BuildRoot: %{_tmppath}/%{name}-%{version}-build +Requires: build +Requires: coreutils +Requires: gawk +Requires: jq +Requires: perl-DateTime-Format-DateParse +Conflicts: containment-rpm + +%description +OBS Post check for containing tik-osimage-* images in RPM + +%prep + +%build + +%install +mkdir -p %{buildroot}/usr/lib/build/post-build-checks/ +install -m 755 %{SOURCE0} %{buildroot}/usr/lib/build/post-build-checks/ +install -m 644 %{SOURCE1} %{buildroot}/usr/lib/build/ + +%files +%defattr(-,root,root) +%dir %{_prefix}/lib/build/post-build-checks +%{_prefix}/lib/build/post-build-checks/containment-tik-img-to-rpm +%{_prefix}/lib/build/image.spec.in + +%changelog diff --git a/image.spec.in b/image.spec.in new file mode 100644 index 0000000..4a3f1fc --- /dev/null +++ b/image.spec.in @@ -0,0 +1,53 @@ +# needsrootforbuild + +Url: http://www.aeondeskop.org/ +Name: __PKG_NAME__ +Summary: Package with __OS_NAME__ tik OS image +Version: __VERSION__ +Release: __RELEASE__ +Group: System/Management +License: GPL-2.0+ +Source0: __SOURCE0__ +Requires: tik +BuildRoot: %{_tmppath}/%{name}-%{version}-build + +%description +This package contains the __OS_NAME__ image for tik. + +%package repart-bundle +BuildRequires: udev +BuildRequires: xz +BuildRequires: systemd-repart-branding-Aeon +BuildRequires: coreutils + +%description repart-bundle +This package containers the __OS_NAME__ systemd-repart bundle for tik + +%prep + +%build +xz -d %{SOURCE0} +systemd-repart --split=1 %(basename ${SOURCE0} xz) + +%install +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 + +install -d -m 644 $RPM_BUILD_ROOT%{_prefix}/lib/tik/img/%{name}.%{version} +install -p -D -m 644 %(basename ${SOURCE0} .raw.xz).root-%{_arch}.raw $RPM_BUILD_ROOT%{_prefix}/lib/tik/img/%{name}.%{version}/ +install -d -m 644 $RPM_BUILD_ROOT%{_prefix}/lib/tik/img/%{name}.%{version}/repart.d +install -p -D -m 644 %{_prefix}/lib/repart.d/* $RPM_BUILD_ROOT%{_prefix}/lib/tik/img/%{name}.%{version}/repart.d + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-, root, root) +%{_prefix}/lib/tik/img/%{name}.%{version}.raw.xz + +%files repart-bundle +%defattr(-, root, root) +%{_prefix}/lib/tik/img/%{name}.%{version} + + +%changelog