[COMMON] Fix condition bracket bashisms - step 1
pointed out by checkbashisms
$ mycmd=$(tox -e checkbashisms
| grep '(\[\[ foo \]\] should be \[ foo \])'
| sed -e "s@^[^.]*\(.[^ ]*\) line \([0-9]*\) .*@sed -i '\2s/\\\[\\\[\\\(
[^]]*\\\)\\\]\\\]/[\\\1]/g' \1;@")
$ eval $mycmd
plus fix manually quoting hells induced and bash specific regex
and multi-conditions
Issue-ID: OOM-2643
Signed-off-by: Guillaume Lambert <guillaume.lambert@orange.com>
Change-Id: Ie7ca5b71938fae22c200b7fead418618160fbe19
diff --git a/kubernetes/common/cassandra/resources/restore.sh b/kubernetes/common/cassandra/resources/restore.sh
index a810534..7f271d2 100644
--- a/kubernetes/common/cassandra/resources/restore.sh
+++ b/kubernetes/common/cassandra/resources/restore.sh
@@ -41,7 +41,7 @@
print_usage
fi
-while [[ $# -gt 0 ]]
+while [ $# -gt 0 ]
do
key="$1"
shift
diff --git a/kubernetes/config/prepull_docker.sh b/kubernetes/config/prepull_docker.sh
index 040adec..590d651 100755
--- a/kubernetes/config/prepull_docker.sh
+++ b/kubernetes/config/prepull_docker.sh
@@ -102,7 +102,7 @@
for line in `parse_yaml $filename`
do
#skiping commented line
- if [[ ${line:0:1} != '#' ]]; then
+ if [ "${line:0:1}" != '#' ]; then
#find all image subtag inside converted values.yaml file's lines
if echo $line | grep -q $IMAGE_TEXT ; then
#find imageName inside line
diff --git a/kubernetes/helm/plugins/deploy/deploy.sh b/kubernetes/helm/plugins/deploy/deploy.sh
index 0d434ad..ce8e802 100755
--- a/kubernetes/helm/plugins/deploy/deploy.sh
+++ b/kubernetes/helm/plugins/deploy/deploy.sh
@@ -49,14 +49,14 @@
for index in "${!SUBCHART_NAMES[@]}"; do
START=${SUBCHART_NAMES[index]}
END=${SUBCHART_NAMES[index+1]}
- if [[ $START = "global:" ]]; then
+ if [ "$START" = "global:" ]; then
echo "global:" > $GLOBAL_OVERRIDES
cat $COMPUTED_OVERRIDES | sed '/common:/,/consul:/d' \
| sed -n '/^'"$START"'/,/'log:'/p' | sed '1d;$d' >> $GLOBAL_OVERRIDES
else
SUBCHART_DIR="$CACHE_SUBCHART_DIR/$(echo "$START" |cut -d':' -f1)"
- if [[ -d "$SUBCHART_DIR" ]]; then
- if [[ -z "$END" ]]; then
+ if [ -d "$SUBCHART_DIR" ]; then
+ if [ -z "$END" ]; then
cat $COMPUTED_OVERRIDES | sed -n '/^'"$START"'/,/'"$END"'/p' \
| sed '1d;$d' | cut -c3- > $SUBCHART_DIR/subchart-overrides.yaml
else
@@ -72,11 +72,11 @@
n=${#flags[*]}
i=0 ; while [ "$i" -lt "$n" ]; do
PARAM=${flags[i]}
- if [[ $PARAM = "-f" || \
- $PARAM = "--values" || \
- $PARAM = "--set" || \
- $PARAM = "--set-string" || \
- $PARAM = "--version" ]]; then
+ if [ "$PARAM" = "-f" ] || \
+ [ "$PARAM" = "--values" ] || \
+ [ "$PARAM" = "--set" ] || \
+ [ "$PARAM" = "--set-string" ] || \
+ [ "$PARAM" = "--version" ]; then
# skip param and its value
i=$((i + 1))
else
@@ -89,7 +89,7 @@
deploy() {
# validate params
- if [[ -z "$1" || -z "$2" ]]; then
+ if [ -z "$1" ] || [ -z "$2" ]; then
usage
exit 0
fi
@@ -99,7 +99,7 @@
FLAGS=${@:3}
CHART_REPO="$(echo "$CHART_URL" |cut -d'/' -f1)"
CHART_NAME="$(echo "$CHART_URL" |cut -d'/' -f2)"
- if [[ $HELM_VER = "v3."* ]]; then
+ if expr "$HELM_VER" : "v3\..*" ; then
CACHE_DIR=~/.local/share/helm/plugins/deploy/cache
else
CACHE_DIR=~/.helm/plugins/deploy/cache
@@ -111,23 +111,23 @@
# determine if verbose output is enabled
VERBOSE="false"
- if [[ $FLAGS = *"--verbose"* ]]; then
+ if expr "$FLAGS" : ".*--verbose.*" ; then
FLAGS="$(echo $FLAGS| sed -n 's/--verbose//p')"
VERBOSE="true"
fi
# determine if delay for deployment is enabled
DELAY="false"
- if [[ $FLAGS = *"--delay"* ]]; then
+ if expr "$FLAGS" : ".*--delay.*" ; then
FLAGS="$(echo $FLAGS| sed -n 's/--delay//p')"
DELAY="true"
fi
# determine if set-last-applied flag is enabled
SET_LAST_APPLIED="false"
- if [[ $FLAGS = *"--set-last-applied"* ]]; then
+ if expr"$FLAGS" : ".*--set-last-applied.*" ; then
FLAGS="$(echo $FLAGS| sed -n 's/--set-last-applied//p')"
SET_LAST_APPLIED="true"
fi
- if [[ $FLAGS = *"--dry-run"* ]]; then
+ if expr "$FLAGS" : ".*--dry-run.*" ; then
VERBOSE="true"
FLAGS="$FLAGS --debug"
fi
@@ -150,7 +150,7 @@
SUBCHART_RELEASE="$(echo "$RELEASE" |cut -d'-' -f2)"
# update specified subchart without parent
RELEASE="$(echo "$RELEASE" |cut -d'-' -f1)"
- if [[ $SUBCHART_RELEASE = $RELEASE ]]; then
+ if [ "$SUBCHART_RELEASE" = "$RELEASE" ]; then
SUBCHART_RELEASE=
fi
@@ -158,7 +158,7 @@
rm -rf $CACHE_DIR
# fetch umbrella chart (parent chart containing subcharts)
- if [[ -d "$CHART_URL" ]]; then
+ if [ -d "$CHART_URL" ]; then
mkdir -p $CHART_DIR
cp -R $CHART_URL/* $CHART_DIR/
@@ -195,20 +195,20 @@
generate_overrides $COMPUTED_OVERRIDES $GLOBAL_OVERRIDES
# upgrade/install parent chart first
- if [[ -z "$SUBCHART_RELEASE" ]]; then
+ if [ -z "$SUBCHART_RELEASE" ]; then
LOG_FILE=$LOG_DIR/${RELEASE}.log
:> $LOG_FILE
helm upgrade -i $RELEASE $CHART_DIR $DEPLOY_FLAGS -f $COMPUTED_OVERRIDES \
> $LOG_FILE.log 2>&1
- if [[ $VERBOSE = "true" ]]; then
+ if [ "$VERBOSE" = "true" ]; then
cat $LOG_FILE
else
echo "release \"$RELEASE\" deployed"
fi
# Add annotation last-applied-configuration if set-last-applied flag is set
- if [[ $SET_LAST_APPLIED = "true" ]]; then
+ if [ "$SET_LAST_APPLIED" = "true" ]; then
helm get manifest ${RELEASE} \
| kubectl apply set-last-applied --create-annotation -n onap -f - \
> $LOG_FILE.log 2>&1
@@ -224,12 +224,12 @@
SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml
SUBCHART_ENABLED=0
- if [[ -f $SUBCHART_OVERRIDES ]]; then
+ if [ -f $SUBCHART_OVERRIDES ]; then
SUBCHART_ENABLED=$(cat $SUBCHART_OVERRIDES | grep -c "^enabled: true")
fi
- if [[ $SUBCHART_ENABLED -eq 1 ]]; then
- if [[ -z "$SUBCHART_RELEASE" || $SUBCHART_RELEASE = "$subchart" ]]; then
+ if [ $SUBCHART_ENABLED -eq 1 ]; then
+ if [ -z "$SUBCHART_RELEASE" ] || [ "$SUBCHART_RELEASE" = "$subchart" ]; then
LOG_FILE=$LOG_DIR/"${RELEASE}-${subchart}".log
:> $LOG_FILE
@@ -237,19 +237,19 @@
$DEPLOY_FLAGS -f $GLOBAL_OVERRIDES -f $SUBCHART_OVERRIDES \
> $LOG_FILE 2>&1
- if [[ $VERBOSE = "true" ]]; then
+ if [ "$VERBOSE" = "true" ]; then
cat $LOG_FILE
else
echo "release \"${RELEASE}-${subchart}\" deployed"
fi
# Add annotation last-applied-configuration if set-last-applied flag is set
- if [[ $SET_LAST_APPLIED = "true" ]]; then
+ if [ "$SET_LAST_APPLIED" = "true" ]; then
helm get manifest "${RELEASE}-${subchart}" \
| kubectl apply set-last-applied --create-annotation -n onap -f - \
> $LOG_FILE.log 2>&1
fi
fi
- if [[ $DELAY = "true" ]]; then
+ if [ "$DELAY" = "true" ]; then
echo sleep 3m
sleep 3m
fi
@@ -257,7 +257,7 @@
array=($(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}"))
n=${#array[*]}
for i in $(seq $(($n-1)) -1 0); do
- if [[ $HELM_VER = "v3."* ]]; then
+ if expr "$HELM_VER" : "v3\..*" ; then
helm del "${array[i]}"
else
helm del "${array[i]}" --purge
@@ -267,7 +267,7 @@
done
# report on success/failures of installs/upgrades
- if [[ $HELM_VER = "v3."* ]]; then
+ if expr "$HELM_VER" : "v3\..*" ; then
helm ls --all-namespaces | grep -i FAILED | grep $RELEASE
else
helm ls | grep FAILED | grep $RELEASE
diff --git a/kubernetes/helm/plugins/undeploy/undeploy.sh b/kubernetes/helm/plugins/undeploy/undeploy.sh
index 1689bf1..790f84f 100755
--- a/kubernetes/helm/plugins/undeploy/undeploy.sh
+++ b/kubernetes/helm/plugins/undeploy/undeploy.sh
@@ -29,7 +29,7 @@
done
}
-if [[ $# < 1 ]]; then
+if [ $# < 1 ]; then
echo "Error: command 'undeploy' requires a release name"
exit 0
fi
diff --git a/kubernetes/robot/demo-k8s.sh b/kubernetes/robot/demo-k8s.sh
index d48070c..099f80c 100755
--- a/kubernetes/robot/demo-k8s.sh
+++ b/kubernetes/robot/demo-k8s.sh
@@ -63,7 +63,7 @@
# Check if execscript flag is used and drop it from input arguments
-if [[ "${!#}" = "execscript" ]]; then
+if [ "${!#}" = "execscript" ]; then
set -- "${@:1:$#-1}"
execscript=true
fi
diff --git a/kubernetes/robot/ete-k8s.sh b/kubernetes/robot/ete-k8s.sh
index 97f4e4d..15d07fb 100755
--- a/kubernetes/robot/ete-k8s.sh
+++ b/kubernetes/robot/ete-k8s.sh
@@ -76,7 +76,7 @@
ETEHOME=/var/opt/ONAP
-if [[ "${!#}" = "execscript" ]]; then
+if [ "${!#}" = "execscript" ]; then
for script in $(ls -1 "$DIR/$SCRIPTDIR"); do
[ -f "$DIR/$SCRIPTDIR/$script" ] && [ -x "$DIR/$SCRIPTDIR/$script" ] && source "$DIR/$SCRIPTDIR/$script"
done
diff --git a/kubernetes/robot/eteHelm-k8s.sh b/kubernetes/robot/eteHelm-k8s.sh
index 2512e5f..d5e2fa4 100755
--- a/kubernetes/robot/eteHelm-k8s.sh
+++ b/kubernetes/robot/eteHelm-k8s.sh
@@ -44,7 +44,7 @@
ETEHOME=/var/opt/ONAP
-if [[ "${!#}" = "execscript" ]]; then
+if [ "${!#}" = "execscript" ]; then
for script in $(ls -1 "$DIR/$SCRIPTDIR"); do
[ -f "$DIR/$SCRIPTDIR/$script" ] && [ -x "$DIR/$SCRIPTDIR/$script" ] && source "$DIR/$SCRIPTDIR/$script"
done
diff --git a/kubernetes/robot/scripts/etescript/vnfsdk-etescript.sh b/kubernetes/robot/scripts/etescript/vnfsdk-etescript.sh
index 19864d4..a93f109 100755
--- a/kubernetes/robot/scripts/etescript/vnfsdk-etescript.sh
+++ b/kubernetes/robot/scripts/etescript/vnfsdk-etescript.sh
@@ -35,7 +35,7 @@
mkdir "$DIR/$SCRIPTDIR/tmp"
cd "$DIR/$SCRIPTDIR/tmp"
-if [[ -f rootCA-robot-$SDCVALID.cert && -f package-robot-$SDCVALID.cert && -f package-robot-$SDCINVALID.cert && -f package-private-robot-$SDCVALID.key && -f package-private-robot-$SDCINVALID.key ]]; then
+if [ -f rootCA-robot-$SDCVALID.cert ] && [ -f package-robot-$SDCVALID.cert ] && [ -f package-robot-$SDCINVALID.cert ] && [ -f package-private-robot-$SDCVALID.key ] && [ -f package-private-robot-$SDCINVALID.key ]; then
echo "All files are present";
else
generate_ca_key_cert_and_package_cert_issued_by_CA $SDCVALID