From: Tim Johnson Date: Tue, 25 Jun 2019 20:46:48 +0000 (-0700) Subject: Script Cleanup X-Git-Tag: v0.4.0~17 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F96%2F15996%2F3;p=releng%2Fcommon-packer.git Script Cleanup 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 --- diff --git a/.coafile b/.coafile index e5d1171..2f3d846 100644 --- 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 diff --git a/ansible-galaxy.sh b/ansible-galaxy.sh index 0c124ba..1d9a080 100755 --- a/ansible-galaxy.sh +++ b/ansible-galaxy.sh @@ -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 diff --git a/provision/install-python.sh b/provision/install-python.sh old mode 100644 new mode 100755 index 6ec0fdf..24f702f --- a/provision/install-python.sh +++ b/provision/install-python.sh @@ -10,11 +10,29 @@ ############################################################################## # 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