Fix: add variable quoting to shell scripts
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 20 Feb 2018 17:16:25 +0000 (12:16 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 20 Feb 2018 17:33:19 +0000 (12:33 -0500)
Prevent errors if a path contains spaces.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
abi-debian-version.sh
abi-rhel-version.sh
rt-patch-version.sh

index 36da2129dabf84f26eee8c7f071da7cb0a19b56f..4f2c088685052212a53f707ffbcacb285bd8b4de 100755 (executable)
@@ -1,9 +1,9 @@
 #!/bin/sh
 
 # First argument is the path to the kernel headers.
-KPATH=$1
+KPATH="$1"
 
-if [ ! -f ${KPATH}/include/generated/package.h ]; then
+if [ ! -f "${KPATH}/include/generated/package.h" ]; then
        echo 0
        exit 0
 fi
@@ -11,10 +11,10 @@ fi
 # Debian snippet courtesy of Ben Hutchings
 
 # Assuming KPATH is the target kernel headers directory
-DEB_PACKAGE_VERSION=$(sed -rn 's/^#define LINUX_PACKAGE_ID " Debian (.*)"/\1/p' ${KPATH}/include/generated/package.h)
+DEB_PACKAGE_VERSION=$(sed -rn 's/^#define LINUX_PACKAGE_ID " Debian (.*)"/\1/p' "${KPATH}/include/generated/package.h")
 
 # Ignore backports part
-DEB_PACKAGE_VERSION=$(echo ${DEB_PACKAGE_VERSION} | sed -r 's/~(bpo|deb).*//')
+DEB_PACKAGE_VERSION=$(echo "${DEB_PACKAGE_VERSION}" | sed -r 's/~(bpo|deb).*//')
 
 # ckt (Canonical Kernel Team) kernels were used for a while during the jessie
 # cycle, their versionning is a bit different. They track the upstream vanilla
@@ -23,15 +23,15 @@ DEB_PACKAGE_VERSION=$(echo ${DEB_PACKAGE_VERSION} | sed -r 's/~(bpo|deb).*//')
 # switched back to upstream style at 3.16.36.
 
 # Get -ckt update number, if present
-KERNEL_CKT_UPDATE=$(echo ${DEB_PACKAGE_VERSION} | sed -rn 's/^[0-9]+\.[0-9]+\.[0-9]+-ckt([0-9]+).*/\1/p')
+KERNEL_CKT_UPDATE=$(echo "${DEB_PACKAGE_VERSION}" | sed -rn 's/^[0-9]+\.[0-9]+\.[0-9]+-ckt([0-9]+).*/\1/p')
 test -n "${KERNEL_CKT_UPDATE}" || KERNEL_CKT_UPDATE=0
 
 # Get package revision
-DEB_PACKAGE_REVISION=$(echo ${DEB_PACKAGE_VERSION} | sed -r 's/.*-([^-]+)$/\1/')
+DEB_PACKAGE_REVISION=$(echo "${DEB_PACKAGE_VERSION}" | sed -r 's/.*-([^-]+)$/\1/')
 # Get non-sec update number
-DEB_PACKAGE_REVISION_BASE=$(echo ${DEB_PACKAGE_REVISION} | sed -r 's/^([0-9]+).*/\1/')
+DEB_PACKAGE_REVISION_BASE=$(echo "${DEB_PACKAGE_REVISION}" | sed -r 's/^([0-9]+).*/\1/')
 # Get security update number, if present
-DEB_PACKAGE_REVISION_SECURITY=$(echo ${DEB_PACKAGE_REVISION} | sed -rn 's/.*\+(squeeze|deb[0-9]+)+u([0-9]+)$/\2/p')
+DEB_PACKAGE_REVISION_SECURITY=$(echo "${DEB_PACKAGE_REVISION}" | sed -rn 's/.*\+(squeeze|deb[0-9]+)+u([0-9]+)$/\2/p')
 test -n "${DEB_PACKAGE_REVISION_SECURITY}" || DEB_PACKAGE_REVISION_SECURITY=0
 # Combine all update numbers into one
 DEB_API_VERSION=$((KERNEL_CKT_UPDATE * 10000 + DEB_PACKAGE_REVISION_BASE * 100 + DEB_PACKAGE_REVISION_SECURITY))
index 30f3c17c44b4eecc1aaa8723986593f8ebc78639..bd5328ac9c1ba807da6bf3eb47e4cfb07c4b3a26 100755 (executable)
@@ -1,19 +1,19 @@
 #!/bin/sh
 
 # First argument is the path to the kernel headers.
-KPATH=$1
+KPATH="$1"
 
-if [ ! -f ${KPATH}/include/generated/uapi/linux/version.h ]; then
+if [ ! -f "${KPATH}/include/generated/uapi/linux/version.h" ]; then
        echo 0
        exit 0
 fi
 
 # Assuming KPATH is the target kernel headers directory
-RHEL_RELEASE=$(sed -rn 's/^#define RHEL_RELEASE "(.*)"/\1/p' ${KPATH}/include/generated/uapi/linux/version.h)
+RHEL_RELEASE=$(sed -rn 's/^#define RHEL_RELEASE "(.*)"/\1/p' "${KPATH}/include/generated/uapi/linux/version.h")
 
-RHEL_RELEASE_MAJOR=$(echo ${RHEL_RELEASE} | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)/\1/')
-RHEL_RELEASE_MINOR=$(echo ${RHEL_RELEASE} | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)/\2/')
-RHEL_RELEASE_PATCH=$(echo ${RHEL_RELEASE} | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)/\3/')
+RHEL_RELEASE_MAJOR=$(echo "${RHEL_RELEASE}" | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)/\1/')
+RHEL_RELEASE_MINOR=$(echo "${RHEL_RELEASE}" | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)/\2/')
+RHEL_RELEASE_PATCH=$(echo "${RHEL_RELEASE}" | sed -r 's/^([0-9]+)\.([0-9]+)\.([0-9]+)/\3/')
 
 # Combine all update numbers into one
 RHEL_API_VERSION=$((RHEL_RELEASE_MAJOR * 10000 + RHEL_RELEASE_MINOR * 100 + RHEL_RELEASE_PATCH))
index 89c77554358a4a454bc893885326320a28dabff5..6a00fef08b0498b648bc8e75c7311c276421e674 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 # First argument is the path to the kernel headers.
-KPATH=$1
+KPATH="$1"
 
 VERSIONFILE=""
 
@@ -22,4 +22,4 @@ if [ "x${RT_PATCH_VERSION}" = "x" ]; then
        exit 0
 fi
 
-echo ${RT_PATCH_VERSION}
+echo "${RT_PATCH_VERSION}"
This page took 0.038478 seconds and 4 git commands to generate.