commit e338628f5ab51c168a6c6454659801f6f3d8aa808c0659737277be3d763c28e1 Author: Vasily Ulyanov Date: Tue Mar 16 15:55:56 2021 +0000 osc copypac from project:home:vulyanov package:obs-service-replace_using_env revision:2 OBS-URL: https://build.opensuse.org/package/show/Virtualization/obs-service-replace_using_env?expand=0&rev=1 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/README b/README new file mode 100644 index 0000000..1df5859 --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +obs-service-replace_using_env +============================= + +This service can be enabled to run during buildtime, when it will replace the +specified placeholders in the given files with the values obtained from the +build environment. Additionally it will eval all the bash commands that are +provided before doing the substitution. diff --git a/obs-service-replace_using_env.changes b/obs-service-replace_using_env.changes new file mode 100644 index 0000000..8409236 --- /dev/null +++ b/obs-service-replace_using_env.changes @@ -0,0 +1,9 @@ +------------------------------------------------------------------- +Tue Mar 16 08:33:01 UTC 2021 - Vasily Ulyanov + +- Add meta info for virt-containers + +------------------------------------------------------------------- +Mon Mar 15 06:27:20 UTC 2021 - Vasily Ulyanov + +- Initial commit diff --git a/obs-service-replace_using_env.spec b/obs-service-replace_using_env.spec new file mode 100644 index 0000000..5d4e99a --- /dev/null +++ b/obs-service-replace_using_env.spec @@ -0,0 +1,53 @@ +# +# spec file for package obs-service-replace_using_env +# +# Copyright (c) 2021 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: obs-service-replace_using_env +Version: 0.1 +Release: 0 +Summary: Service for variables substitution +License: GPL-2.0-or-later +URL: https://build.opensuse.org/ +Source0: replace_using_env +Source1: replace_using_env.service +Source2: README +Source3: virt-containers-meta +Requires: bash +Requires: sed +BuildArch: noarch + +%description +This service can be enabled to run during buildtime to replace the placeholders +in the specified files with the values from the build environment. + +%prep +cp %{SOURCE2} . + +%build + +%install +mkdir -p %{buildroot}%{_prefix}/lib/obs/service/meta +install -m 0755 %{SOURCE0} %{buildroot}%{_prefix}/lib/obs/service +install -m 0644 %{SOURCE1} %{buildroot}%{_prefix}/lib/obs/service +install -m 0755 %{SOURCE3} %{buildroot}%{_prefix}/lib/obs/service/meta + +%files +%doc README +%dir %{_prefix}/lib/obs +%{_prefix}/lib/obs/service + +%changelog diff --git a/replace_using_env b/replace_using_env new file mode 100644 index 0000000..a238887 --- /dev/null +++ b/replace_using_env @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e + +VARS=() +FILES=() +VERBOSE= + +while [ -n "$1" ]; do + param="$1" + arg="$2" + + case "${param}" in + --eval) + eval "${arg}" + shift 2 + ;; + --var) + VARS+=(${arg}) + shift 2 + ;; + --file) + FILES+=(${arg}) + shift 2 + ;; + --verbose) + VERBOSE=1 + shift 2 + ;; + *) + echo "Ignoring unknown parameter: ${param}" + shift + esac +done + +if [ ${#FILES[@]} -eq 0 ]; then + echo "No input files" + exit 0 +fi + +for var in ${VARS[@]}; do + echo "Replacing '${var}' with '${!var}'" + sed -i"" \ + -e "s#%%${var}%%#${!var}#g" \ + "${FILES[@]}" +done + +if [ -n "${VERBOSE}" ]; then + cat ${FILES[@]} +fi diff --git a/replace_using_env.service b/replace_using_env.service new file mode 100644 index 0000000..0d73e2c --- /dev/null +++ b/replace_using_env.service @@ -0,0 +1,5 @@ + + Replace placeholder variables + Replaces placeholders %%VAR%% in specified files with the +values from the build environment ${VAR}. + diff --git a/virt-containers-meta b/virt-containers-meta new file mode 100644 index 0000000..23d409e --- /dev/null +++ b/virt-containers-meta @@ -0,0 +1,17 @@ +#!/bin/bash + +distro=$(rpm --eval '%{?sle_version}:%{?is_opensuse}%{!?is_opensuse:0}') +case "${distro}" in +150200:0) + TAGPREFIX=suse/sles/15.2 + LABELPREFIX=com.suse.kubevirt + ;; +150300:0) + TAGPREFIX=suse/sles/15.3 + LABELPREFIX=com.suse.kubevirt + ;; +*) + TAGPREFIX=opensuse/tumbleweed + LABELPREFIX=org.opensuse.kubevirt + ;; +esac