From: Christian Göttsche <cgzones@xxxxxxxxxxxxxx> Improve portability and avoid actual issues being hidden. Signed-off-by: Christian Göttsche <cgzones@xxxxxxxxxxxxxx> --- tests/kvercmp | 16 +++++++++------- tests/os_detect | 10 ++++++---- tests/pol_detect | 12 +++++++----- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tests/kvercmp b/tests/kvercmp index 3742f16..4b1e345 100755 --- a/tests/kvercmp +++ b/tests/kvercmp @@ -1,15 +1,17 @@ -#!/bin/bash +#!/bin/sh -function kvercmp() +set -eu + +kvercmp() { - ver1=`echo $1 | sed 's/-/./'` - ver2=`echo $2 | sed 's/-/./'` + ver1=$(echo "$1" | sed 's/-/./') + ver2=$(echo "$2" | sed 's/-/./') ret=0 i=1 - while [ 1 ]; do - digit1=`echo $ver1 | cut -d . -f $i` - digit2=`echo $ver2 | cut -d . -f $i` + while true; do + digit1=$(echo "$ver1" | cut -d . -f $i) + digit2=$(echo "$ver2" | cut -d . -f $i) if [ -z "$digit1" ]; then if [ -z "$digit2" ]; then diff --git a/tests/os_detect b/tests/os_detect index cddcb85..6b723f6 100755 --- a/tests/os_detect +++ b/tests/os_detect @@ -1,8 +1,10 @@ -#!/bin/bash +#!/bin/sh -if [[ -r /etc/redhat-release ]]; then - ver=$(cat /etc/redhat-release | sed -ne '/^Red Hat Enterprise Linux/p') - if [[ -n $ver ]]; then +set -eu + +if [ -r /etc/redhat-release ]; then + ver=$(sed -ne '/^Red Hat Enterprise Linux/p' /etc/redhat-release) + if [ -n "$ver" ]; then echo "$ver" | \ sed -e 's/Red Hat Enterprise Linux[ \ta-zA-Z]*\([0-9]\+\).*/RHEL\1/' fi diff --git a/tests/pol_detect b/tests/pol_detect index ba25b94..8c07997 100755 --- a/tests/pol_detect +++ b/tests/pol_detect @@ -1,4 +1,6 @@ -#!/bin/bash +#!/bin/sh + +set -eu if [ $# -ne 1 ]; then echo "Usage $0 <selinuxfs directory>" @@ -8,10 +10,10 @@ fi # This is heuristic but seems unlikely to be wrong, # the kernel initial sid should always be SystemHigh # and SystemHigh is normally s15 -level=$(cat $1/initial_contexts/kernel | tr '\0' '\n' | cut -d: -f4) +level=$(cat "$1/initial_contexts/kernel" | tr '\0' '\n' | cut -d: -f4) -if [ -z $level ]; then echo "NON-MLS" -elif [ $level = 's0' ]; then echo "MCS" -elif [ $level = 's15' ]; then echo "MLS" +if [ -z "$level" ]; then echo "NON-MLS" +elif [ "$level" = 's0' ]; then echo "MCS" +elif [ "$level" = 's15' ]; then echo "MLS" else echo "UNKNOWN" fi -- 2.45.2