[COMMON] Enforce checkbashisms tox profile 48/119248/17
authorGuillaume Lambert <guillaume.lambert@orange.com>
Fri, 12 Mar 2021 12:53:18 +0000 (13:53 +0100)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Wed, 22 Sep 2021 09:17:18 +0000 (09:17 +0000)
- add checkbahims to tox.ini default profiles
- remove -f options to unforce bashisms detection in explicit bash
  scripts and to differentiate treatments between bash and sh
- migrate #!/bin/bash shebangs to #!/bin/sh for scripts without bashisms
  The following scripts have not been migrated since they still use
  bashisms difficult to migrate (mostly arrays - more details below)

./kubernetes/common/mariadb-init/resources/config/db_init.sh
./kubernetes/portal/components/portal-mariadb/resources/config/ \
mariadb/docker-entrypoint.sh
./kubernetes/helm/plugins/deploy/deploy.sh
./kubernetes/helm/plugins/undeploy/undeploy.sh
./kubernetes/sdnc/components/sdnc-prom/resources/bin/ensureSdncActive.sh

$ find . -not -path '*/\.*' -name *.sh -exec checkbashisms -f {} + 2>&1\
| grep line | cut -d' ' -f 7- | sort | uniq -c | sort -k1,1nr
     18 (bash arrays, ${name[0|*|@]}):
      2 (declare):
      1 ($FUNCNAME):
      1 (shopt):
      1 (trap with ERR|DEBUG|RETURN):

https://mywiki.wooledge.org/Bashism#Arrays
https://mywiki.wooledge.org/Bashism#Special_Variables
https://mywiki.wooledge.org/Bashism#Builtins
https://www.oilshell.org/release/0.5.alpha2/test/spec.wwz/builtin-trap.html

Issue-ID: OOM-2643
Signed-off-by: Guillaume Lambert <guillaume.lambert@orange.com>
Change-Id: Id06ad1d45004321a293bdd26038d8da5f7b6b4ac

25 files changed:
docs/slave_nfs_node.sh
kubernetes/appc/resources/config/appc/opt/onap/appc/bin/health_check.sh
kubernetes/appc/resources/config/appc/opt/onap/appc/bin/startODL.sh
kubernetes/appc/resources/config/appc/opt/onap/ccsdk/bin/installSdncDb.sh
kubernetes/common/cassandra/resources/config/docker-entrypoint.sh
kubernetes/common/music/resources/config/startup.sh
kubernetes/common/timescaledb/resources/init/init-schema.sh
kubernetes/config/prepull_docker.sh
kubernetes/contrib/components/ejbca/resources/ejbca-config.sh
kubernetes/contrib/dns-server-for-vhost-ingress-testing/deploy_dns.sh
kubernetes/contrib/metallb-loadbalancer-inst/install-metallb-on-cluster.sh
kubernetes/contrib/tools/check-for-staging-images.sh
kubernetes/contrib/tools/rke/rke_setup.sh
kubernetes/msb/components/msb-consul/resources/docker-entrypoint.sh
kubernetes/oof/components/oof-has/resources/config/healthy.sh
kubernetes/robot/demo-k8s.sh
kubernetes/robot/ete-k8s.sh
kubernetes/robot/eteHelm-k8s.sh
kubernetes/robot/instantiate-k8s.sh
kubernetes/robot/scripts/etescript/hvves-etescript.sh
kubernetes/robot/scripts/etescript/security-etescript.sh
kubernetes/robot/scripts/etescript/vnfsdk-etescript.sh
kubernetes/sdnc/components/sdnc-prom/resources/bin/prom.sh
kubernetes/sdnc/resources/config/bin/installSdncDb.sh
tox.ini

index fb2e230..1035ff5 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 usage () {
   echo "Usage:"
index f2675b0..424074a 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash -x
+#!/bin/sh -x
+
 {{/*
 # Copyright © 2018  AT&T, Amdocs, Bell Canada Intellectual Property.  All rights reserved.
 #
index 97df772..789f1b3 100755 (executable)
@@ -1,6 +1,6 @@
-#!/bin/bash -x
-{{/*
+#!/bin/sh -x
 
+{{/*
 ###
 # ============LICENSE_START=======================================================
 # APPC
index e3cee36..eb84b08 100755 (executable)
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/bin/sh
+
 {{/*
-#
 # ============LICENSE_START==========================================
 # org.onap.music
 # ===================================================================
index ab83cff..9cc0f5f 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # ============LICENSE_START=======================================================
 #  Copyright (c) 2021 Bell Canada.
index 54d7a2d..596ace6 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #function to provide help
 #desc: this function provide help menu
index 2c672e2..94c95d6 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 waitForEjbcaToStart() {
     until $(curl -kI https://localhost:8443/ejbca/publicweb/healthcheck/ejbcahealth --output /dev/null --silent --head --fail)
index 7e9077d..3c66fee 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash -e
+#!/bin/sh -e
 
 #   Copyright 2020 Samsung Electronics Co., Ltd.
 #
@@ -33,7 +33,8 @@ $0 --info Display howto configure target machine
 }
 
 
-target_machine_notice_info() {
+target_machine_notice_info()
+{
 cat << ==infodeploy
 Extra DNS server already deployed:
 1. You can add the DNS server to the target machine using following commands:
index ce5a19b..c62e2a5 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash -e
+#!/bin/sh -e
+
 #
 #   Copyright 2020 Samsung Electronics Co., Ltd.
 #
@@ -15,7 +16,8 @@
 #   limitations under the License.
 #
 
-usage() {
+usage()
+{
 cat << ==usage
 $0 Automatic configuration using external addresess from nodes
 $0 --help This message
index 2ee123b..a8938a9 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/bin/sh
+
 #############################################################################
 # Copyright © 2019 Bell.
 #
index 2b42402..18692d8 100755 (executable)
@@ -1,16 +1,11 @@
+#!/bin/sh
+
 #!/usr/bin/dumb-init /bin/sh
+# As of docker 1.13, using docker run --init achieves the same outcome than dumb-init.
+
 set -e
 set -x
 
-# Note above that we run dumb-init as PID 1 in order to reap zombie processes
-# as well as forward signals to all processes in its session. Normally, sh
-# wouldn't do either of these functions so we'd leak zombies as well as do
-# unclean termination of all our sub-processes.
-# As of docker 1.13, using docker run --init achieves the same outcome.
-
-# You can set CONSUL_BIND_INTERFACE to the name of the interface you'd like to
-# bind to and this will look up the IP and pass the proper -bind= option along
-# to Consul.
 CONSUL_BIND=
 if [ -n "$CONSUL_BIND_INTERFACE" ]; then
   CONSUL_BIND_ADDRESS=$(ip -o -4 addr list $CONSUL_BIND_INTERFACE | head -n1 | awk '{print $4}' | cut -d/ -f1)
index 37631bc..4393905 100755 (executable)
@@ -1,4 +1,5 @@
-#!/bin/bash
+#!/bin/sh
+
 # Copyright (C) 2018 Amdocs, Bell Canada
 # Modifications Copyright (C) 2019 Samsung
 # Modifications Copyright (C) 2020 Nokia
index 01cf092..4ef8f46 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Copyright © 2018 Amdocs, Bell Canada
 #
index 8b74da7..1b31c16 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
 #
index 623870b..aef812b 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
 #
index fa76a9e..6d7ada6 100755 (executable)
@@ -1,6 +1,6 @@
-#!/bin/bash
-{{/*
+#!/bin/sh
 
+{{/*
 # Copyright © 2018 Amdocs
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
index 3c08dd6..2406a48 100755 (executable)
@@ -1,6 +1,6 @@
-#!/bin/bash
-{{/*
+#!/bin/sh
 
+{{/*
 ###
 # ============LICENSE_START=======================================================
 # ONAP : SDN-C
diff --git a/tox.ini b/tox.ini
index 01e9953..7339601 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -4,6 +4,7 @@ envlist =
  docs,
  docs-linkcheck,
  gitlint,
+ checkbashisms,
 skipsdist=true
 
 [doc8]
@@ -52,7 +53,7 @@ commands =
     sh -c 'which checkbashisms>/dev/null  || sudo yum install devscripts-minimal || sudo apt-get install devscripts \
         || (echo "checkbashisms command not found - please install it (e.g. sudo apt-get install devscripts | \
         yum install devscripts-minimal )" >&2 && exit 1)'
-    find . -not -path '*/\.*' -name *.sh -exec checkbashisms -f  \{\} +
+    find . -not -path '*/\.*' -name *.sh -exec checkbashisms \{\} +
 
 [testenv:autopep8]
 deps = autopep8