diff --git a/tools_bin/ngcp-api-tools b/tools/ngcp-api.inc similarity index 100% rename from tools_bin/ngcp-api-tools rename to tools/ngcp-api.inc diff --git a/tools_bin/ngcp-api-delete b/tools_bin/ngcp-api-delete index ad4a178ade..66aed2c269 100755 --- a/tools_bin/ngcp-api-delete +++ b/tools_bin/ngcp-api-delete @@ -1,11 +1,10 @@ -#!/bin/sh +#!/bin/bash CURL="/usr/bin/curl" CREDS="$HOME/.ngcp-api" -TOOLS="/usr/bin/ngcp-api-tools" -test -f "$TOOLS" && . "$TOOLS" +TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { - cat << EOF + cat << EOF Usage: $0 [OPTIONS] sends a delete request to NGCP REST API @@ -14,11 +13,17 @@ OPTIONS: -h this help -v verbose mode EOF - exit 1 + exit 1 } -test -z "$APIUSER" && -f "$TOOLS" && importcreds -test -z "$APIUSER" && APIUSER="administrator:administrator" +if [ -z "$APIUSER" ] ; then + if [ -f "$TOOLS" ] ; then + source "$TOOLS" + importcreds + else + APIUSER="administrator:administrator" + fi +fi HEADERS="-H 'Connection: close'" while getopts "hv" OPTION @@ -38,6 +43,8 @@ done shift $(($OPTIND - 1)) URL="$1" -test -z "$URL" && usage; +if [ -z "$URL" ] ; then + usage +fi ${CURL} -i ${VERBOSE} -X DELETE "$HEADERS" --user "$APIUSER" --insecure "$URL" diff --git a/tools_bin/ngcp-api-get b/tools_bin/ngcp-api-get index 7975dd9f52..d33bdab766 100755 --- a/tools_bin/ngcp-api-get +++ b/tools_bin/ngcp-api-get @@ -1,24 +1,29 @@ #!/bin/bash CURL="/usr/bin/curl" CREDS="$HOME/.ngcp-api" -TOOLS="/usr/bin/ngcp-api-tools" -test -f "$TOOLS" && . "$TOOLS" +TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { - cat << EOF + cat << EOF Usage: $0 [OPTIONS] sends a get request to NGCP REST API OPTIONS: - -h this help - -v verbose mode + -h this help + -v verbose mode EOF - exit 1 + exit 1 } -test -z "$APIUSER" && -f "$TOOLS" && importcreds -test -z "$APIUSER" && APIUSER="administrator:administrator" +if [ -z "$APIUSER" ] ; then + if [ -f "$TOOLS" ] ; then + source "$TOOLS" + importcreds + else + APIUSER="administrator:administrator" + fi +fi HEADERS="-H 'Connection: close'" while getopts "hv" OPTION @@ -38,6 +43,8 @@ done shift $(($OPTIND - 1)) URL="$1" -test -z "$URL" && usage; +if [ -z "$URL" ] ; then + usage +fi ${CURL} -i ${VERBOSE} -X GET "$HEADERS" --user "$APIUSER" --insecure "$URL" diff --git a/tools_bin/ngcp-api-patch b/tools_bin/ngcp-api-patch index 1095951d24..6d9fa4d34c 100755 --- a/tools_bin/ngcp-api-patch +++ b/tools_bin/ngcp-api-patch @@ -1,11 +1,10 @@ -#!/bin/sh +#!/bin/bash CURL="/usr/bin/curl" CREDS="$HOME/.ngcp-api" -TOOLS="/usr/bin/ngcp-api-tools" -test -f "$TOOLS" && . "$TOOLS" +TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { - cat << EOF + cat << EOF Usage: $0 [OPTIONS] sends a patch request to NGCP REST API @@ -16,11 +15,17 @@ OPTIONS: -f read the input info from a file instead of read stdin -m use Header 'Refer: return=minimal' EOF - exit 1 + exit 1 } -test -z "$APIUSER" && -f "$TOOLS" && importcreds -test -z "$APIUSER" && APIUSER="administrator:administrator" +if [ -z "$APIUSER" ] ; then + if [ -f "$TOOLS" ] ; then + source "$TOOLS" + importcreds + else + APIUSER="administrator:administrator" + fi +fi INPUT="-T -" CTYPE="application/json-patch+json" PREFER="representation" @@ -53,7 +58,9 @@ done shift $(($OPTIND - 1)) URL="$1" -test -z "$URL" && usage; +if [ -z "$URL" ] ; then + usage +fi ${CURL} -i ${VERBOSE} -X PATCH \ -H 'Connection: close' -H "Prefer: return=$PREFER" \ diff --git a/tools_bin/ngcp-api-post b/tools_bin/ngcp-api-post index bf9c4bff06..39c6262a7a 100755 --- a/tools_bin/ngcp-api-post +++ b/tools_bin/ngcp-api-post @@ -1,11 +1,10 @@ -#!/bin/sh +#!/bin/bash CURL="/usr/bin/curl" CREDS="$HOME/.ngcp-api" -TOOLS="/usr/bin/ngcp-api-tools" -test -f "$TOOLS" && . "$TOOLS" +TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { - cat << EOF + cat << EOF Usage: $0 [OPTIONS] [content-type] sends a post request to NGCP REST API @@ -15,11 +14,17 @@ OPTIONS: -v verbose mode -f read the input info from a file instead of read stdin EOF - exit 1 + exit 1 } -test -z "$APIUSER" && -f "$TOOLS" && importcreds -test -z "$APIUSER" && APIUSER="administrator:administrator" +if [ -z "$APIUSER" ] ; then + if [ -f "$TOOLS" ] ; then + source "$TOOLS" + importcreds + else + APIUSER="administrator:administrator" + fi +fi INPUT="-T -" while getopts "f:hv" OPTION @@ -47,7 +52,9 @@ done shift $(($OPTIND - 1)) URL="$1" -test -z "$URL" && usage; +if [ -z "$URL" ] ; then + usage +fi CTYPE=${2:-application/json} ${CURL} -i ${VERBOSE} -X POST \ diff --git a/tools_bin/ngcp-api-put b/tools_bin/ngcp-api-put index ad72756000..ecdd2a0117 100755 --- a/tools_bin/ngcp-api-put +++ b/tools_bin/ngcp-api-put @@ -1,11 +1,10 @@ -#!/bin/sh +#!/bin/bash CURL="/usr/bin/curl" CREDS="$HOME/.ngcp-api" -TOOLS="/usr/bin/ngcp-api-tools" -test -f "$TOOLS" && . "$TOOLS" +TOOLS="/usr/share/ngcp-panel-tools/ngcp-api.inc" usage () { - cat << EOF + cat << EOF Usage: $0 [OPTIONS] [content-type] sends a put request to NGCP REST API @@ -15,11 +14,17 @@ OPTIONS: -v verbose mode -f read the input info from a file instead of read stdin EOF - exit 1 + exit 1 } -test -z "$APIUSER" && -f "$TOOLS" && importcreds -test -z "$APIUSER" && APIUSER="administrator:administrator" +if [ -z "$APIUSER" ] ; then + if [ -f "$TOOLS" ] ; then + source "$TOOLS" + importcreds + else + APIUSER="administrator:administrator" + fi +fi INPUT="-T -" while getopts "f:hv" OPTION @@ -47,7 +52,9 @@ done shift $(($OPTIND - 1)) URL="$1" -test -z "$URL" && usage; +if [ -z "$URL" ] ; then + usage +fi CTYPE=${2:-application/json} ${CURL} -i ${VERBOSE} -X PUT \