Compare commits

...

1 Commits
3.0.1 ... 3.1

Author SHA1 Message Date
Antynea
b8325cf134 Fix: some functions doesn't work as expected (#48)
* Fix: Title format in grub-menu

function: 
- title_format , doesn't work as expected

replace print message with default parameter (p/d/n)

* Update header

- Add Github link
- Clear up some explanations

* Fix: path to grub-mkconfig_lib

. "$pkgdatadir/grub-mkconfig_lib" doesn't work on some distribution
Replaced by . "$datarootdir/grub/grub-mkconfig_lib"

* Fix: matches kernel & initramfs

matches kernel & initramfs doesn't work as expected
2018-04-19 15:45:59 +02:00

View File

@@ -4,18 +4,19 @@
######################################################################################################################################################################### #########################################################################################################################################################################
# Written by: Antynea # # Written by: Antynea #
# BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt # # BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt #
# # # Github: https://github.com/Antynea/grub-btrfs #
# #
# Purpose: Include btrfs snapshots at boot options (grub-menu). # # Purpose: Include btrfs snapshots at boot options (grub-menu). #
# # # #
# What this script does: # # What this script does: #
# Simple rollback using snapshots you made previously. # # Simple rollback using snapshots you made previously. #
# - Automatically List snapshots existing on root partition (btrfs). # # - Automatically List snapshots existing on root partition (btrfs). #
# - Automatically Detect if "/boot" is in separate partition. # # - Automatically Detect if "/boot" is in separate partition. #
# - Automatically Detect kernel, initramfs and intel microcode in "/boot" directory on snapshots. (For custon name, see below.) # # - Automatically Detect kernel, initramfs and intel microcode in "/boot" directory on snapshots. #
# - Automatically Create corresponding "menuentry" in grub.cfg , which ensures a very easy rollback. # # - Automatically Create corresponding "menuentry" in grub.cfg , which ensures a very easy rollback. #
# - Automatically detect snapper and use snapper's snapshot description if available. # # - Automatically detect snapper and use snapper's snapshot description if available. #
# # # #
# How to use it: # # How to customize it: #
# - Add this lines to /etc/default/grub: # # - Add this lines to /etc/default/grub: #
# # # #
# * GRUB_BTRFS_SUBMENUNAME="Arch Linux snapshots" # # * GRUB_BTRFS_SUBMENUNAME="Arch Linux snapshots" #
@@ -36,12 +37,12 @@
# * GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true" # # * GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true" #
# (Show Total of snapshots found during run "grub-mkconfig") # # (Show Total of snapshots found during run "grub-mkconfig") #
# * GRUB_BTRFS_NKERNEL=("vmlinuz-linux") # # * GRUB_BTRFS_NKERNEL=("vmlinuz-linux") #
# (Use only if you have custom kernel name or auto-detect failed.) # # (Use only if you have custom kernel name.) #
# * GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") # # * GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") #
# (Use only if you have custom initramfs name or auto-detect failed.) # # (Use only if you have custom initramfs name.) #
# * GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img") # # * GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img") #
# (Use only if you have custom intel-ucode or auto-detect failed.) # # (Use only if you have custom intel-ucode.) #
# * GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker" "nosnapshot") # # * GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker") #
# (Ignore specific path during run "grub-mkconfig") # # (Ignore specific path during run "grub-mkconfig") #
# * GRUB_BTRFS_SNAPPER_CONFIG="root" # # * GRUB_BTRFS_SNAPPER_CONFIG="root" #
# (Snapper's config name to use) # # (Snapper's config name to use) #
@@ -73,8 +74,7 @@ datarootdir="/usr/share"
sysconfdir="/etc" sysconfdir="/etc"
. "${sysconfdir}/default/grub" . "${sysconfdir}/default/grub"
. "$pkgdatadir/grub-mkconfig_lib" . "$datarootdir/grub/grub-mkconfig_lib"
# . "$datarootdir/grub/grub-mkconfig_lib" # Uncomment if you run "bash -x"
###################################### ######################################
### Variables in /etc/default/grub ### ### Variables in /etc/default/grub ###
@@ -182,16 +182,17 @@ make_menu_entries()
[[ ! -f "${boot_dir}"/"${k}" ]] && continue; [[ ! -f "${boot_dir}"/"${k}" ]] && continue;
kversion=${k#*"-"} kversion=${k#*"-"}
for i in "${name_initramfs[@]}"; do for i in "${name_initramfs[@]}"; do
prefix_i=${i[@]%%"-"*} prefix_i=${i%%"-"*}
suffix_i=${i[@]##*"-"} suffix_i=${i#*"-"}
if [ -f "${boot_dir}"/"${prefix_i}-${kversion}-${suffix_i}" ]; then i="${i}"; alt_suffix_i=${i##*"-"}
elif [ -f "${boot_dir}"/"${prefix_i}-${kversion}" ]; then i="${i}"; if [ "${kversion}" = "${suffix_i}" ]; then i="${i}";
elif [ -f "${boot_dir}"/"${prefix_i}-${kversion}.img" ]; then i="${i}"; elif [ "${kversion}.img" = "${suffix_i}" ]; then i="${i}";
elif [ -f "${boot_dir}"/"${prefix_i}-${kversion}.gz" ]; then i="${i}"; elif [ "${kversion}-fallback.img" = "${suffix_i}" ]; then i="${i}";
elif [ "${kversion}.gz" = "${suffix_i}" ]; then i="${i}";
else continue ; else continue ;
fi fi
for u in "${name_microcode[@]}"; do for u in "${name_microcode[@]}"; do
if [[ -f "${boot_dir}"/"${u}" && "${i}" != initramfs-linux-fallback.img ]] ; then if [[ -f "${boot_dir}"/"${u}" && "${i}" != "${prefix_i}-${kversion}-${alt_suffix_i}" ]] ; then
entry " entry "
menuentry '"${k}" & "${i}" & "${u}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid'{" menuentry '"${k}" & "${i}" & "${u}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid'{"
else else
@@ -212,7 +213,7 @@ make_menu_entries()
echo 'Loading Snapshot: "${snap_date_time}" "${snap_dir_name}"' echo 'Loading Snapshot: "${snap_date_time}" "${snap_dir_name}"'
echo 'Loading Kernel: "${k}" ...' echo 'Loading Kernel: "${k}" ...'
linux \"${boot_dir_root_grub}/"${k}"\" root=UUID=${root_uuid} rw rootflags=subvol=\""${snap_dir_name}"\" ${kernel_parameters}" linux \"${boot_dir_root_grub}/"${k}"\" root=UUID=${root_uuid} rw rootflags=subvol=\""${snap_dir_name}"\" ${kernel_parameters}"
if [[ -f "${boot_dir}"/"${u}" && "${i}" != initramfs-linux-fallback.img ]] ; then if [[ -f "${boot_dir}"/"${u}" && "${i}" != "${prefix_i}-${kversion}-${alt_suffix_i}" ]] ; then
entry "\ entry "\
echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...' echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...'
initrd \"${boot_dir_root_grub}/"${u}"\" \"${boot_dir_root_grub}/"${i}"\"" initrd \"${boot_dir_root_grub}/"${u}"\" \"${boot_dir_root_grub}/"${i}"\""
@@ -394,16 +395,15 @@ path_snapshot()
title_format() title_format()
{ {
case "${title_format}" in case "${title_format}" in
p/d/n) title_menu="${prefixentry} ${snap_date_time} ${name_snapshot}";;
p/n/d) title_menu="${prefixentry} ${name_snapshot} ${snap_date_time}";; p/n/d) title_menu="${prefixentry} ${name_snapshot} ${snap_date_time}";;
p/d) title_menu="${prefixentry} ${snap_date_time}";; p/d) title_menu="${prefixentry} ${snap_date_time}";;
p/n) title_menu="${prefixentry} ${name_snapshot}";; p/n) title_menu="${prefixentry} ${name_snapshot}";;
d/n) title_menu="${snap_date_time} ${name_snapshot}";; d/n) title_menu="${snap_date_time} ${name_snapshot}";;
n/d) title_menu="${name_snapshot} ${snap_date_time}";; n/d) title_menu="${name_snapshot} ${snap_date_time}";;
p) title_menu="${prefixentry}";; p) title_menu="${prefixentry}";;
d) title_menu="${snap_date_time}";; d) title_menu="${snap_date_time}";;
n) title_menu="${name_snapshot}";; n) title_menu="${name_snapshot}";;
*) printf $"# Warning: GRUB_BTRFS_TITLE_FORMAT=${title_format}, syntax error \n" >&2 *) title_menu="${prefixentry} ${snap_date_time} ${name_snapshot}"
esac esac
} }