From d92c259b70e711c1f84e2851de0d6856a79f5601 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 19:51:26 -0500 Subject: [PATCH 01/24] initial commit --- Makefile | 2 + grub.d/10_linux_symlink | 282 ++++++++++++++++++++++++++++++++++++++++ scripts/snap-pac | 16 +++ 3 files changed, 300 insertions(+) create mode 100755 grub.d/10_linux_symlink diff --git a/Makefile b/Makefile index 8ebf875..9859ad2 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ PKGNAME = snap-pac PREFIX ?= /usr SHARE_DIR = $(DESTDIR)$(PREFIX)/share +ETC_DIR = $(DESTDIR)$(PREFIX)/etc .PHONY: install @@ -28,3 +29,4 @@ install: @install -Dm644 LICENSE -t $(SHARE_DIR)/licenses/$(PKGNAME) @install -Dm644 man8/* -t $(SHARE_DIR)/man/man8 @install -Dm644 README -t $(SHARE_DIR)/doc/$(PKGNAME) + @install -Dm644 grub.d/* -t $(ETC_DIR)/grub.d/ diff --git a/grub.d/10_linux_symlink b/grub.d/10_linux_symlink new file mode 100755 index 0000000..cbab3c2 --- /dev/null +++ b/grub.d/10_linux_symlink @@ -0,0 +1,282 @@ +#! /bin/sh +set -e + +# grub-mkconfig helper script. +# 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 . + +prefix="/usr" +exec_prefix="/usr" +datarootdir="/usr/share" + +. "$pkgdatadir/grub-mkconfig_lib" + +export TEXTDOMAIN=grub +export TEXTDOMAINDIR="${datarootdir}/locale" + +CLASS="--class gnu-linux --class gnu --class os" + +if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then + OS=Linux +else + OS="${GRUB_DISTRIBUTOR} Linux" + CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" +fi + +# loop-AES arranges things so that /dev/loop/X can be our root device, but +# the initrds that Linux uses don't like that. +case ${GRUB_DEVICE} in + /dev/loop/*|/dev/loop[0-9]) + GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` + ;; +esac + +# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter +# and mounting btrfs requires user space scanning, so force UUID in this case. +if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ + || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ + || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then + LINUX_ROOT_DEVICE=${GRUB_DEVICE} +else + LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} +fi + +case x"$GRUB_FS" in + xbtrfs) + rootsubvol="`make_system_path_relative_to_its_root /`" + rootsubvol="${rootsubvol#/}" + if [ "x${rootsubvol}" != x ]; then + GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" + fi;; + xzfs) + rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` + bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" + LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" + ;; +esac + +title_correction_code= + +linux_entry () +{ + os="$1" + version="$2" + type="$3" + args="$4" + + if [ -z "$boot_device_id" ]; then + boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" + fi + if [ x$type != xsimple ] ; then + case $type in + recovery) + title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;; + fallback) + title="$(gettext_printf "%s, with Linux %s (fallback initramfs)" "${os}" "${version}")" ;; + *) + title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;; + esac + if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then + replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" + quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" + title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" + grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")" + fi + echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" + else + echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" + fi + if [ x$type != xrecovery ] ; then + save_default_entry | grub_add_tab + fi + + # Use ELILO's generic "efifb" when it's known to be available. + # FIXME: We need an interface to select vesafb in case efifb can't be used. + if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then + echo " load_video" | sed "s/^/$submenu_indentation/" + if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ + && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then + echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/" + fi + else + if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then + echo " load_video" | sed "s/^/$submenu_indentation/" + fi + echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" + fi + + echo " insmod gzio" | sed "s/^/$submenu_indentation/" + + if [ x$dirname = x/ ]; then + if [ -z "${prepare_root_cache}" ]; then + prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)" + fi + printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/" + else + if [ -z "${prepare_boot_cache}" ]; then + prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)" + fi + printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" + fi + message="$(gettext_printf "Loading Linux %s ..." ${version})" + sed "s/^/$submenu_indentation/" << EOF + echo '$(echo "$message" | grub_quote)' + linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} rw ${args} +EOF + if test -n "${initrd}" -o -n "${initrd_extra}" ; then + # TRANSLATORS: ramdisk isn't identifier. Should be translated. + message="$(gettext_printf "Loading initial ramdisk ...")" + printf ' %s\n' "echo '$(echo "$message" | grub_quote)'" | sed "s/^/$submenu_indentation/" + printf ' %s ' 'initrd' | sed "s/^/$submenu_indentation/" + for i in ${initrd_extra} ${initrd}; do + printf ' %s/%s' "${rel_dirname}" "${i}" + done + printf '\n' + fi + sed "s/^/$submenu_indentation/" << EOF +} +EOF +} + +machine=`uname -m` +case "x$machine" in + xi?86 | xx86_64) + list= + for i in /boot/old/vmlinuz-*; do + if grub_file_is_not_garbage "$i" && [[ -h $i ]]; then list="$list $i" ; fi + done ;; + *) + list= + for i in /boot/old/vmlinuz-*; do + if grub_file_is_not_garbage "$i" && [[ -h $i ]]; then list="$list $i" ; fi + done ;; +esac + +case "$machine" in + i?86) GENKERNEL_ARCH="x86" ;; + mips|mips64) GENKERNEL_ARCH="mips" ;; + mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;; + arm*) GENKERNEL_ARCH="arm" ;; + *) GENKERNEL_ARCH="$machine" ;; +esac + +prepare_boot_cache= +prepare_root_cache= +boot_device_id= +title_correction_code= + +# Extra indentation to add to menu entries in a submenu. We're not in a submenu +# yet, so it's empty. In a submenu it will be equal to '\t' (one tab). +submenu_indentation="" + +gettext_printf "Generating entries for older versions...\n" >&2 +is_top_level=true +while [ "x$list" != "x" ] ; do + linux=`version_find_latest $list` + link=`readlink $linux` + basename=`basename $link` + dirname=`dirname $link` + rel_dirname=`make_system_path_relative_to_its_root $dirname` + version=`echo $basename | sed -e "s,vmlinuz-,,g"` + version_=`echo $(basename $linux) | sed -e "s,vmlinuz-,,g"` + gettext_printf "Found linux image: %s (%s)\n" "$link" "$version_" >&2 + alt_version=`echo $version | sed -e "s,\.old$,,g"` + linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" + + initrd= + for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ + "initrd-${version}" "initramfs-${version}.img" \ + "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ + "initrd-${alt_version}" "initramfs-${alt_version}.img" \ + "initramfs-genkernel-${version}" \ + "initramfs-genkernel-${alt_version}" \ + "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ + "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do + if test -e "${dirname}/${i}" ; then + initrd="$i" + break + fi + done + initrd_extra= + for i in intel-ucode.img; do + if test -e "${dirname}/${i}" ; then + initrd_extra="${initrd_extra} ${i}" + fi + done + + config= + for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do + if test -e "${i}" ; then + config="${i}" + break + fi + done + + initramfs= + if test -n "${config}" ; then + initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` + fi + + if test -n "${initrd}" -o -n "${initrd_extra}" ; then + gettext_printf "Found initrd image(s) in %s:%s\n" "${dirname}" "${initrd_extra} ${initrd}" >&2 + elif test -z "${initramfs}" ; then + # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's + # no initrd or builtin initramfs, it can't work here. + linux_root_device_thisversion=${GRUB_DEVICE} + fi + + if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then + linux_entry "${OS}" "${version}" simple \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + + submenu_indentation="$grub_tab" + + if [ -z "$boot_device_id" ]; then + boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" + fi + # TRANSLATORS: %s is replaced with an OS name + echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {" + is_top_level=false + fi + + linux_entry "${OS}" "${version_}" advanced \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + + if test -e "${dirname}/initramfs-linux-fallback.img" ; then + initrd="initramfs-linux-fallback.img" + + if test -n "${initrd}" ; then + gettext_printf "Found fallback initrd image(s) in %s:%s\n" "${dirname}" "${initrd_extra} ${initrd}" >&2 + fi + + linux_entry "${OS}" "${version_}" fallback \ + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" + fi + + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then + linux_entry "${OS}" "${version_}" recovery \ + "single ${GRUB_CMDLINE_LINUX}" + fi + + list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '` +done + +# If at least one kernel was found, then we need to +# add a closing '}' for the submenu command. +if [ x"$is_top_level" != xtrue ]; then + echo '}' +fi + +echo "$title_correction_code" diff --git a/scripts/snap-pac b/scripts/snap-pac index fdc7b43..2888a13 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -51,6 +51,7 @@ set_defaults() { PACMAN_PRE_DESCRIPTION="$pacman_cmd" PACMAN_POST_DESCRIPTION="$pacman_cmd" PACMAN_CLEANUP_ALGORITHM="number" + PACMAN_KEEP_OLD_KERNELS="no" } trap error_exit ERR @@ -71,7 +72,22 @@ for CONFIG in $SNAPPER_CONFIGS; do if [[ "$pre_or_post" == "pre" ]]; then x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" + if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" ]]; then + [[ -d /boot/old ]] && mkdir -p /boot/old + find /usr/lib/modules -xtype l -delete + find /boot/old -xtype l -delete + ln -s /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) + fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then + if [[ $CONFIG == "root" $PACMAN_KEEP_OLD_KERNELS == "yes" ]]; then + x=$(<$prefile) + ln -s /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ + kver=$(pacman -Q linux | awk '{print $2}')-ARCH + mv /boot/vmlinuz-linux /boot/vmlinuz-linux-$kver + mv /boot/initramfs-linux.img /boot/initramfs-linux-$kver.img + mv /boot/initramfs-linux-fallback.img /boot/initramfs-linux-$kver-fallback.img + grub-mkconfig -o /boot/grub/grub.cfg + fi x=$($snapper_cmd "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")") printf "==> %s: %s\n" "$CONFIG" "$x" rm -f "$prefile" From 4151fcb35cffdc2d81bb2486f06410ade932feb9 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:00:44 -0500 Subject: [PATCH 02/24] check if kernel is updated --- hooks/00_snapper-pre.hook | 1 + hooks/zy_snapper-post.hook | 1 + scripts/snap-pac | 11 +++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hooks/00_snapper-pre.hook b/hooks/00_snapper-pre.hook index c62fada..d0f90e3 100644 --- a/hooks/00_snapper-pre.hook +++ b/hooks/00_snapper-pre.hook @@ -28,4 +28,5 @@ Description = Performing snapper pre snapshots for the following configurations. Depends = snap-pac When = PreTransaction Exec = /usr/share/libalpm/scripts/snap-pac pre +NeedsTargets AbortOnFail diff --git a/hooks/zy_snapper-post.hook b/hooks/zy_snapper-post.hook index 74f08d2..f3ee29a 100644 --- a/hooks/zy_snapper-post.hook +++ b/hooks/zy_snapper-post.hook @@ -28,3 +28,4 @@ Description = Performing snapper post snapshots for the following configurations Depends = snap-pac When = PostTransaction Exec = /usr/share/libalpm/scripts/snap-pac post +NeedsTargets diff --git a/scripts/snap-pac b/scripts/snap-pac index 2888a13..6057270 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -18,6 +18,13 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +kernel_updated="no" +while read -r f; do + if [[ "$f" == "linux" ]]; then + kernel_updated="yes" + fi +done + declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper declare -r DESC_LIMIT=48 declare -r name="snap-pac" @@ -72,14 +79,14 @@ for CONFIG in $SNAPPER_CONFIGS; do if [[ "$pre_or_post" == "pre" ]]; then x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" - if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" ]]; then + if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" && $kernel_updated == "yes" ]]; then [[ -d /boot/old ]] && mkdir -p /boot/old find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete ln -s /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then - if [[ $CONFIG == "root" $PACMAN_KEEP_OLD_KERNELS == "yes" ]]; then + if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" && $kernel_updated == "yes" ]]; then x=$(<$prefile) ln -s /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ kver=$(pacman -Q linux | awk '{print $2}')-ARCH From d3d4a40992ef8c5426d1e140a737052875f45570 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:02:57 -0500 Subject: [PATCH 03/24] correct etc install directory --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9859ad2..d80f5f8 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ PKGNAME = snap-pac PREFIX ?= /usr SHARE_DIR = $(DESTDIR)$(PREFIX)/share -ETC_DIR = $(DESTDIR)$(PREFIX)/etc +ETC_DIR = $(DESTDIR)/etc .PHONY: install From bc059a3f04e1a52a45f63e99c2d28a1d2ad4ccbe Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:07:53 -0500 Subject: [PATCH 04/24] move everything to post snapshot --- scripts/snap-pac | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 6057270..22c5864 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -79,15 +79,14 @@ for CONFIG in $SNAPPER_CONFIGS; do if [[ "$pre_or_post" == "pre" ]]; then x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" + elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" && $kernel_updated == "yes" ]]; then [[ -d /boot/old ]] && mkdir -p /boot/old + printf "==> Linking old kernels and modules..." + x=$(<$prefile) find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete ln -s /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) - fi - elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then - if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" && $kernel_updated == "yes" ]]; then - x=$(<$prefile) ln -s /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ kver=$(pacman -Q linux | awk '{print $2}')-ARCH mv /boot/vmlinuz-linux /boot/vmlinuz-linux-$kver From d5d7fe5956fe11f8e30901da0a4dbb62dac925f8 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:11:53 -0500 Subject: [PATCH 05/24] debugging --- scripts/snap-pac | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 22c5864..144c8e6 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -24,6 +24,7 @@ while read -r f; do kernel_updated="yes" fi done +printf "Kernel updated: %s\n" $kernel_updated declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper declare -r DESC_LIMIT=48 @@ -79,15 +80,17 @@ for CONFIG in $SNAPPER_CONFIGS; do if [[ "$pre_or_post" == "pre" ]]; then x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" - elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" && $kernel_updated == "yes" ]]; then - [[ -d /boot/old ]] && mkdir -p /boot/old - printf "==> Linking old kernels and modules..." - x=$(<$prefile) + printf "==> Linking old kernels and modules...\n" find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete ln -s /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) ln -s /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ + fi + elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then + if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" && $kernel_updated == "yes" ]]; then + [[ -d /boot/old ]] && mkdir -p /boot/old + printf "==> Linking old kernels and modules...\n" kver=$(pacman -Q linux | awk '{print $2}')-ARCH mv /boot/vmlinuz-linux /boot/vmlinuz-linux-$kver mv /boot/initramfs-linux.img /boot/initramfs-linux-$kver.img From 9a8e7ac65fb31d33af5a69a555e2388ea77f53f4 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:14:24 -0500 Subject: [PATCH 06/24] debugging --- scripts/snap-pac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/snap-pac b/scripts/snap-pac index 144c8e6..63a24f8 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -24,6 +24,7 @@ while read -r f; do kernel_updated="yes" fi done +#FIXME printf "Kernel updated: %s\n" $kernel_updated declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper @@ -66,6 +67,8 @@ trap error_exit ERR trap kill_exit SIGTERM SIGINT source "$SNAPPER_CONFIG_FILE" +#FIXME +printf "PACMAN_KEEP_OLD_KERNELS: %s\n" $PACMAN_KEEP_OLD_KERNELS for CONFIG in $SNAPPER_CONFIGS; do From f67d8dab2cd9a613a8bc6093e8808a907f296a8e Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:17:21 -0500 Subject: [PATCH 07/24] debugging --- scripts/snap-pac | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 63a24f8..a23a012 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -24,8 +24,6 @@ while read -r f; do kernel_updated="yes" fi done -#FIXME -printf "Kernel updated: %s\n" $kernel_updated declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper declare -r DESC_LIMIT=48 @@ -68,7 +66,6 @@ trap kill_exit SIGTERM SIGINT source "$SNAPPER_CONFIG_FILE" #FIXME -printf "PACMAN_KEEP_OLD_KERNELS: %s\n" $PACMAN_KEEP_OLD_KERNELS for CONFIG in $SNAPPER_CONFIGS; do @@ -83,7 +80,11 @@ for CONFIG in $SNAPPER_CONFIGS; do if [[ "$pre_or_post" == "pre" ]]; then x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" - if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" && $kernel_updated == "yes" ]]; then +#FIXME + printf "Kernel updated: %s\n" $kernel_updated + printf "PACMAN_KEEP_OLD_KERNELS: %s\n" $PACMAN_KEEP_OLD_KERNELS + printf "CONFIG: %s\n" $CONFIG + if [[ "$CONFIG" == "root" -a "$PACMAN_KEEP_OLD_KERNELS" == "yes" -a "$kernel_updated" == "yes" ]]; then printf "==> Linking old kernels and modules...\n" find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete @@ -91,7 +92,11 @@ for CONFIG in $SNAPPER_CONFIGS; do ln -s /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then - if [[ $CONFIG == "root" && $PACMAN_KEEP_OLD_KERNELS == "yes" && $kernel_updated == "yes" ]]; then +#FIXME + printf "Kernel updated: %s\n" $kernel_updated + printf "PACMAN_KEEP_OLD_KERNELS: %s\n" $PACMAN_KEEP_OLD_KERNELS + printf "CONFIG: %s\n" $CONFIG + if [[ "$CONFIG" == "root" -a "$PACMAN_KEEP_OLD_KERNELS" == "yes" -a "$kernel_updated" == "yes" ]]; then [[ -d /boot/old ]] && mkdir -p /boot/old printf "==> Linking old kernels and modules...\n" kver=$(pacman -Q linux | awk '{print $2}')-ARCH From 67a89013cd040c11910fad4fb42f14e3bb261aac Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:18:26 -0500 Subject: [PATCH 08/24] and --- scripts/snap-pac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index a23a012..c428e30 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -84,7 +84,7 @@ for CONFIG in $SNAPPER_CONFIGS; do printf "Kernel updated: %s\n" $kernel_updated printf "PACMAN_KEEP_OLD_KERNELS: %s\n" $PACMAN_KEEP_OLD_KERNELS printf "CONFIG: %s\n" $CONFIG - if [[ "$CONFIG" == "root" -a "$PACMAN_KEEP_OLD_KERNELS" == "yes" -a "$kernel_updated" == "yes" ]]; then + if [[ "$CONFIG" == "root" && "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then printf "==> Linking old kernels and modules...\n" find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete @@ -96,7 +96,7 @@ for CONFIG in $SNAPPER_CONFIGS; do printf "Kernel updated: %s\n" $kernel_updated printf "PACMAN_KEEP_OLD_KERNELS: %s\n" $PACMAN_KEEP_OLD_KERNELS printf "CONFIG: %s\n" $CONFIG - if [[ "$CONFIG" == "root" -a "$PACMAN_KEEP_OLD_KERNELS" == "yes" -a "$kernel_updated" == "yes" ]]; then + if [[ "$CONFIG" == "root" && "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then [[ -d /boot/old ]] && mkdir -p /boot/old printf "==> Linking old kernels and modules...\n" kver=$(pacman -Q linux | awk '{print $2}')-ARCH From ce7516c681364bf4e475b0c72daf881bc7cad389 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:20:02 -0500 Subject: [PATCH 09/24] PACMAN_KEEP_OLD_KERNELS goes in root snapper config --- scripts/snap-pac | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index c428e30..9e8a709 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -80,11 +80,7 @@ for CONFIG in $SNAPPER_CONFIGS; do if [[ "$pre_or_post" == "pre" ]]; then x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" -#FIXME - printf "Kernel updated: %s\n" $kernel_updated - printf "PACMAN_KEEP_OLD_KERNELS: %s\n" $PACMAN_KEEP_OLD_KERNELS - printf "CONFIG: %s\n" $CONFIG - if [[ "$CONFIG" == "root" && "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then + if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then printf "==> Linking old kernels and modules...\n" find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete @@ -92,11 +88,7 @@ for CONFIG in $SNAPPER_CONFIGS; do ln -s /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then -#FIXME - printf "Kernel updated: %s\n" $kernel_updated - printf "PACMAN_KEEP_OLD_KERNELS: %s\n" $PACMAN_KEEP_OLD_KERNELS - printf "CONFIG: %s\n" $CONFIG - if [[ "$CONFIG" == "root" && "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then + if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then [[ -d /boot/old ]] && mkdir -p /boot/old printf "==> Linking old kernels and modules...\n" kver=$(pacman -Q linux | awk '{print $2}')-ARCH From a238bd40f5888470d124927421343b5641a9c977 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:26:36 -0500 Subject: [PATCH 10/24] mark kernel snaps as important --- scripts/snap-pac | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 9e8a709..2437e20 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -65,7 +65,6 @@ trap error_exit ERR trap kill_exit SIGTERM SIGINT source "$SNAPPER_CONFIG_FILE" -#FIXME for CONFIG in $SNAPPER_CONFIGS; do @@ -78,7 +77,12 @@ for CONFIG in $SNAPPER_CONFIGS; do snapper_cmd="snapper --config $CONFIG create --type $pre_or_post --cleanup-algorithm $PACMAN_CLEANUP_ALGORITHM --print-number --description" if [[ "$pre_or_post" == "pre" ]]; then - x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") + + if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then + x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)" --userdata important=yes) + else + x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") + fi printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then printf "==> Linking old kernels and modules...\n" From 9f8816b103371874ceeb8814de05e14b0ddb6668 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:28:48 -0500 Subject: [PATCH 11/24] bug with creating directory --- scripts/snap-pac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 2437e20..53e40db 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -86,6 +86,7 @@ for CONFIG in $SNAPPER_CONFIGS; do printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then printf "==> Linking old kernels and modules...\n" + [[ -d /boot/old ]] || mkdir -p /boot/old find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete ln -s /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) @@ -93,7 +94,6 @@ for CONFIG in $SNAPPER_CONFIGS; do fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then - [[ -d /boot/old ]] && mkdir -p /boot/old printf "==> Linking old kernels and modules...\n" kver=$(pacman -Q linux | awk '{print $2}')-ARCH mv /boot/vmlinuz-linux /boot/vmlinuz-linux-$kver From 3bbd2a3152837e452168bf2ea954f2c1f3f3e698 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:29:27 -0500 Subject: [PATCH 12/24] debugging --- scripts/snap-pac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 53e40db..5f94b65 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -89,8 +89,8 @@ for CONFIG in $SNAPPER_CONFIGS; do [[ -d /boot/old ]] || mkdir -p /boot/old find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete - ln -s /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) - ln -s /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ + ln -sv /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) + ln -sv /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then From edc4e893688d88a27db1e4cbe267969a3e340add Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:32:22 -0500 Subject: [PATCH 13/24] debugging --- scripts/snap-pac | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 5f94b65..1ad889e 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -86,7 +86,7 @@ for CONFIG in $SNAPPER_CONFIGS; do printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then printf "==> Linking old kernels and modules...\n" - [[ -d /boot/old ]] || mkdir -p /boot/old + mkdir -p /boot/old find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete ln -sv /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) @@ -94,11 +94,11 @@ for CONFIG in $SNAPPER_CONFIGS; do fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then - printf "==> Linking old kernels and modules...\n" - kver=$(pacman -Q linux | awk '{print $2}')-ARCH - mv /boot/vmlinuz-linux /boot/vmlinuz-linux-$kver - mv /boot/initramfs-linux.img /boot/initramfs-linux-$kver.img - mv /boot/initramfs-linux-fallback.img /boot/initramfs-linux-$kver-fallback.img + printf "==> Regenerating GRUB configuration...\n" +# kver=$(pacman -Q linux | awk '{print $2}')-ARCH +# mv /boot/vmlinuz-linux /boot/vmlinuz-linux-$kver +# mv /boot/initramfs-linux.img /boot/initramfs-linux-$kver.img +# mv /boot/initramfs-linux-fallback.img /boot/initramfs-linux-$kver-fallback.img grub-mkconfig -o /boot/grub/grub.cfg fi x=$($snapper_cmd "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")") From 2f7c44ba21c1bdd9605dd0151c0421ae0fa1b6b6 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:34:53 -0500 Subject: [PATCH 14/24] can't link modules until after --- scripts/snap-pac | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 1ad889e..e1c6cd4 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -89,12 +89,13 @@ for CONFIG in $SNAPPER_CONFIGS; do mkdir -p /boot/old find /usr/lib/modules -xtype l -delete find /boot/old -xtype l -delete - ln -sv /.snapshots/$x/snapshot/boot/vmlinuz-linux/boot/old/vmlinuz-linux-$(uname -r) - ln -sv /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ + ln -sv /.snapshots/$x/snapshot/boot/vmlinuz-linux /boot/old/vmlinuz-linux-$(uname -r) fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then - printf "==> Regenerating GRUB configuration...\n" + printf "==> Linking old kernels and modules...\n" + x=$(<$prefile) + ln -sv /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ # kver=$(pacman -Q linux | awk '{print $2}')-ARCH # mv /boot/vmlinuz-linux /boot/vmlinuz-linux-$kver # mv /boot/initramfs-linux.img /boot/initramfs-linux-$kver.img From 7b39fb5d1be35641124689201c063d7b0e42ffc6 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Tue, 18 Apr 2017 20:43:54 -0500 Subject: [PATCH 15/24] grub file +x --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d80f5f8..18db05a 100644 --- a/Makefile +++ b/Makefile @@ -29,4 +29,4 @@ install: @install -Dm644 LICENSE -t $(SHARE_DIR)/licenses/$(PKGNAME) @install -Dm644 man8/* -t $(SHARE_DIR)/man/man8 @install -Dm644 README -t $(SHARE_DIR)/doc/$(PKGNAME) - @install -Dm644 grub.d/* -t $(ETC_DIR)/grub.d/ + @install -Dm755 grub.d/* -t $(ETC_DIR)/grub.d/ From 76c4151814b1e01f1f7565a015e9b0eaf361551a Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 08:03:55 -0500 Subject: [PATCH 16/24] initial commit --- Makefile | 1 - grub.d/10_linux_symlink | 282 ---------------------------------------- scripts/snap-pac | 21 +-- 3 files changed, 4 insertions(+), 300 deletions(-) delete mode 100755 grub.d/10_linux_symlink diff --git a/Makefile b/Makefile index 18db05a..94891f4 100644 --- a/Makefile +++ b/Makefile @@ -29,4 +29,3 @@ install: @install -Dm644 LICENSE -t $(SHARE_DIR)/licenses/$(PKGNAME) @install -Dm644 man8/* -t $(SHARE_DIR)/man/man8 @install -Dm644 README -t $(SHARE_DIR)/doc/$(PKGNAME) - @install -Dm755 grub.d/* -t $(ETC_DIR)/grub.d/ diff --git a/grub.d/10_linux_symlink b/grub.d/10_linux_symlink deleted file mode 100755 index cbab3c2..0000000 --- a/grub.d/10_linux_symlink +++ /dev/null @@ -1,282 +0,0 @@ -#! /bin/sh -set -e - -# grub-mkconfig helper script. -# 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 . - -prefix="/usr" -exec_prefix="/usr" -datarootdir="/usr/share" - -. "$pkgdatadir/grub-mkconfig_lib" - -export TEXTDOMAIN=grub -export TEXTDOMAINDIR="${datarootdir}/locale" - -CLASS="--class gnu-linux --class gnu --class os" - -if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then - OS=Linux -else - OS="${GRUB_DISTRIBUTOR} Linux" - CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" -fi - -# loop-AES arranges things so that /dev/loop/X can be our root device, but -# the initrds that Linux uses don't like that. -case ${GRUB_DEVICE} in - /dev/loop/*|/dev/loop[0-9]) - GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` - ;; -esac - -# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter -# and mounting btrfs requires user space scanning, so force UUID in this case. -if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ - || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ - || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then - LINUX_ROOT_DEVICE=${GRUB_DEVICE} -else - LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} -fi - -case x"$GRUB_FS" in - xbtrfs) - rootsubvol="`make_system_path_relative_to_its_root /`" - rootsubvol="${rootsubvol#/}" - if [ "x${rootsubvol}" != x ]; then - GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" - fi;; - xzfs) - rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` - bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" - LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" - ;; -esac - -title_correction_code= - -linux_entry () -{ - os="$1" - version="$2" - type="$3" - args="$4" - - if [ -z "$boot_device_id" ]; then - boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" - fi - if [ x$type != xsimple ] ; then - case $type in - recovery) - title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;; - fallback) - title="$(gettext_printf "%s, with Linux %s (fallback initramfs)" "${os}" "${version}")" ;; - *) - title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;; - esac - if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then - replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" - quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" - title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" - grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")" - fi - echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" - else - echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" - fi - if [ x$type != xrecovery ] ; then - save_default_entry | grub_add_tab - fi - - # Use ELILO's generic "efifb" when it's known to be available. - # FIXME: We need an interface to select vesafb in case efifb can't be used. - if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then - echo " load_video" | sed "s/^/$submenu_indentation/" - if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ - && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then - echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/" - fi - else - if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then - echo " load_video" | sed "s/^/$submenu_indentation/" - fi - echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" - fi - - echo " insmod gzio" | sed "s/^/$submenu_indentation/" - - if [ x$dirname = x/ ]; then - if [ -z "${prepare_root_cache}" ]; then - prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)" - fi - printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/" - else - if [ -z "${prepare_boot_cache}" ]; then - prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)" - fi - printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" - fi - message="$(gettext_printf "Loading Linux %s ..." ${version})" - sed "s/^/$submenu_indentation/" << EOF - echo '$(echo "$message" | grub_quote)' - linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} rw ${args} -EOF - if test -n "${initrd}" -o -n "${initrd_extra}" ; then - # TRANSLATORS: ramdisk isn't identifier. Should be translated. - message="$(gettext_printf "Loading initial ramdisk ...")" - printf ' %s\n' "echo '$(echo "$message" | grub_quote)'" | sed "s/^/$submenu_indentation/" - printf ' %s ' 'initrd' | sed "s/^/$submenu_indentation/" - for i in ${initrd_extra} ${initrd}; do - printf ' %s/%s' "${rel_dirname}" "${i}" - done - printf '\n' - fi - sed "s/^/$submenu_indentation/" << EOF -} -EOF -} - -machine=`uname -m` -case "x$machine" in - xi?86 | xx86_64) - list= - for i in /boot/old/vmlinuz-*; do - if grub_file_is_not_garbage "$i" && [[ -h $i ]]; then list="$list $i" ; fi - done ;; - *) - list= - for i in /boot/old/vmlinuz-*; do - if grub_file_is_not_garbage "$i" && [[ -h $i ]]; then list="$list $i" ; fi - done ;; -esac - -case "$machine" in - i?86) GENKERNEL_ARCH="x86" ;; - mips|mips64) GENKERNEL_ARCH="mips" ;; - mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;; - arm*) GENKERNEL_ARCH="arm" ;; - *) GENKERNEL_ARCH="$machine" ;; -esac - -prepare_boot_cache= -prepare_root_cache= -boot_device_id= -title_correction_code= - -# Extra indentation to add to menu entries in a submenu. We're not in a submenu -# yet, so it's empty. In a submenu it will be equal to '\t' (one tab). -submenu_indentation="" - -gettext_printf "Generating entries for older versions...\n" >&2 -is_top_level=true -while [ "x$list" != "x" ] ; do - linux=`version_find_latest $list` - link=`readlink $linux` - basename=`basename $link` - dirname=`dirname $link` - rel_dirname=`make_system_path_relative_to_its_root $dirname` - version=`echo $basename | sed -e "s,vmlinuz-,,g"` - version_=`echo $(basename $linux) | sed -e "s,vmlinuz-,,g"` - gettext_printf "Found linux image: %s (%s)\n" "$link" "$version_" >&2 - alt_version=`echo $version | sed -e "s,\.old$,,g"` - linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" - - initrd= - for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ - "initrd-${version}" "initramfs-${version}.img" \ - "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ - "initrd-${alt_version}" "initramfs-${alt_version}.img" \ - "initramfs-genkernel-${version}" \ - "initramfs-genkernel-${alt_version}" \ - "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ - "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do - if test -e "${dirname}/${i}" ; then - initrd="$i" - break - fi - done - initrd_extra= - for i in intel-ucode.img; do - if test -e "${dirname}/${i}" ; then - initrd_extra="${initrd_extra} ${i}" - fi - done - - config= - for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do - if test -e "${i}" ; then - config="${i}" - break - fi - done - - initramfs= - if test -n "${config}" ; then - initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` - fi - - if test -n "${initrd}" -o -n "${initrd_extra}" ; then - gettext_printf "Found initrd image(s) in %s:%s\n" "${dirname}" "${initrd_extra} ${initrd}" >&2 - elif test -z "${initramfs}" ; then - # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's - # no initrd or builtin initramfs, it can't work here. - linux_root_device_thisversion=${GRUB_DEVICE} - fi - - if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then - linux_entry "${OS}" "${version}" simple \ - "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - - submenu_indentation="$grub_tab" - - if [ -z "$boot_device_id" ]; then - boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" - fi - # TRANSLATORS: %s is replaced with an OS name - echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {" - is_top_level=false - fi - - linux_entry "${OS}" "${version_}" advanced \ - "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - - if test -e "${dirname}/initramfs-linux-fallback.img" ; then - initrd="initramfs-linux-fallback.img" - - if test -n "${initrd}" ; then - gettext_printf "Found fallback initrd image(s) in %s:%s\n" "${dirname}" "${initrd_extra} ${initrd}" >&2 - fi - - linux_entry "${OS}" "${version_}" fallback \ - "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - fi - - if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then - linux_entry "${OS}" "${version_}" recovery \ - "single ${GRUB_CMDLINE_LINUX}" - fi - - list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '` -done - -# If at least one kernel was found, then we need to -# add a closing '}' for the submenu command. -if [ x"$is_top_level" != xtrue ]; then - echo '}' -fi - -echo "$title_correction_code" diff --git a/scripts/snap-pac b/scripts/snap-pac index e1c6cd4..20755a2 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -58,7 +58,7 @@ set_defaults() { PACMAN_PRE_DESCRIPTION="$pacman_cmd" PACMAN_POST_DESCRIPTION="$pacman_cmd" PACMAN_CLEANUP_ALGORITHM="number" - PACMAN_KEEP_OLD_KERNELS="no" + PACMAN_LINK_MOCULES="no" } trap error_exit ERR @@ -78,29 +78,16 @@ for CONFIG in $SNAPPER_CONFIGS; do if [[ "$pre_or_post" == "pre" ]]; then - if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then + if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)" --userdata important=yes) else x=$($snapper_cmd "$(truncate_description $PACMAN_PRE_DESCRIPTION)") fi printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" - if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then - printf "==> Linking old kernels and modules...\n" - mkdir -p /boot/old - find /usr/lib/modules -xtype l -delete - find /boot/old -xtype l -delete - ln -sv /.snapshots/$x/snapshot/boot/vmlinuz-linux /boot/old/vmlinuz-linux-$(uname -r) - fi elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then - if [[ "$PACMAN_KEEP_OLD_KERNELS" == "yes" && "$kernel_updated" == "yes" ]]; then + if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then printf "==> Linking old kernels and modules...\n" - x=$(<$prefile) - ln -sv /.snapshots/$x/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ -# kver=$(pacman -Q linux | awk '{print $2}')-ARCH -# mv /boot/vmlinuz-linux /boot/vmlinuz-linux-$kver -# mv /boot/initramfs-linux.img /boot/initramfs-linux-$kver.img -# mv /boot/initramfs-linux-fallback.img /boot/initramfs-linux-$kver-fallback.img - grub-mkconfig -o /boot/grub/grub.cfg + ln -sv /.snapshots/$(<$prefile)/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ fi x=$($snapper_cmd "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")") printf "==> %s: %s\n" "$CONFIG" "$x" From 6ad1c1f5718fca6f749ee860cf84706b5c7f4e3d Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 08:36:06 -0500 Subject: [PATCH 17/24] rearrange how package update is detected --- scripts/snap-pac | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 20755a2..fcc571e 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -18,19 +18,11 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -kernel_updated="no" -while read -r f; do - if [[ "$f" == "linux" ]]; then - kernel_updated="yes" - fi -done - declare -r SNAPPER_CONFIG_FILE=/etc/conf.d/snapper declare -r DESC_LIMIT=48 declare -r name="snap-pac" declare PACMAN_ABORT_ON_FAIL="no" declare -r pacman_cmd="$(ps -q $(ps -p "$$" -o ppid=) -o args=)" -declare -i x=0 declare -r pre_or_post=$1 out() { printf "$1 $2\n" "${@:3}"; } @@ -61,9 +53,25 @@ set_defaults() { PACMAN_LINK_MOCULES="no" } + +package_updated() { + check="$1" + for x in ${packages[@]}; do + echo $x + if [[ "$x" == "$check" ]]; then + echo "yes" + return + fi + done + echo "no" +} + trap error_exit ERR trap kill_exit SIGTERM SIGINT +mapfile -t packages +kernel_updated=$(package_updated "linux") + source "$SNAPPER_CONFIG_FILE" for CONFIG in $SNAPPER_CONFIGS; do @@ -86,7 +94,7 @@ for CONFIG in $SNAPPER_CONFIGS; do printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then - printf "==> Linking old kernels and modules...\n" + printf "==> Linking old kernel modules...\n" ln -sv /.snapshots/$(<$prefile)/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ fi x=$($snapper_cmd "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")") From 9ebba032da0abe4e74fc582aa71e82f2b3749cb6 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 08:45:25 -0500 Subject: [PATCH 18/24] delete old broken links --- scripts/snap-pac | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/snap-pac b/scripts/snap-pac index fcc571e..c9c9f35 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -95,6 +95,7 @@ for CONFIG in $SNAPPER_CONFIGS; do elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then printf "==> Linking old kernel modules...\n" + find /usr/lib/modules -xtype l -delete ln -sv /.snapshots/$(<$prefile)/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ fi x=$($snapper_cmd "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")") From 311e2d9a75055d9457991ce82bcd7a00aeda8a95 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 08:45:42 -0500 Subject: [PATCH 19/24] remove unneeded ETC_DIR --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 94891f4..8ebf875 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,6 @@ PKGNAME = snap-pac PREFIX ?= /usr SHARE_DIR = $(DESTDIR)$(PREFIX)/share -ETC_DIR = $(DESTDIR)/etc .PHONY: install From 3a904dac0ed59a6abd880a4fe2eb9587fa743ad3 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 09:22:30 -0500 Subject: [PATCH 20/24] fix typos --- scripts/snap-pac | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index c9c9f35..6eba121 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -50,14 +50,13 @@ set_defaults() { PACMAN_PRE_DESCRIPTION="$pacman_cmd" PACMAN_POST_DESCRIPTION="$pacman_cmd" PACMAN_CLEANUP_ALGORITHM="number" - PACMAN_LINK_MOCULES="no" + PACMAN_LINK_MODULES="no" } package_updated() { check="$1" for x in ${packages[@]}; do - echo $x if [[ "$x" == "$check" ]]; then echo "yes" return From 1135776e9382ef68d59aa6f35e8b835084dac54e Mon Sep 17 00:00:00 2001 From: James Barnett Date: Thu, 20 Apr 2017 09:28:15 -0500 Subject: [PATCH 21/24] more verbose --- scripts/snap-pac | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 6eba121..86804cc 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -93,8 +93,9 @@ for CONFIG in $SNAPPER_CONFIGS; do printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then - printf "==> Linking old kernel modules...\n" - find /usr/lib/modules -xtype l -delete + printf "==> Deleting broken kernel modules symlinks...\n" + find /usr/lib/modules -xtype l -delete -print + printf "==> Symlinking old kernel modules...\n" ln -sv /.snapshots/$(<$prefile)/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ fi x=$($snapper_cmd "$(truncate_description $PACMAN_POST_DESCRIPTION)" --pre-number "$(< "$prefile")") From 4f5ce6554a297e3ebbf0fdf80e51208ea1564155 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Wed, 17 Jan 2018 20:58:33 -0500 Subject: [PATCH 22/24] add option to link kernel modules --- scripts/snap-pac | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/snap-pac b/scripts/snap-pac index 934a2c6..cd837ca 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -30,6 +30,7 @@ declare -r pre_or_post=$1 declare -r DESC_LIMIT=${DESC_LIMIT:-48} declare -r ABORT_ON_FAIL=${ABORT_ON_FAIL:-"no"} +declare -r LINK_MODULES=${LINK_MODULES:-"no"} out() { printf "$1 $2\n" "${@:3}"; } error() { out "==> \033[00;31merror:\033[00m" "$@"; } >&2 @@ -91,7 +92,7 @@ for CONFIG in $SNAPPER_CONFIGS; do x=$($snapper_cmd "$(truncate_description $PRE_DESCRIPTION)") printf "==> %s: $(echo $x | tee "$prefile")\n" "$CONFIG" elif [[ -f $prefile && "$pre_or_post" == "post" ]]; then - if [[ "$PACMAN_LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then + if [[ "$LINK_MODULES" == "yes" && "$kernel_updated" == "yes" ]]; then printf "==> Symlinking old kernel modules...\n" find /usr/lib/modules -xtype l -delete -print ln -sv /.snapshots/$(<$prefile)/snapshot/usr/lib/modules/$(uname -r) /usr/lib/modules/ From 1d02860306b7194f81f70b4c0c41f213ae8fe3a0 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Wed, 17 Jan 2018 21:05:35 -0500 Subject: [PATCH 23/24] update manpage --- man8/snap-pac.8 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/man8/snap-pac.8 b/man8/snap-pac.8 index 9eb2f85..b3f6763 100644 --- a/man8/snap-pac.8 +++ b/man8/snap-pac.8 @@ -53,6 +53,17 @@ Number of characters to limit length of descriptions used for snapper. Default is "48". .RE +\fBLINK_MODULES=\fR\fB\fIyes\fR\fR\fB or \fR\fB\fIno\fR\fR +.RS 4 +When set to "yes" this, if the \fIlinux\fR package is updated, then a +symlink will be created in the kernel modules directory for the +currently running kernel to same directory in the pre snapshot. This +is so that the kernel modules will still be available for use before a +reboot is required. + +Default is "no". +.RE + The following are possible settings used on each specific snapper configuration you have. To use them, first create the folder \fI/etc/snap-pac\fR if it does not already exist. Then create a file From 7bff82da28cd8dc99fde29dc3d20f9f27d8819d8 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Fri, 19 Jan 2018 11:02:12 -0500 Subject: [PATCH 24/24] restored package_updated --- scripts/snap-pac | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/snap-pac b/scripts/snap-pac index cd837ca..779fd8d 100755 --- a/scripts/snap-pac +++ b/scripts/snap-pac @@ -60,6 +60,18 @@ truncate_description() { fi } +package_updated() { + check="$1" + for x in ${packages[@]}; do + echo $x + if [[ "$x" == "$check" ]]; then + echo "yes" + return + fi + done + echo "no" +} + trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR trap trapkill SIGTERM SIGINT