]> git.proxmox.com Git - pve-installer.git/commitdiff
unconfigured: fix getting swap devices
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 14 Jun 2021 10:35:04 +0000 (12:35 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 14 Jun 2021 10:35:11 +0000 (12:35 +0200)
Previously we used a ugly hack to extract the device from the whole
line returned by passing it to bash's `set`, which assigns remaining
arguments it does not know about (or after "--") to $1, $2, etc.

This is ugly due to:
* not using "--", so it could break easily
* being quite subtle in general, e.g., shellcheck does not likes
  unquoted variable expansions, so one would add quotes around
  breaking the actual use case

Just use awk to do both the grep and extraction, which is much
clearer to do

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
unconfigured.sh

index c18484ed7a12c9ddcf775a9eaff5bca28553f3c0..0f616669ec5bb0099e9bc2ce4812a514923b7d91 100755 (executable)
@@ -30,10 +30,9 @@ real_reboot() {
     /etc/init.d/udev stop
 
     echo -n "Deactivating swap..."
-    swap=$(grep /dev /proc/swaps);
+    swap=$(awk '/^\/dev\// { print $1 }' /proc/swaps);
     if [ -n "$swap" ]; then
-       set $swap
-       swapoff $1
+       swapoff "$swap"
     fi
     echo "done."