On 03/03/2016 04:00 PM, Stephen Gallagher wrote:
> I'm attaching the current fedora-release.spec and convert-to-edition bash
> script
> for perusal.
I'm attaching a lightly tested Lua conversion. I'm not familiar with
all the scenarios to test, so I thought I'd post what I have quite
early. Most of the pieces should be in place.
Florian
%define release_name Twenty Four
%define dist_version 24
%define bug_version 24
Summary: Fedora release files
Name: fedora-release
Version: 24
Release: 0.12
License: MIT
Group: System Environment/Base
URL: http://fedoraproject.org
Source: %{name}-%{version}.tar.bz2
Source1: convert-to-edition.lua
Obsoletes: redhat-release
Provides: redhat-release
Provides: system-release
Provides: system-release(%{version})
# Kill off the fedora-release-nonproduct package
Provides: fedora-release-nonproduct = %{version}
Obsoletes: fedora-release-nonproduct <= 23-0.3
Provides: fedora-release-standard = 22-0.8
Obsoletes: fedora-release-standard < 22-0.8
Requires: fedora-repos(%{version})
BuildArch: noarch
%description
Fedora release files such as various /etc/ files that define the release.
%package cloud
Summary: Base package for Fedora Cloud-specific default configurations
Provides: system-release-cloud
Provides: system-release-cloud(%{version})
Provides: system-release-product
Requires: fedora-release = %{version}-%{release}
%description cloud
Provides a base package for Fedora Cloud-specific configuration files to
depend on.
%package server
Summary: Base package for Fedora Server-specific default configurations
Provides: system-release-server
Provides: system-release-server(%{version})
Provides: system-release-product
Requires: fedora-release = %{version}-%{release}
Requires: systemd
Requires: cockpit
Requires: rolekit
Requires(post): sed
Requires(post): systemd
%description server
Provides a base package for Fedora Server-specific configuration files to
depend on.
%package workstation
Summary: Base package for Fedora Workstation-specific default configurations
Provides: system-release-workstation
Provides: system-release-workstation(%{version})
Provides: system-release-product
Requires: fedora-release = %{version}-%{release}
# needed for captive portal support
Requires: NetworkManager-config-connectivity-fedora
Requires(post): /usr/bin/glib-compile-schemas
Requires(postun): /usr/bin/glib-compile-schemas
%description workstation
Provides a base package for Fedora Workstation-specific configuration files to
depend on.
%prep
%setup -q
sed -i 's|@@VERSION@@|%{dist_version}|g' Fedora-Legal-README.txt
%build
%install
install -d $RPM_BUILD_ROOT/etc
echo "Fedora release %{version} (%{release_name})" > $RPM_BUILD_ROOT/etc/fedora-release
echo "cpe:/o:fedoraproject:fedora:%{version}" > $RPM_BUILD_ROOT/etc/system-release-cpe
# Symlink the -release files
ln -s fedora-release $RPM_BUILD_ROOT/etc/redhat-release
ln -s fedora-release $RPM_BUILD_ROOT/etc/system-release
# Create the common os-release file
install -d $RPM_BUILD_ROOT/usr/lib/os.release.d/
cat << EOF >>$RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-fedora
NAME=Fedora
VERSION="%{dist_version} (%{release_name})"
ID=fedora
VERSION_ID=%{dist_version}
PRETTY_NAME="Fedora %{dist_version} (%{release_name})"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:fedoraproject:fedora:%{dist_version}"
HOME_URL="https://fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=%{bug_version}
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=%{bug_version}
PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy
EOF
# Create the common /etc/issue
echo "\S" > $RPM_BUILD_ROOT/usr/lib/os.release.d/issue-fedora
echo "Kernel \r on an \m (\l)" >> $RPM_BUILD_ROOT/usr/lib/os.release.d/issue-fedora
echo >> $RPM_BUILD_ROOT/usr/lib/os.release.d/issue-fedora
# Create /etc/issue.net
echo "\S" > $RPM_BUILD_ROOT/usr/lib/issue.net
echo "Kernel \r on an \m (\l)" >> $RPM_BUILD_ROOT/usr/lib/issue.net
ln -s ../usr/lib/issue.net $RPM_BUILD_ROOT/etc/issue.net
# Create os-release and issue files for the different editions
# Cloud
cp -p $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-fedora \
$RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-cloud
echo "VARIANT=\"Cloud Edition\"" >> $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-cloud
echo "VARIANT_ID=cloud" >> $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-cloud
sed -i -e "s|(%{release_name})|(Cloud Edition)|g" $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-cloud
# Server
cp -p $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-fedora \
$RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-server
echo "VARIANT=\"Server Edition\"" >> $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-server
echo "VARIANT_ID=server" >> $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-server
sed -i -e "s|(%{release_name})|(Server Edition)|g" $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-server
cp -p $RPM_BUILD_ROOT/usr/lib/os.release.d/issue-fedora \
$RPM_BUILD_ROOT/usr/lib/os.release.d/issue-server
echo "Admin Console: https://\4:9090/ or https://[\6]:9090/" >> $RPM_BUILD_ROOT/usr/lib/os.release.d/issue-server
echo >> $RPM_BUILD_ROOT/usr/lib/os.release.d/issue-server
# Workstation
cp -p $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-fedora \
$RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-workstation
echo "VARIANT=\"Workstation Edition\"" >> $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-workstation
echo "VARIANT_ID=workstation" >> $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-workstation
sed -i -e "s|(%{release_name})|(Workstation Edition)|g" $RPM_BUILD_ROOT/usr/lib/os.release.d/os-release-workstation
# Create the symlink for /etc/os-release
# We don't create the /usr/lib/os-release symlink until %%post
# so that we can ensure that the right one is referenced.
ln -s ../usr/lib/os-release $RPM_BUILD_ROOT/etc/os-release
# Create the symlink for /etc/issue
# We don't create the /usr/lib/os-release symlink until %%post
# so that we can ensure that the right one is referenced.
ln -s ../usr/lib/issue $RPM_BUILD_ROOT/etc/issue
# Set up the dist tag macros
install -d -m 755 $RPM_BUILD_ROOT%{_rpmconfigdir}/macros.d
cat >> $RPM_BUILD_ROOT%{_rpmconfigdir}/macros.d/macros.dist << EOF
# dist macros.
%%fedora %{dist_version}
%%dist .fc%{dist_version}
%%fc%{dist_version} 1
EOF
# Add presets
mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/user-preset/
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-preset/
mkdir -p $RPM_BUILD_ROOT/usr/lib/os.release.d/presets
# Default system wide
install -m 0644 85-display-manager.preset $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-preset/
install -m 0644 90-default.preset $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-preset/
install -m 0644 99-default-disable.preset $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-preset/
# Fedora Server
install -m 0644 80-server.preset $RPM_BUILD_ROOT%{_prefix}/lib/os.release.d/presets/
# Fedora Workstation
install -m 0644 80-workstation.preset $RPM_BUILD_ROOT%{_prefix}/lib/os.release.d/presets/
# Override the list of enabled gnome-shell extensions for Workstation
mkdir -p $RPM_BUILD_ROOT%{_datadir}/glib-2.0/schemas/
install -m 0644 org.gnome.shell.gschema.override $RPM_BUILD_ROOT%{_datadir}/glib-2.0/schemas/
# Copy the make_edition script to /usr/sbin
mkdir -p $RPM_BUILD_ROOT/%{_prefix}/sbin/
install -m 0744 convert-to-edition $RPM_BUILD_ROOT/%{_prefix}/sbin/
%post -p <lua>
%include %{SOURCE1}
-- On initial installation, we'll at least temporarily put the non-product
-- symlinks in place. It will be overridden by fedora-release-$EDITION
-- %%post sections because we don't write the /usr/lib/variant file until
-- %%posttrans to avoid trumping the fedora-release-$EDITION packages.
-- This is necessary to avoid breaking systemctl scripts since they rely on
-- /usr/lib/os-release being valid. We can't wait until %%posttrans to default
-- to os-release-fedora.
if arg[2] == "0" then
set_release(fedora)
set_issue(fedora)
end
-- We also want to forcibly set these paths on upgrade if we are explicitly
-- set to "nonproduct"
if read_variant() == "nonproduct" then
convert_to_edition("nonproduct", false)
end
%posttrans -p <lua>
%include %{SOURCE1}
-- If we get to %%posttrans and nothing created /usr/lib/variant, set it to
-- nonproduct.
if posix.stat(VARIANT_FILE) == nil then
convert_to_edition("nonproduct", true)
end
%post cloud -p <lua>
%include %{SOURCE1}
install_edition("cloud")
%preun cloud -p <lua>
%include %{SOURCE1}
uninstall_edition("cloud")
%post server -p <lua>
%include %{SOURCE1}
install_edition("server")
%preun server -p <lua>
%include %{SOURCE1}
uninstall_edition("server")
%post workstation -p <lua>
%include %{SOURCE1}
install_edition("workstation")
%preun workstation -p <lua>
%include %{SOURCE1}
uninstall_edition("workstation")
%postun workstation
if [ $1 -eq 0 ] ; then
glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
fi
%posttrans workstation
glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
%files
%defattr(-,root,root,-)
%{!?_licensedir:%global license %%doc}
%license LICENSE Fedora-Legal-README.txt
%ghost /usr/lib/variant
%dir /usr/lib/os.release.d
%dir /usr/lib/os.release.d/presets
%config %attr(0644,root,root) /usr/lib/os.release.d/os-release-fedora
%ghost /usr/lib/os-release
/etc/os-release
%config %attr(0644,root,root) /etc/fedora-release
/etc/redhat-release
/etc/system-release
%config %attr(0644,root,root) /etc/system-release-cpe
%config %attr(0644,root,root) /usr/lib/os.release.d/issue-fedora
%ghost /usr/lib/issue
%config(noreplace) /etc/issue
%config %attr(0644,root,root) /usr/lib/issue.net
%config(noreplace) /etc/issue.net
%attr(0644,root,root) %{_rpmconfigdir}/macros.d/macros.dist
%dir /usr/lib/systemd/user-preset/
%dir %{_prefix}/lib/systemd/system-preset/
%{_prefix}/lib/systemd/system-preset/85-display-manager.preset
%{_prefix}/lib/systemd/system-preset/90-default.preset
%{_prefix}/lib/systemd/system-preset/99-default-disable.preset
/usr/sbin/convert-to-edition
%files cloud
%{!?_licensedir:%global license %%doc}
%license LICENSE
%config %attr(0644,root,root) /usr/lib/os.release.d/os-release-cloud
%files server
%{!?_licensedir:%global license %%doc}
%license LICENSE
%config %attr(0644,root,root) /usr/lib/os.release.d/os-release-server
%config %attr(0644,root,root) /usr/lib/os.release.d/issue-server
%ghost %{_prefix}/lib/systemd/system-preset/80-server.preset
%config %attr(0644,root,root) /usr/lib/os.release.d/presets/80-server.preset
%files workstation
%{!?_licensedir:%global license %%doc}
%license LICENSE
%config %attr(0644,root,root) /usr/lib/os.release.d/os-release-workstation
%{_datadir}/glib-2.0/schemas/org.gnome.shell.gschema.override
%ghost %{_prefix}/lib/systemd/system-preset/80-workstation.preset
%config %attr(0644,root,root) /usr/lib/os.release.d/presets/80-workstation.preset
%changelog
* Mon Feb 29 2016 Stephen Gallagher <sgall...@redhat.com> - 24-0.12
- Only run grub2-mkconfig for platforms that support it
- Remove erroneous RPM_BUILD_ROOT variables in convert-to-edition
* Fri Feb 26 2016 Stephen Gallagher <sgall...@redhat.com> - 24-0.11
- Fix upgrade bug in Workstation and Cloud
* Tue Feb 23 2016 Dennis Gilmore <den...@ausil.us> - 24-0.10
- setup for f24 being branched
* Thu Jan 21 2016 Stephen Gallagher <sgall...@redhat.com> 24-0.9
- Install Edition presets only for the configured Edition
- Add script to convert from non-edition to an Edition
- Fix upgrade bugs with non-edition installs
- Explicitly set issue-fedora for cloud installs
- Resolves: rhbz#1288205
* Tue Dec 15 2015 Stephen Gallagher <sgall...@redhat.com> 24-0.8
- Fix copy-paste error for Workstation os-release and issue
* Tue Sep 29 2015 Stephen Gallagher <sgall...@redhat.com> 24-0.7
- Rework os-release and issue mechanism to avoid upgrade issues such as
competing fedora-release-$EDITION packages
- Make a non-product install persistent (it won't be converted to an Edition
install if something pulls in a fedora-release-$EDITION package
* Mon Sep 28 2015 Dennis Gilmore <den...@ausil.us> - 24-0.6
- set bug_version to be rawhide rhbz#1259287
* Tue Sep 15 2015 Stephen Gallagher <sgall...@redhat.com> - 24-0.5
- Do not clobber /etc/issue[.net] customizations
* Wed Sep 09 2015 Stephen Gallagher <sgall...@redhat.com> - 24-0.4
- Update preset file with FESCo decisions
- https://fedorahosted.org/fesco/ticket/1472
* Wed Sep 09 2015 Stephen Gallagher <sgall...@redhat.com> - 24-0.3
- Enclose IPv6 addresses in square brackets in /etc/issue
* Mon Aug 24 2015 Stephen Gallagher <sgall...@redhat.com> - 24-0.2
- Make /etc/issue configurable per-edition
- Resolves: RHBZ#1239089
* Tue Jul 14 2015 Dennis Gilmore <den...@ausil.us> - 24-0.1
- setup for rawhide being f24
-- This is intended to be run as an RPM scriptlet.
local VARIANT_FILE = "/usr/lib/variant"
local disable_presets = false
local function read_variant()
local variant
local f = io.open("/usr/lib/variant", "r")
if f ~= nil then
while true do
local line = f:read()
if line == nil then
break
end
local m = line:match("^VARIANT_ID=([^\n]+)")
if m ~= nil then
variant = m
end
end
end
return variant
end
local function writefile(path, data)
local tmp = path .. ".convert-to-edition"
local f = io.open(tmp, "w+")
if f == nil then
return
end
f:write(data)
f:close()
if not os.rename(tmp, path) then
os.remove(tmp)
end
end
local function symlink(from, to)
os.remove(to)
assert(posix.symlink(from, to))
end
local function execute(...)
local pid = posix.fork()
if pid == 0 then
posix.exec(...)
posix.exit(1)
elseif pid ~= -1 then
local status = posix.wait(pid)
if status ~= 0 then
local program = ...
error(program .. " exited with status " .. status)
end
end
end
local function clear_presets()
local path = "/usr/lib/systemd/system-preset"
for file in posix.files(path) do
if file:match("^80-.*%.preset$") then
os.remove(path .. "/" .. file)
end
end
end
local function read_presets(path)
local result = {}
local f = assert(io.open(path))
if f ~= nil then
while true do
local line = f:read()
if line == nil then
break
end
local cmd, arg = line:match("^([^ \t]+)[ \t]+([^\n \t]+)")
if cmd == "enable" or cmd == "disable" then
result[#result + 1] = arg
end
f:close()
end
end
return result
end
local function set_variant(variant)
writefile(VARIANT_FILE, "VARIANT_ID=" .. variant .. "\n")
end
local function set_release(release)
symlink("./os.release.d/os-release-" .. release, "/usr/lib/os-release")
end
local function set_issue(release)
symlink("./os.release.d/issue-" .. release, "/usr/lib/issue")
end
local variants = {
cloud = {release = "cloud", issue = "fedora", presets = false},
nonproduct = {release = "fedora", issue = "fedora", presets = false},
server = {release = "server", issue = "server", presets = true},
server = {release = "workstation", issue = "fedora", presets = true},
}
local function set_presets(edition)
if variants[edition].presets then
local target = "/usr/lib/systemd/system-preset/80-" .. edition .. ".preset"
symlink("../../os.edition.d/presets/80-" .. edition .. ".preset", target)
local presets = read_presets(target)
os.execute("/usr/bin/systemctl", "preset", "-q",
table.unpack(presets))
end
end
local function convert_to_edition(edition, do_presets)
local variant = variants[edition]
if variant == nil then
error("undefined edition: " .. edition)
end
set_release(variant.release)
set_issue(variant.issue)
clear_presets()
if do_presets then
set_presets(edition)
end
local grub = "/usr/sbin/grub2-mkconfig"
if posix.access(grub) then
execute(grub, "-o", "/boot/grub2/grub.cfg")
end
print("This system has been converted to " .. edition)
end
local function install_edition(edition)
-- Create the variant file if it does not already exist. This needs
-- to be done on both installation and upgrade, to ensure that we
-- upgrade from F23 and earlier properly.
if not posix.access(VARIANT_FILE, "f") then
set_variant(edition)
end
if read_variant() == edition then
-- (On initial installation only), fix up after %%systemd_post
-- in packages possibly installed before our preset file was
-- added
-- On upgrades, do not enable or disable presets to avoid
-- surprising the user
local initial_install = arg[2] == "1"
convert_to_edition(edition, initial_install)
end
end
local function uninstall_edition(edition)
-- If we are uninstalling, we need to reset the variant file and
-- force the os-release file back to os-release-fedora. We do this
-- in %%preun so that we don't have any time where the os-release
-- symlink is dangling (since in %%postun, the os-release-$EDITION
-- file will have already been removed)
if arg[2] == "0" then
if read_variant() == edition then
convert_to_edition("nonproduct", false)
end
end
end
--
devel mailing list
devel@lists.fedoraproject.org
http://lists.fedoraproject.org/admin/lists/devel@lists.fedoraproject.org