From b1e004b1ed7f5b9850cbf41e5764b7c0daab0888 Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Wed, 23 May 2018 15:02:05 +0200 Subject: [PATCH] TT#29620 Update ngcp-api.inc to follow Sipwise shell style Also removed unnecessary exit code handling through the separate variable. Fixed error output to STDERR and add one more check for the file readability. Change-Id: I38f54f027f16c45cd54f69a6bd42b3911fc2eec6 --- tools/ngcp-api.inc | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/ngcp-api.inc b/tools/ngcp-api.inc index 6f2d0e69b7..69291e9a8d 100644 --- a/tools/ngcp-api.inc +++ b/tools/ngcp-api.inc @@ -1,15 +1,23 @@ +#!/bin/bash + +set -e + importcreds () { - if [ -f "$CREDS" ]; then - echo "$CREDS present, checking perms" - set +e; stat "$CREDS" | grep 'Access: (0600' 1>/dev/null; r=$?; set -e - if [ "$r" = "0" ]; then - echo "$CREDS permissions ok" - . "$CREDS" - else - echo "$CREDS must have permissions 600" - exit 1 - fi - fi -} + if [ ! -f "${CREDS}" ]; then + return + fi + if [ ! -r "${CREDS}" ]; then + echo "Error: cannot read ${CREDS}" >&2 + exit 1 + fi + echo "${CREDS} present, checking perms" + if stat "${CREDS}" | grep -q 'Access: (0600' 1>/dev/null ; then + echo "${CREDS} permissions ok" + . "${CREDS}" + else + echo "Error: ${CREDS} must have permissions 600" >&2 + exit 1 + fi +}