Script Cleanup 96/15996/3
authorTim Johnson <tijohnson@linuxfoundation.org>
Tue, 25 Jun 2019 20:46:48 +0000 (13:46 -0700)
committerTim Johnson <tijohnson@linuxfoundation.org>
Tue, 2 Jul 2019 17:14:13 +0000 (10:14 -0700)
Improved error handling, more succinct output (removed -x flag). Minor
enhancements tox config (.coafile). Changed local variables to
lower-case.

Change-Id: Ice1768f01ed513b7236b7cfa42d4b32886a3c83e
Signed-off-by: Tim Johnson <tijohnson@linuxfoundation.org>
.coafile
ansible-galaxy.sh
provision/install-python.sh [changed mode: 0644->0755]

index e5d1171..2f3d846 100644 (file)
--- a/.coafile
+++ b/.coafile
@@ -28,11 +28,12 @@ files = templates/**.json,
 indent_size = 2
 
 [all.ShellCheck]
-bears = ShellCheckBear,SpaceConsistencyBear
-files = provision/**.sh
+bears = ShellCheckBear, SpaceConsistencyBear, LineLengthBear
+files = provision/**.sh, ansible-galaxy.sh
 shell = bash
 indent_size = 4
-use_spaces = yeah
+use_spaces = True
+max_line_length = 80
 
 [YAML]
 bears = YAMLLintBear
index 0c124ba..1d9a080 100755 (executable)
@@ -9,14 +9,23 @@
 # http://www.eclipse.org/legal/epl-v10.html
 ##############################################################################
 
-ANSIBLE_ROLES_PATH="${1:-.galaxy}"
-ANSIBLE_REQUIREMENTS_FILE="${2:-requirements.yaml}"
-SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+set -eu -o pipefail -o noglob
 
-set -eux -o pipefail
+echo "----> ansible-galaxy.sh"
 
-ansible-galaxy install -p "$ANSIBLE_ROLES_PATH" -r "$SCRIPT_DIR/requirements.yaml"
+ansible_roles_path=${1:-.galaxy}
+ansible_requirements_file=${2:-requirements.yaml}
+script_dir=$(dirname "$0")
 
-if [ -f "$ANSIBLE_REQUIREMENTS_FILE" ]; then
-    ansible-galaxy install -p "$ANSIBLE_ROLES_PATH" -r "$ANSIBLE_REQUIREMENTS_FILE"
+cmd="ansible-galaxy install -p $ansible_roles_path -r \
+         $script_dir/requirements.yaml"
+echo "Running: $cmd"
+$cmd
+
+# Check for local requirements file
+if [[ -f $ansible_requirements_file ]]; then
+    cmd="ansible-galaxy install -p $ansible_roles_path -r \
+             $ansible_requirements_file"
+    echo "Running: $cmd"
+    $cmd
 fi
old mode 100644 (file)
new mode 100755 (executable)
index 6ec0fdf..24f702f
 ##############################################################################
 # vi: ts=4 sw=4 sts=4 et :
 
+set -eu -o pipefail -o noglob
+
+echo "----> install-python.sh"
+
 # Ansible requires Python 2 so check availability and install as necessary.
-if ! command -v /usr/bin/python; then
-    # Ubuntu 16.04 does not come with Python 2 by default.
-    if command -v apt; then
-        apt -y update
-        apt install -y python-minimal
+# Ubuntu 16.04 does not come with Python 2 by default
+
+function is_ubuntu()
+{
+    # If the file exist and contains ubuntu entry return 0
+    if egrep -q "^ID=ubuntu" /etc/os-release 2> /dev/null; then
+        echo "Distro is Ubuntu"
+        return 0
     fi
+    echo "Distro is NOT Ubuntu"
+    return 1
+}
+
+if is_ubuntu; then
+    echo "Installing python-minimal..."
+    apt -y update
+    apt install -y python-minimal
 fi
+
+type python
+type sudo