Skip to contentSkip to conversation

lvresize: use POSIX shell for lvresize_fs_helper.sh

PATCH New Natanael Copa 1 participant 1 message Nov 16, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lvresize: use POSIX shell for lvresize_fs_helper.sh

Use POSIX shell for the fs reisize helper to avoid dependency of bash. This is useful for ditributions like Alpine Linux which does not include bash by default.

---
 scripts/lvresize_fs_helper.sh | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
scripts/lvresize_fs_helper.sh +14 -14
index 031b8453b..df153eb09 100755
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Copyright (C) 2022 Red Hat, Inc. All rights reserved.
 #
@@ -73,7 +73,7 @@ fsextend() {
 		fi
 	fi
 
-	if [[ "$FSTYPE" == "ext"* ]]; then
+	if [ "${FSTYPE#ext}" != "$FSTYPE" ]; then
 		logmsg "resize2fs ${DEVPATH}"
 		resize2fs "$DEVPATH"
 		if [ $? -eq 0 ]; then
@@ -82,7 +82,7 @@ fsextend() {
 			logmsg "resize2fs failed"
 			RESIZEFS_FAILED=1
 		fi
-	elif [[ "$FSTYPE" == "xfs" ]]; then
+	elif [ "$FSTYPE" = "xfs" ]; then
 		logmsg "xfs_growfs ${DEVPATH}"
 		xfs_growfs "$DEVPATH"
 		if [ $? -eq 0 ]; then
@@ -109,7 +109,7 @@ fsextend() {
 
 	# If the fs was temporarily unmounted, now remount it.
 	# Not considered a command failure if this fails.
-	if [[ $DO_UNMOUNT -eq 1 && $REMOUNT -eq 1 ]]; then
+	if [ "$DO_UNMOUNT" -eq 1 ] && [ "$REMOUNT" -eq 1 ]; then
 		logmsg "remount ${DEVPATH} ${MOUNTDIR}"
 		mount -t "$FSTYPE" "$DEVPATH" "$MOUNTDIR"
 		if [ $? -eq 0 ]; then
@@ -162,7 +162,7 @@ fsreduce() {
 		fi
 	fi
 
-	if [[ "$FSTYPE" == "ext"* ]]; then
+	if [ "${FSTYPE#ext}" != "$FSTYPE" ]; then
 		NEWSIZEKB=$(($NEWSIZEBYTES/1024))
 		logmsg "resize2fs ${DEVPATH} ${NEWSIZEKB}k"
 		resize2fs "$DEVPATH" "$NEWSIZEKB"k
@@ -208,7 +208,7 @@ fsreduce() {
 
 	# If the fs was temporarily unmounted, now remount it.
 	# Not considered a command failure if this fails.
-	if [[ $DO_UNMOUNT -eq 1 && $REMOUNT -eq 1 ]]; then
+	if [ "$DO_UNMOUNT" -eq 1 ] && [ "$REMOUNT" -eq 1 ]; then
 		logmsg "remount ${DEVPATH} ${MOUNTDIR}"
 		mount -t "$FSTYPE" "$DEVPATH" "$MOUNTDIR"
 		if [ $? -eq 0 ]; then
@@ -307,7 +307,7 @@ DO_FSCK=0
 # mounted and the script unmounted it.
 REMOUNT=0
 
-if [ "$UID" != 0 ] && [ "$EUID" != 0 ]; then
+if [ "$(id -u)" != 0 ]; then
 	errorexit "${SCRIPTNAME} must be run as root."
 fi
 
@@ -388,11 +388,11 @@ done
 #
 
 # There are three top level commands: --fsextend, --fsreduce, --cryptresize.
-if [[ "$DO_FSEXTEND" -eq 0 && "$DO_FSREDUCE" -eq 0 && "$DO_CRYPTRESIZE" -eq 0 ]]; then
+if [ "$DO_FSEXTEND" -eq 0 ] && [ "$DO_FSREDUCE" -eq 0 ]  && [ "$DO_CRYPTRESIZE" -eq 0 ]; then
 	errorexit "Missing --fsextend|--fsreduce|--cryptresize."
 fi
 
-if [[ "$DO_FSEXTEND" -eq 1 || "$DO_FSREDUCE" -eq 1 ]]; then
+if [ "$DO_FSEXTEND" -eq 1 ] || [ "$DO_FSREDUCE" -eq 1 ]; then
 	case "$FSTYPE" in
 	  ext[234]) ;;
 	  "xfs")    ;;
@@ -404,7 +404,7 @@ if [[ "$DO_FSEXTEND" -eq 1 || "$DO_FSREDUCE" -eq 1 ]]; then
 	fi
 fi
 
-if [[ "$DO_CRYPTRESIZE" -eq 1 && -z "$CRYPTPATH" ]]; then
+if [ "$DO_CRYPTRESIZE" -eq 1 ] && [ -z "$CRYPTPATH" ]; then
 	errorexit "Missing required --cryptpath for --cryptresize."
 fi
 
@@ -422,15 +422,15 @@ if [ ! -e "$DEVPATH" ]; then
 	errorexit "Device does not exist \"$DEVPATH\"."
 fi
 
-if [[ "$DO_UNMOUNT" -eq 1 && -z "$MOUNTDIR" ]]; then
+if [ "$DO_UNMOUNT" -eq 1 ] && [ -z "$MOUNTDIR" ]; then
 	errorexit "Missing required --mountdir for --unmount."
 fi
 
-if [[ "$DO_FSREDUCE" -eq 1 && "$FSTYPE" == "xfs" ]]; then
+if [ "$DO_FSREDUCE" -eq 1 ] && [ "$FSTYPE" = "xfs" ]; then
 	errorexit "Cannot reduce xfs."
 fi
 
-if [[ "$DO_FSCK" -eq 1 && "$FSTYPE" == "xfs" ]]; then
+if [ "$DO_FSCK" -eq 1 ] && [ "$FSTYPE" = "xfs" ]; then
 	errorexit "Cannot use --fsck with xfs."
 fi
 
@@ -440,7 +440,7 @@ if [ "$DO_MOUNT" -eq 1 ]; then
 		errorexit "Failed to create temp dir."
 	fi
 	# In case the script terminates without doing cleanup
-	function finish {
+	finish() {
 		if [ "$TMP_MOUNT_DONE" -eq 1 ]; then
 			logmsg "exit unmount ${TMPDIR}"
 			umount "$TMPDIR"
Signature · 1 line
2.38.1