From 168942bb7a18122e5d67c8274f60859a153450a2 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Feb 03 2016 18:51:33 +0000 Subject: 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 Signed-off-by: Stephen Gallagher --- diff --git a/convert-to-edition b/convert-to-edition new file mode 100755 index 0000000..70a3969 --- /dev/null +++ b/convert-to-edition @@ -0,0 +1,168 @@ +#!/bin/bash + +# Simple script to set up Edition defaults for Fedora + +OPTIND=1 + +VARIANT_FILE=/usr/lib/variant + +# Defaults are set to provide the fewest suprises for anyone running this +# script manually to convert their own system. In nearly all cases, it should +# be possible to run `convert-to-edition -e ` and get expected results + +# By default, install new packages to ensure that all the necessary files are +# available before symlinking. This must be skipped when running this file as +# part of an RPM scriptlet. +do_installation=1 + +# By default, do not modify the enabled or disabled state of any service on the +# system. This should only be done when this script is run as part of system +# installation or if the user is certain that they want to apply the changes to +# the presets to their system. +enable_presets=0 + +exit_usage() { + echo "Usage: convert-to-edition [options] -e cloud|non-edition|server|workstation" + echo " Options:" + echo " -e: The edition to install (cloud, non-edition, server or workstation)" + echo " -i: Skip installing additional files and just update symlinks" + echo " -p: Also enable newly-added systemd presets" + exit 1 +} + +while getopts "e:ihp" opt; do + case "$opt" in + e) + EDITION=$OPTARG + ;; + i) + do_installation=0 + ;; + p) + enable_presets=1 + ;; + h) + exit_usage + ;; + esac +done + +# None of the actions below can be run by a non-root user +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +case $EDITION in + cloud) + if [ $do_installation -gt 0 ]; then + echo "Installing Fedora Cloud Packages" + dnf install -y fedora-release-cloud + fi + + echo "VARIANT_ID=cloud" > $VARIANT_FILE + + # Ensure that the os-release file is pointing to the correct version + ln -sf ./os.release.d/os-release-cloud /usr/lib/os-release || : + + # Ensure that the issue file is pointing to the correct version + ln -sf ./os.release.d/issue-fedora $RPM_BUILD_ROOT/usr/lib/issue + + # Remove any presets from other Editions. + rm -f /usr/lib/systemd/system-preset/80-*.preset + ;; + + non-edition) + echo "VARIANT_ID=nonproduct" > $VARIANT_FILE + + # Ensure that the os-release file is pointing to the correct version + ln -sf ./os.release.d/os-release-fedora /usr/lib/os-release || : + + # Ensure that the issue file is pointing to the correct version + ln -sf ./os.release.d/issue-fedora $RPM_BUILD_ROOT/usr/lib/issue + + # Remove any presets from other Editions. + rm -f /usr/lib/systemd/system-preset/80-*.preset + ;; + + server) + if [ $do_installation -gt 0 ]; then + echo "Installing Fedora Server Packages" + dnf install -y fedora-release-server + fi + + echo "VARIANT_ID=server" > $VARIANT_FILE + + # Ensure that the os-release and issue files are pointing to the correct + # version + ln -sf ./os.release.d/os-release-server /usr/lib/os-release + ln -sf ./os.release.d/issue-server /usr/lib/issue + + # Remove any presets from other Editions. This should always be a no-op, + # but it's good to be explicit. + # We reserve 80-*.preset for Editions + rm -f /usr/lib/systemd/system-preset/80-*.preset + + # Symlink in the proper preset + ln -sf ../../os.release.d/presets/80-server.preset \ + /usr/lib/systemd/system-preset/80-server.preset + + if [ $enable_presets -gt 0 ]; then + # Enable new units specified by presets + units=$(sed -n 's/^enable//p' \ + < /usr/lib/systemd/system-preset/80-server.preset) + /usr/bin/systemctl preset $units >/dev/null 2>&1 || : + + # Disable new units specified by presets + units=$(sed -n 's/^disable//p' \ + < /usr/lib/systemd/system-preset/80-server.preset) + /usr/bin/systemctl preset $units >/dev/null 2>&1 || : + fi + ;; + + workstation) + if [ $do_installation -gt 0 ]; then + echo "Installing Fedora Workstation Packages" + dnf install -y fedora-release-workstation + fi + + echo "VARIANT_ID=workstation" > $VARIANT_FILE + # Ensure that the os-release and issue files are pointing to the correct + # version + ln -sf ./os.release.d/os-release-workstation /usr/lib/os-release + ln -sf ./os.release.d/issue-fedora /usr/lib/issue + + # Remove any presets from other Editions. This should always be a no-op, + # but it's good to be explicit. + # We reserve 80-*.preset for Editions + rm -f /usr/lib/systemd/system-preset/80-*.preset + + # Symlink in the proper preset + ln -sf ../../os.release.d/presets/80-workstation.preset \ + /usr/lib/systemd/system-preset/80-workstation.preset + + if [ $enable_presets -gt 0 ]; then + # Enable new units specified by presets + units=$(sed -n 's/^enable//p' \ + < /usr/lib/systemd/system-preset/80-workstation.preset) + /usr/bin/systemctl preset $units >/dev/null 2>&1 || : + + # Disable new units specified by presets + units=$(sed -n 's/^disable//p' \ + < /usr/lib/systemd/system-preset/80-workstation.preset) + /usr/bin/systemctl preset $units >/dev/null 2>&1 || : + fi + ;; + + *) + exit_usage + ;; +esac + +# Update the grub2 bootloader text to show the correct edition +grub2-mkconfig -o /boot/grub2/grub.cfg + +echo This system has been converted to $EDITION + +exit 0 + diff --git a/fedora-release.spec b/fedora-release.spec index 32b7799..a5eebc7 100644 --- a/fedora-release.spec +++ b/fedora-release.spec @@ -5,7 +5,7 @@ Summary: Fedora release files Name: fedora-release Version: 24 -Release: 0.8 +Release: 0.9 License: MIT Group: System Environment/Base URL: http://fedoraproject.org @@ -164,19 +164,25 @@ 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/systemd/system-preset/ +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/systemd/system-preset/ +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 # On initial installation, we'll at least temporarily put the non-product # symlinks in place. It will be overridden by fedora-release-$EDITION @@ -186,22 +192,31 @@ install -m 0644 org.gnome.shell.gschema.override $RPM_BUILD_ROOT%{_datadir}/glib # /usr/lib/os-release being valid. We can't wait until %%posttrans to default # to os-release-fedora. if [ $1 = 0 ]; then - ln -s ./os.release.d/os-release-fedora $RPM_BUILD_ROOT/usr/lib/os-release || : - ln -s ./os.release.d/issue-fedora $RPM_BUILD_ROOT/usr/lib/issue || : + ln -sf ./os.release.d/os-release-fedora $RPM_BUILD_ROOT/usr/lib/os-release || : + ln -sf ./os.release.d/issue-fedora $RPM_BUILD_ROOT/usr/lib/issue || : fi -%posttrans - # If we get to %%posttrans and nothing created /usr/lib/variant, set it to - # nonproduct +# We also want to forcibly set these paths on upgrade if we are explicitly +# set to "nonproduct" +if [ -e /usr/lib/variant ]; then . /usr/lib/variant || : - if [ "x$VARIANT_ID" = "x" ]; then - echo "VARIANT_ID=nonproduct" > /usr/lib/variant || : + if [ "x$VARIANT_ID" = "xnonproduct" ]; then + # Run the convert-to-edition script. + %{_prefix}/sbin/convert-to-edition -ie non-edition fi +fi + +%posttrans +# If we get to %%posttrans and nothing created /usr/lib/variant, set it to +# nonproduct +if [ \! -e /usr/lib/variant ]; then + %{_prefix}/sbin/convert-to-edition -ipe non-edition +fi %post cloud # == Run every time == # 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 Beta +# on both installation and upgrade, to ensure that we upgrade from F23 # and earlier properly. if [ \! -e /usr/lib/variant ]; then echo "VARIANT_ID=cloud" > /usr/lib/variant || : @@ -209,8 +224,15 @@ fi . /usr/lib/variant || : if [ "x$VARIANT_ID" = "xcloud" ]; then - # Ensure that the os-release file is pointing to the correct version - ln -sf ./os.release.d/os-release-cloud /usr/lib/os-release || : + if [ $1 -eq 1 ] ; then + # (On initial installation only), fix up after %%systemd_post in packages + # possibly installed before our preset file was added + %{_prefix}/sbin/convert-to-edition -ipe cloud + else + # On upgrades, do not enable or disable presets to avoid surprising + # the user + %{_prefix}/sbin/convert-to-edition -ip cloud + fi fi %preun cloud @@ -222,8 +244,8 @@ fi if [ $1 = 0 ]; then . /usr/lib/variant || : if [ "x$VARIANT_ID" = "xcloud" ]; then - ln -sf ./os.release.d/os-release-fedora /usr/lib/os-release || : - echo "VARIANT_ID=nonproduct" > /usr/lib/variant || : + # Do not enable or disable presets when uninstalling + %{_prefix}/sbin/convert-to-edition -ie non-edition fi fi @@ -231,7 +253,7 @@ fi %post server # == Run every time == # 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 Beta +# on both installation and upgrade, to ensure that we upgrade from F23 # and earlier properly. if [ \! -e /usr/lib/variant ]; then echo "VARIANT_ID=server" > /usr/lib/variant || : @@ -239,19 +261,15 @@ fi . /usr/lib/variant || : if [ "x$VARIANT_ID" = "xserver" ]; then - # Ensure that the os-release and issue files are pointing to the correct - # version - ln -sf ./os.release.d/os-release-server /usr/lib/os-release - ln -sf ./os.release.d/issue-server /usr/lib/issue -fi - -# (On initial installation only), fix up after %%systemd_post in packages -# possibly installed before our preset file was added -# This must be done after the os-release file has been symlinked properly. -if [ $1 -eq 1 ] ; then - units=$(sed -n 's/^enable//p' \ - < %{_prefix}/lib/systemd/system-preset/80-server.preset) - /usr/bin/systemctl preset $units >/dev/null 2>&1 || : + if [ $1 -eq 1 ] ; then + # (On initial installation only), fix up after %%systemd_post in packages + # possibly installed before our preset file was added + %{_prefix}/sbin/convert-to-edition -ipe server + else + # On upgrades, do not enable or disable presets to avoid surprising + # the user + %{_prefix}/sbin/convert-to-edition -ie server + fi fi %preun server @@ -263,16 +281,15 @@ fi if [ $1 = 0 ]; then . /usr/lib/variant || : if [ "x$VARIANT_ID" = "xserver" ]; then - ln -sf ./os.release.d/os-release-fedora /usr/lib/os-release || : - ln -sf ./os.release.d/issue-fedora /usr/lib/issue || : - echo "VARIANT_ID=nonproduct" > /usr/lib/variant || : + # Do not enable or disable presets when uninstalling + %{_prefix}/sbin/convert-to-edition -ie non-edition fi fi %post workstation # == Run every time == # 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 Beta +# on both installation and upgrade, to ensure that we upgrade from F23 # and earlier properly. if [ \! -e /usr/lib/variant ]; then echo "VARIANT_ID=workstation" > /usr/lib/variant || : @@ -280,19 +297,15 @@ fi . /usr/lib/variant || : if [ "x$VARIANT_ID" = "xworkstation" ]; then - # Ensure that the os-release and issue files are pointing to the correct - # version - ln -sf ./os.release.d/os-release-workstation /usr/lib/os-release - ln -sf ./os.release.d/issue-fedora /usr/lib/issue -fi - -# (On initial installation only), fix up after %%systemd_post in packages -# possibly installed before our preset file was added -# This must be done after the os-release file has been symlinked properly. -if [ $1 -eq 1 ] ; then - units=$(sed -n 's/^disable//p' \ - < %{_prefix}/lib/systemd/system-preset/80-workstation.preset) - /usr/bin/systemctl preset $units >/dev/null 2>&1 || : + if [ $1 -eq 1 ] ; then + # (On initial installation only), fix up after %%systemd_post in packages + # possibly installed before our preset file was added + %{_prefix}/sbin/convert-to-edition -ipe workstation + else + # On upgrades, do not enable or disable presets to avoid surprising + # the user + %{_prefix}/sbin/convert-to-edition -ip workstation + fi fi %preun workstation @@ -304,9 +317,8 @@ fi if [ $1 = 0 ]; then . /usr/lib/variant || : if [ "x$VARIANT_ID" = "xworkstation" ]; then - ln -sf ./os.release.d/os-release-fedora /usr/lib/os-release || : - ln -sf ./os.release.d/issue-fedora /usr/lib/issue || : - echo "VARIANT_ID=nonproduct" > /usr/lib/variant || : + # Do not enable or disable presets when uninstalling + %{_prefix}/sbin/convert-to-edition -ie non-edition fi fi @@ -325,6 +337,7 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || : %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 @@ -343,6 +356,7 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || : %{_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} @@ -355,16 +369,25 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || : %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 -%{_prefix}/lib/systemd/system-preset/80-server.preset +%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 -%{_prefix}/lib/systemd/system-preset/80-workstation.preset +%ghost %{_prefix}/lib/systemd/system-preset/80-workstation.preset +%config %attr(0644,root,root) /usr/lib/os.release.d/presets/80-workstation.preset %changelog +* Thu Jan 21 2016 Stephen Gallagher 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 24-0.8 - Fix copy-paste error for Workstation os-release and issue