usr_sbin/grml2ram: Fix a couple of shellcheck warnings
authorDarshaka Pathirana <dpat@syn-net.org>
Fri, 5 Mar 2021 14:37:36 +0000 (15:37 +0100)
committerDarshaka Pathirana <dpat@syn-net.org>
Fri, 3 Dec 2021 11:54:54 +0000 (12:54 +0100)
- Ignore SC1091: Not following: /etc/grml/lsb-functions was not specified as input (see shellcheck -x).
- Ignore SC1091: Not following: /etc/grml/script-functions was not specified as input (see shellcheck -x).
- Set interpreter to /bin/bash because of SC2039: In POSIX sh, 'local' is undefined.
- SC2086: Double quote to prevent globbing and word splitting.
- SC2061: Quote the parameter to -name so the shell won't interpret it.
- SC2086: Double quote to prevent globbing and word splitting.
- SC2086: Double quote to prevent globbing and word splitting.
- SC2015: Note that A && B || C is not if-then-else. C may run when A is true.

usr_sbin/grml2ram

index 3482bdb..a4e119e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # Filename:      grml2ram
 # Purpose:       copy compressed GRML image to RAM
 # Authors:       (c) Michael Schierl <schierlm-public@gmx.de>, (c) Michael Prokop <mika@grml.org>
@@ -8,7 +8,9 @@
 
 set -e
 
+# shellcheck disable=SC1091
 . /etc/grml/lsb-functions
+# shellcheck disable=SC1091
 . /etc/grml/script-functions
 
 check4root || exit 1
@@ -50,7 +52,7 @@ getbootparam(){
 MEDIA_PATH="$(getbootparam live-media-path)"
 MEDIA_PATH="${MEDIA_PATH:-.}"
 
-IMAGE=$(find ${LIVECD_PATH}/${MEDIA_PATH}/ -name *.squashfs 2>/dev/null | head -1)
+IMAGE=$(find "${LIVECD_PATH}/${MEDIA_PATH}/" -name "*.squashfs" 2>/dev/null | head -1)
 if ! [ -r "$IMAGE" ] ; then
    if [ -r /cdrom/GRML/GRML ] ; then
       IMAGE='/cdrom/GRML/GRML'
@@ -68,7 +70,7 @@ case "$*" in -f|--force)
   ewarn "Forcing copy process for grml-image (${GRMLSIZE}kB) as requested via force option." ; eend 0
    ;;
   *)
-   if test $RAM -lt $GRMLSIZE ; then
+   if test "$RAM" -lt "$GRMLSIZE" ; then
       eerror "Sorry, not enough free RAM (${RAM}kB) available for grml-image (${GRMLSIZE}kB)." ; eend 1
       exit 1
    fi
@@ -96,7 +98,12 @@ fi
 [ -n "$GRMLDEV" ] || GRMLDEV='/dev/cdrom'
 
 einfo "Unmounting cdrom"
-[ -d $LIVECD_PATH ] && umount $LIVECD_PATH || umount /cdrom
+if [ -d $LIVECD_PATH ] ;
+then
+  umount $LIVECD_PATH
+else
+  umount /cdrom
+fi
 eend $?
 einfo "Now you can eject your grml-cd (e.g. run 'eject $GRMLDEV')." ; eend 0