OSDN Git Service

66boot-storage-autoconf: add swap partition and swapfile detection.
authormobinmob <mobinmob@disroot.org>
Mon, 3 Jan 2022 17:37:06 +0000 (19:37 +0200)
committermobinmob <mobinmob@disroot.org>
Mon, 3 Jan 2022 17:37:06 +0000 (19:37 +0200)
Bug report/enhancement proposal by Gabriele Del Roscio
(https://gitlab.com/skikky94).

srcpkgs/boot-66serv/files/66boot-storage-autoconf

index 38f5aa0..ec4ff5e 100755 (executable)
@@ -28,6 +28,11 @@ detect_fs() {
         export "${1}"_detected="$(blkid --match-token=TYPE="${1}" | wc -l )"
 }
 
+detect_swapfile() {
+        # Finds swap references in /etc/fstab.
+        export swapfile_detected="$(awk '!/^(#)/' /etc/fstab | awk '$3=="swap" ' | wc -l )"
+}
+
 detect_util() {
         # Uses 66-which to determine if a utility exists.
         # Output is $fs_util_exitst=0 (or 1)
@@ -111,12 +116,19 @@ dmraid_detected=$((ddf_raid_member_detected+isw_raid_member_detected\
 +hpt45x_raid_member_detected+adaptec_raid_member_detected\
 +jmicron_raid_member_detected))
 
+# swap can be detected by blkid if it is a partition or it can be a swapfile
+# declared in fstab
+detect_fs swap
+detect_swapfile
+swap_detected=$((swap_detected+swapfile_detected))
+
 # Use detect_util for all utilities
 detect_util btrfs_util btrfs
 detect_util zfs_util zfs
 detect_util luks_util cryptsetup
 detect_util lvm_util lvchange
 detect_util dmraid_util dmraid
+detect_util swap_util swapon
 
 # Finally detect and apply the configuration
 check_and_apply_conf "$btrfs_detected" "$btrfs_util_exists" BTRFS BTRFS btrfs "[btrfs_progs]"
@@ -125,6 +137,8 @@ check_and_apply_conf_zpool "$zfs_detected" "$zfs_util_exists" ZFS
 check_and_apply_conf "$crypto_LUKS_detected" "$luks_util_exists" CRYPTTAB LUKS cryptsetup "[cryptsetup]"
 check_and_apply_conf "$LVM2_member_detected" "$lvm_util_exists" LVM LVM lvchange "[lvm2]"
 check_and_apply_conf "$dmraid_detected" "$dmraid_util_exists" DMRAID DMRAID dmraid "[dmraid]"
+check_and_apply_conf "$swap_detected" "$swap_util_exists" SWAP SWAP swapon "[util-linux]"
+
 
 66-yeller %g "Please re-enable the boot@system service
 for the changes to take effect by running (as root):