Accepting request 445123 from home:fbui:branches:Base:System
- Import preset macros from systemd-rpm-macro and convert them into scripts. Presets are not supposed to be shipped by other packages as the default policy needs to be reviewed by the secteam. Therefore don't encourage packagers to do that and make those macros private to this package. Also convert them into real scripts so they're much easier to maintain and debug. Also working in %posttrans is unneeded as this package is assumed to be the only one to update the preset. - There's no need to reload the daemon configuration as presets are not part of the dameon config. OBS-URL: https://build.opensuse.org/request/show/445123 OBS-URL: https://build.opensuse.org/package/show/Base:System/systemd-presets-branding-openSUSE?expand=0&rev=83
This commit is contained in:
parent
5e864279dd
commit
38ce564eef
120
branding-preset-states
Normal file
120
branding-preset-states
Normal file
@ -0,0 +1,120 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# Written by sbrabec@suse.com
|
||||
#
|
||||
declare -a PRESET_FILES
|
||||
declare -A PRESETS
|
||||
declare -A PRESETS_OLD
|
||||
declare -A PRESETS_OLD_WILDCARD
|
||||
declare -A PRESETS_WILDCARD
|
||||
|
||||
save_preset_states () {
|
||||
PRESET_FILES=(*.preset)
|
||||
|
||||
for ((i=${#PRESET_FILES[@]}-1 ; i>= 0 ; i-- )) ; do
|
||||
FILE=${PRESET_FILES[i]}
|
||||
exec 3<"$FILE"
|
||||
while read -u3 ENABLE SERVICE PAD ; do
|
||||
if test -z "$SERVICE" ; then
|
||||
continue;
|
||||
fi
|
||||
case "$ENABLE" in
|
||||
enable|disable)
|
||||
PRESETS[$SERVICE]=$ENABLE;;
|
||||
esac
|
||||
done
|
||||
exec 3<&-
|
||||
done
|
||||
exec 3>systemd_preset-old.rpm-tmp
|
||||
for PRESET in "${!PRESETS[@]}" ; do
|
||||
echo >&3 "${PRESETS[$PRESET]} $PRESET"
|
||||
done
|
||||
exec 3>&-
|
||||
}
|
||||
|
||||
apply_preset_state_changes () {
|
||||
if ! test -f systemd_preset-old.rpm-tmp ; then
|
||||
return
|
||||
fi
|
||||
exec 3<systemd_preset-old.rpm-tmp
|
||||
while read -u3 ENABLE SERVICE PAD ; do
|
||||
if test -z "$SERVICE" ; then
|
||||
continue
|
||||
fi
|
||||
case "$ENABLE" in
|
||||
enable|disable)
|
||||
case $SERVICE in
|
||||
*"*"*|*"?"*) PRESETS_OLD_WILDCARD[$SERVICE]=$ENABLE;;
|
||||
*) PRESETS_OLD[$SERVICE]=$ENABLE;;
|
||||
esac
|
||||
esac
|
||||
done
|
||||
exec 3<&-
|
||||
PRESET_FILES=(*.preset)
|
||||
for ((i=${#PRESET_FILES[@]}-1 ; i>= 0 ; i-- )) ; do
|
||||
FILE=${PRESET_FILES[i]}
|
||||
exec 3<"$FILE"
|
||||
while read -u3 ENABLE SERVICE PAD ; do
|
||||
if test -z "$SERVICE" ; then
|
||||
continue
|
||||
fi
|
||||
case "$ENABLE" in
|
||||
enable|disable)
|
||||
case $SERVICE in
|
||||
*"*"*|*"?"*) PRESETS_WILDCARD[$SERVICE]=$ENABLE;;
|
||||
*) PRESETS[$SERVICE]=$ENABLE;;
|
||||
esac
|
||||
esac
|
||||
done
|
||||
exec 3<&-
|
||||
done
|
||||
if test -x /usr/bin/systemctl ; then
|
||||
/usr/bin/systemctl --type=service,socket list-unit-files
|
||||
fi >systemd_preset-states.rpm-tmp
|
||||
exec 3<systemd_preset-states.rpm-tmp
|
||||
read -u3 PAD
|
||||
while read -u3 SERVICE ENABLE PAD ; do
|
||||
if test -z "$SERVICE" ; then
|
||||
break
|
||||
fi
|
||||
# FIXME: This is not strictly correct as associative
|
||||
# arrays are not ordered.
|
||||
ENABLE_OLD=enable
|
||||
for PRESET in "${!PRESETS_OLD_WILDCARD[@]}" ; do
|
||||
case "$SERVICE" in
|
||||
$PRESET) ENABLE_OLD=${PRESETS_OLD_WILDCARD[$PRESET]};;
|
||||
esac
|
||||
done
|
||||
if test -n "${PRESETS_OLD[$SERVICE]}" ; then
|
||||
ENABLE_OLD="${PRESETS_OLD[$SERVICE]}"
|
||||
fi
|
||||
ENABLE_NEW=enable
|
||||
for PRESET in "${!PRESETS_WILDCARD[@]}" ; do
|
||||
case "$SERVICE" in
|
||||
$PRESET) ENABLE_NEW=${PRESETS_WILDCARD[$PRESET]};;
|
||||
esac
|
||||
done
|
||||
if test -n "${PRESETS[$SERVICE]}" ; then
|
||||
ENABLE_NEW="${PRESETS[$SERVICE]}"
|
||||
fi
|
||||
if test "$ENABLE_OLD" != "$ENABLE_NEW" ; then
|
||||
echo "Resetting $SERVICE to the new default: $ENABLE_NEW"
|
||||
/usr/bin/systemctl preset "$SERVICE" || :
|
||||
fi
|
||||
done
|
||||
exec 3<&-
|
||||
rm -f systemd_preset-{old,states}.rpm-tmp
|
||||
}
|
||||
|
||||
|
||||
cd /usr/lib/systemd/system-preset
|
||||
|
||||
case $1 in
|
||||
apply-changes)
|
||||
apply_preset_state_changes ;;
|
||||
save)
|
||||
save_preset_states ;;
|
||||
*)
|
||||
echo >&2 "Unkown command '$1'"
|
||||
exit 1
|
||||
esac
|
@ -1,3 +1,24 @@
|
||||
-------------------------------------------------------------------
|
||||
Thu Dec 8 16:40:15 UTC 2016 - fbui@suse.com
|
||||
|
||||
- Import preset macros from systemd-rpm-macro and convert them into
|
||||
scripts.
|
||||
|
||||
Presets are not supposed to be shipped by other packages as the
|
||||
default policy needs to be reviewed by the secteam. Therefore don't
|
||||
encourage packagers to do that and make those macros private to this
|
||||
package.
|
||||
|
||||
Also convert them into real scripts so they're much easier to
|
||||
maintain and debug. Also working in %posttrans is unneeded as this
|
||||
package is assumed to be the only one to update the preset.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Thu Dec 8 15:00:17 UTC 2016 - fbui@suse.com
|
||||
|
||||
- There's no need to reload the daemon configuration as presets are
|
||||
not part of the dameon config.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Nov 29 12:17:22 UTC 2016 - meissner@suse.com
|
||||
|
||||
|
@ -16,23 +16,30 @@
|
||||
#
|
||||
|
||||
|
||||
Name: systemd-presets-branding-openSUSE
|
||||
%define generic_name systemd-presets-branding
|
||||
|
||||
Name: %{generic_name}-openSUSE
|
||||
Version: 0.3.0
|
||||
Release: 0
|
||||
Summary: systemd default presets for openSUSE
|
||||
Summary: Systemd default presets for openSUSE
|
||||
License: GPL-2.0+
|
||||
Group: System/Base
|
||||
Source0: default-openSUSE.preset
|
||||
Source1: 99-default-disable.preset
|
||||
Source2: branding-preset-states
|
||||
# FIXME: why systemd is required ?
|
||||
BuildRequires: systemd
|
||||
#!BuildIgnore: systemd-presets-branding
|
||||
PreReq: coreutils
|
||||
Provides: systemd-presets-branding = %{version}
|
||||
Provides: %{generic_name} = %{version}
|
||||
Supplements: packageand(systemd:branding-openSUSE)
|
||||
Conflicts: otherproviders(systemd-presets-branding)
|
||||
Conflicts: otherproviders(%{generic_name})
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||
BuildArch: noarch
|
||||
|
||||
Requires(pre): bash
|
||||
Requires(post): bash
|
||||
|
||||
%description
|
||||
Default presets for systemd on openSUSE distribution.
|
||||
|
||||
@ -42,26 +49,35 @@ Default presets for systemd on openSUSE distribution.
|
||||
%build
|
||||
|
||||
%install
|
||||
mkdir -p %{buildroot}/usr/lib/systemd/system-preset
|
||||
install -m644 %{SOURCE0} %{buildroot}/usr/lib/systemd/system-preset/90-default-openSUSE.preset
|
||||
install -m644 %{SOURCE1} %{buildroot}/usr/lib/systemd/system-preset/
|
||||
mkdir -p %{buildroot}%{_prefix}/lib/%{generic_name}
|
||||
mkdir -p %{buildroot}%{_prefix}/lib/systemd/system-preset
|
||||
install -m644 %{SOURCE0} %{buildroot}%{_prefix}/lib/systemd/system-preset/90-default-openSUSE.preset
|
||||
install -m644 %{SOURCE1} %{buildroot}%{_prefix}/lib/systemd/system-preset/
|
||||
install -m755 %{SOURCE2} %{buildroot}%{_prefix}/lib/%{generic_name}/
|
||||
|
||||
%pre -p /bin/bash
|
||||
%systemd_preset_pre
|
||||
|
||||
%post
|
||||
systemctl daemon-reload >/dev/null 2>&1 || :
|
||||
|
||||
%postun
|
||||
if [ $1 -eq 0 ]; then
|
||||
systemctl daemon-reload >/dev/null 2>&1 || :
|
||||
%pre
|
||||
if [ $1 -gt 1 ] ; then
|
||||
#
|
||||
# Save the old state so we can detect which package have its
|
||||
# default changed later.
|
||||
#
|
||||
# Note: the old version of the script is used here.
|
||||
#
|
||||
%{_prefix}/lib/%{generic_name}/branding-preset-states save
|
||||
fi
|
||||
|
||||
%posttrans -p /bin/bash
|
||||
%systemd_preset_posttrans
|
||||
%post
|
||||
if [ $1 -gt 1 ] ; then
|
||||
#
|
||||
# Now that the updated presets are installed, find the ones
|
||||
# that have been changed and apply "systemct preset" on them.
|
||||
#
|
||||
%{_prefix}/lib/%{generic_name}/branding-preset-states apply-changes
|
||||
fi
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
/usr/lib/systemd/system-preset/*
|
||||
%{_prefix}/lib/%{generic_name}/
|
||||
%{_prefix}/lib/systemd/system-preset/*
|
||||
|
||||
%changelog
|
||||
|
Loading…
Reference in New Issue
Block a user