Accepting request 221392 from Base:System
- add grub2-snapper-plugin.sh (fate#316232) * grub2's snapper plugin for advanced btrfs snapshot menu management * package as grub2-snapper-plugin.noarch - refresh 0002-script-create-menus-for-btrfs-snapshot.patch * when booting btrfs snapshots disabled, deleting snapshot master config if it's not customized (forwarded request 221073 from michael-chang) OBS-URL: https://build.opensuse.org/request/show/221392 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/grub2?expand=0&rev=84
This commit is contained in:
parent
f82e4ea3dc
commit
b664720e25
@ -20,6 +20,10 @@ v2:
|
|||||||
* Create missing slave config in /.snapshots/<num>/
|
* Create missing slave config in /.snapshots/<num>/
|
||||||
* Prefix with SUSE_ for related options
|
* Prefix with SUSE_ for related options
|
||||||
|
|
||||||
|
v3:
|
||||||
|
* When booting btrfs snapshots disabled, deleting snapshot master config
|
||||||
|
if it's not customized
|
||||||
|
|
||||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||||
|
|
||||||
Index: grub-2.02~beta2/Makefile.util.def
|
Index: grub-2.02~beta2/Makefile.util.def
|
||||||
@ -60,7 +64,7 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
|
|||||||
===================================================================
|
===================================================================
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
|
+++ grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
|
||||||
@@ -0,0 +1,171 @@
|
@@ -0,0 +1,174 @@
|
||||||
+#! /bin/sh
|
+#! /bin/sh
|
||||||
+set -e
|
+set -e
|
||||||
+
|
+
|
||||||
@ -122,7 +126,10 @@ Index: grub-2.02~beta2/util/grub.d/80_btrfs_snapshot.in
|
|||||||
+# specify SUSE_DISABLE_BOOTING_SNAPSHOT=false the update the config
|
+# specify SUSE_DISABLE_BOOTING_SNAPSHOT=false the update the config
|
||||||
+if [ "x${SUSE_DISABLE_BOOTING_SNAPSHOT}" != "xfalse" ]; then
|
+if [ "x${SUSE_DISABLE_BOOTING_SNAPSHOT}" != "xfalse" ]; then
|
||||||
+ rm -f "/${slave_cfg}"
|
+ rm -f "/${slave_cfg}"
|
||||||
+ rm -f "${master_snapshot_cfg}"
|
+# Delete snapshot master config if not customized
|
||||||
|
+ if [ "x${SUSE_ENABLE_CUSTOM_SNAPSHOT_SUBMENU}" != "xtrue" ]; then
|
||||||
|
+ rm -f "${master_snapshot_cfg}"
|
||||||
|
+ fi
|
||||||
+ exit 0
|
+ exit 0
|
||||||
+fi
|
+fi
|
||||||
+
|
+
|
||||||
|
189
grub2-snapper-plugin.sh
Normal file
189
grub2-snapper-plugin.sh
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||||
|
#
|
||||||
|
# GRUB is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# GRUB is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
grub_mkconfig="/usr/sbin/grub2-mkconfig"
|
||||||
|
grub_mkrelpath="/usr/bin/grub2-mkrelpath"
|
||||||
|
grub_setting="/etc/default/grub"
|
||||||
|
grub_cfg="/boot/grub2/grub.cfg"
|
||||||
|
grub_snapshot_cfg="/boot/grub2/snapshot_submenu.cfg"
|
||||||
|
|
||||||
|
snapshot_submenu_name="snapshot_submenu.cfg"
|
||||||
|
snapshot_menuentry_name="snapshot_menuentry.cfg"
|
||||||
|
snapshot_menuentry_cfg="boot/grub2/${snapshot_menuentry_name}"
|
||||||
|
|
||||||
|
rel_root=`"$grub_mkrelpath" /`
|
||||||
|
|
||||||
|
snapshot_submenu_refresh () {
|
||||||
|
|
||||||
|
for s_dir in /.snapshots/*; do
|
||||||
|
|
||||||
|
snapshot="${s_dir}/snapshot"
|
||||||
|
snapper_cfg="${s_dir}/${snapshot_submenu_name}"
|
||||||
|
|
||||||
|
if [ ! -d "$snapshot" ]; then
|
||||||
|
rm -f "${snapper_cfg}"
|
||||||
|
rm -f "${s_dir}/${snapshot_menuentry_name}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
cfgs="${s_dir}/${snapshot_menuentry_name} ${snapshot}/${snapshot_menuentry_cfg}"
|
||||||
|
date=`xmllint --xpath '/snapshot/date/text()' "${s_dir}/info.xml" || echo ""`
|
||||||
|
|
||||||
|
cat <<EOF > "${snapper_cfg}.new"
|
||||||
|
|
||||||
|
for x in $cfgs; do
|
||||||
|
snap="${rel_root}${snapshot}"
|
||||||
|
snap_cfg="${rel_root}\$x"
|
||||||
|
|
||||||
|
if [ -f "\$snap_cfg" ]; then
|
||||||
|
snapshot_found=true
|
||||||
|
submenu "$date" "\$snap" "\$snap_cfg" {
|
||||||
|
set subvol="\$2"
|
||||||
|
export subvol
|
||||||
|
source "\$3"
|
||||||
|
}
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if grub2-script-check "${snapper_cfg}.new"; then
|
||||||
|
mv -f "${snapper_cfg}.new" "${snapper_cfg}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
grub_snapshot_cfg_refresh () {
|
||||||
|
|
||||||
|
: > "${grub_snapshot_cfg}.tmp"
|
||||||
|
for s_dir in /.snapshots/*; do
|
||||||
|
|
||||||
|
snapshot="${s_dir}/snapshot"
|
||||||
|
snapper_cfg="${s_dir}/${snapshot_submenu_name}"
|
||||||
|
|
||||||
|
if [ -f "${snapper_cfg}" ]; then
|
||||||
|
echo "source ${rel_root}${snapper_cfg}" >>"${grub_snapshot_cfg}.tmp"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
cat <<EOF >"${grub_snapshot_cfg}.new"
|
||||||
|
submenu "Bootable snapshots" {
|
||||||
|
`sort -V "${grub_snapshot_cfg}.tmp"`
|
||||||
|
if [ x\$snapshot_found != xtrue ]; then
|
||||||
|
submenu "Not Found" {true}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if grub2-script-check "${grub_snapshot_cfg}.new"; then
|
||||||
|
mv -f "${grub_snapshot_cfg}.new" "${grub_snapshot_cfg}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
snapshot_submenu_clean () {
|
||||||
|
|
||||||
|
for s_dir in /.snapshots/*; do
|
||||||
|
|
||||||
|
snapshot="${s_dir}/snapshot"
|
||||||
|
snapper_cfg="${s_dir}/${snapshot_submenu_name}"
|
||||||
|
|
||||||
|
if [ -f "$snapper_cfg" ]; then
|
||||||
|
rm -f "$snapper_cfg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
set_grub_setting () {
|
||||||
|
|
||||||
|
name=$1
|
||||||
|
val=$2
|
||||||
|
|
||||||
|
if grep -q "$name" "$grub_setting"; then
|
||||||
|
sed -i -e "s/.*\($name\)=.*/\1=$val/" "$grub_setting"
|
||||||
|
else
|
||||||
|
echo "$name=$val" >> "$grub_setting"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
update_grub_cfg () {
|
||||||
|
|
||||||
|
"$grub_mkconfig" -o "$grub_cfg"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check the arguments.
|
||||||
|
while test $# -gt 0
|
||||||
|
do
|
||||||
|
option=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
case "$option" in
|
||||||
|
-e | --enable)
|
||||||
|
opt_enable=true
|
||||||
|
;;
|
||||||
|
-d | --disable)
|
||||||
|
opt_enable=false
|
||||||
|
;;
|
||||||
|
-r | --refresh)
|
||||||
|
opt_refresh=true
|
||||||
|
;;
|
||||||
|
-c | --clean)
|
||||||
|
opt_clean=true
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "x${opt_enable}" = "xtrue" ]; then
|
||||||
|
|
||||||
|
set_grub_setting SUSE_DISABLE_BOOTING_SNAPSHOT false
|
||||||
|
set_grub_setting SUSE_ENABLE_CUSTOM_SNAPSHOT_SUBMENU true
|
||||||
|
update_grub_cfg
|
||||||
|
snapshot_submenu_refresh
|
||||||
|
grub_snapshot_cfg_refresh
|
||||||
|
|
||||||
|
elif [ "x${opt_enable}" = "xfalse" ]; then
|
||||||
|
|
||||||
|
snapshot_submenu_clean
|
||||||
|
set_grub_setting SUSE_DISABLE_BOOTING_SNAPSHOT true
|
||||||
|
set_grub_setting SUSE_ENABLE_CUSTOM_SNAPSHOT_SUBMENU false
|
||||||
|
update_grub_cfg
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ x${opt_refresh} = "xtrue" ]; then
|
||||||
|
|
||||||
|
snapshot_submenu_refresh
|
||||||
|
grub_snapshot_cfg_refresh
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ x${opt_clean} = "xtrue" ]; then
|
||||||
|
|
||||||
|
snapshot_submenu_clean
|
||||||
|
grub_snapshot_cfg_refresh
|
||||||
|
|
||||||
|
fi
|
@ -1,3 +1,13 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Wed Feb 5 04:33:55 UTC 2014 - mchang@suse.com
|
||||||
|
|
||||||
|
- add grub2-snapper-plugin.sh (fate#316232)
|
||||||
|
* grub2's snapper plugin for advanced btrfs snapshot menu management
|
||||||
|
* package as grub2-snapper-plugin.noarch
|
||||||
|
- refresh 0002-script-create-menus-for-btrfs-snapshot.patch
|
||||||
|
* when booting btrfs snapshots disabled, deleting snapshot master config
|
||||||
|
if it's not customized
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Fri Jan 31 14:42:26 UTC 2014 - dvaleev@suse.com
|
Fri Jan 31 14:42:26 UTC 2014 - dvaleev@suse.com
|
||||||
|
|
||||||
|
19
grub2.spec
19
grub2.spec
@ -113,6 +113,7 @@ Source6: grub2-once
|
|||||||
Source7: 20_memtest86+
|
Source7: 20_memtest86+
|
||||||
Source10: openSUSE-UEFI-CA-Certificate.crt
|
Source10: openSUSE-UEFI-CA-Certificate.crt
|
||||||
Source11: SLES-UEFI-CA-Certificate.crt
|
Source11: SLES-UEFI-CA-Certificate.crt
|
||||||
|
Source12: grub2-snapper-plugin.sh
|
||||||
Source1000: PATCH_POLICY
|
Source1000: PATCH_POLICY
|
||||||
Patch1: rename-grub-info-file-to-grub2.patch
|
Patch1: rename-grub-info-file-to-grub2.patch
|
||||||
Patch2: grub2-linux.patch
|
Patch2: grub2-linux.patch
|
||||||
@ -233,6 +234,17 @@ provides support for EFI systems.
|
|||||||
|
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
%package snapper-plugin
|
||||||
|
|
||||||
|
Summary: Grub2's snapper plugin
|
||||||
|
Group: System/Fhs
|
||||||
|
Requires: %{name} = %{version}-%{release}
|
||||||
|
Requires: libxml2-tools
|
||||||
|
BuildArch: noarch
|
||||||
|
|
||||||
|
%description snapper-plugin
|
||||||
|
Grub2's snapper plugin for advanced btrfs snapshot boot menu management
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
# We create (if we build for efi) two copies of the sources in the Builddir
|
# We create (if we build for efi) two copies of the sources in the Builddir
|
||||||
%setup -q -n grub-%{version} -a 5
|
%setup -q -n grub-%{version} -a 5
|
||||||
@ -458,6 +470,7 @@ rm $RPM_BUILD_ROOT%{_datadir}/%{name}/*.h
|
|||||||
# Defaults
|
# Defaults
|
||||||
install -m 644 -D %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/default/grub
|
install -m 644 -D %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/default/grub
|
||||||
install -m 755 -D %{SOURCE6} $RPM_BUILD_ROOT%{_sbindir}/grub2-once
|
install -m 755 -D %{SOURCE6} $RPM_BUILD_ROOT%{_sbindir}/grub2-once
|
||||||
|
install -m 755 -D %{SOURCE12} $RPM_BUILD_ROOT%{_libdir}/snapper/plugins/grub
|
||||||
|
|
||||||
%find_lang %{name}
|
%find_lang %{name}
|
||||||
%fdupes %buildroot%{_bindir}
|
%fdupes %buildroot%{_bindir}
|
||||||
@ -726,4 +739,10 @@ fi
|
|||||||
%endif
|
%endif
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
%files snapper-plugin
|
||||||
|
%defattr(-,root,root,-)
|
||||||
|
%dir %{_libdir}/snapper
|
||||||
|
%dir %{_libdir}/snapper/plugins
|
||||||
|
%{_libdir}/snapper/plugins/grub
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
Loading…
Reference in New Issue
Block a user