Skip to content
Snippets Groups Projects
Commit a009995f authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '6629-fix-returnvalue-hasParamOption' into 'master'

reverse return code in ph.hasParamoption

See merge request !157
parents 42b157db a9dced74
Branches
No related tags found
1 merge request!157reverse return code in ph.hasParamoption
......@@ -20,11 +20,12 @@
# 2021-06-24 v0.2 <axel.hahn@iml.unibe.ch> check if query cache is enabled as a shared function
# 2023-06-06 v0.3 <axel.hahn@unibe.ch> some shell fixes
# 2023-07-28 v1.0 <axel.hahn@unibe.ch> update help page; fix [client]: command not found
# 2023-08-30 v1.1 <axel.hahn@unibe.ch> reverse return code in ph.hasParamoption to unix like return codes: 0=true; <>0 = false
# ======================================================================
. $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=1.0
export self_APPVERSION=1.1
# --- set HOME
HOME=/etc/icingaclient
......@@ -194,12 +195,12 @@ function _verify_cache(){
# MAIN
# ----------------------------------------------------------------------
bOptInstall=$( ph.hasParamoption "i" "$@")
bOptUninstall=$( ph.hasParamoption "u" "$@")
bOptHelp=$( ph.hasParamoption "h" "$@")
ph.hasParamoption "i" "$@"; bOptInstall=$?
ph.hasParamoption "u" "$@"; bOptUninstall=$?
ph.hasParamoption "h" "$@"; bOptHelp=$?
if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then
showHelp
if [ $bOptHelp -eq 0 -o $# -lt 1 ]; then
echo "showHelp"
exit 0
fi
......@@ -207,7 +208,7 @@ fi
ph.require mysql
# --- install
if [ $bOptInstall -eq 1 -a "$( whoami )" = "root" ]; then
if [ $bOptInstall -eq 0 -a "$( whoami )" = "root" ]; then
if [ -f $cfgfile ]; then
ph.status "SKIP installation. config file already exists: $cfgfile."
ph.exit
......@@ -223,7 +224,7 @@ if [ $bOptInstall -eq 1 -a "$( whoami )" = "root" ]; then
fi
# --- uninstall
if [ $bOptUninstall -eq 1 -a "$( whoami )" = "root" ]; then
if [ $bOptUninstall -eq 0 -a "$( whoami )" = "root" ]; then
HOME=/root
_uninstall
......
......@@ -19,12 +19,13 @@
# 2023-06-09 v0.5 <axel.hahn@unibe.ch> deltaunit can be set as parameter
# 2023-06-13 v0.6 <axel.hahn@unibe.ch> no output on activity; update replication check
# 2023-06-16 v0.7 <axel.hahn@unibe.ch> update help text
# 2023-08-30 v0.8 <axel.hahn@unibe.ch> reverse return code in ph.hasParamoption to unix like return codes: 0=true; <>0 = false
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=0.7
self_APPVERSION=0.8
# --- other vars...
cfgfile=/etc/icingaclient/.psql.conf
......@@ -176,11 +177,11 @@ function renderCounters(){
# MAIN
# ----------------------------------------------------------------------
bOptInstall=$( ph.hasParamoption "i" "$@")
bOptUninstall=$( ph.hasParamoption "u" "$@")
bOptHelp=$( ph.hasParamoption "h" "$@")
ph.hasParamoption "i" "$@"; bOptInstall=$?
ph.hasParamoption "u" "$@"; bOptUninstall=$?
ph.hasParamoption "h" "$@"; bOptHelp=$?
if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then
if [ $bOptHelp -eq 0 -o $# -lt 1 ]; then
_usage
exit 0
fi
......@@ -189,7 +190,7 @@ fi
# ph.require mysql
# --- install
if [ $bOptInstall -eq 1 -a "$( whoami )" = "root" ]; then
if [ $bOptInstall -eq 0 -a "$( whoami )" = "root" ]; then
if [ -f $cfgfile ]; then
ph.status "SKIP installation. config file already exists: $cfgfile."
ph.exit
......@@ -203,7 +204,7 @@ if [ $bOptInstall -eq 1 -a "$( whoami )" = "root" ]; then
fi
# --- uninstall
if [ $bOptUninstall -eq 1 -a "$( whoami )" = "root" ]; then
if [ $bOptUninstall -eq 0 -a "$( whoami )" = "root" ]; then
_uninstall
rm -f $cfgfile
......
......@@ -186,7 +186,7 @@ This will set variable iWarnLimit based on CLI parameter -w [value] ... if it do
### ph.hasParamoption
check if a letter was used as command line option and return as 0 (=no) or 1 (=yes)
check if a letter was used as command line option and return as 0 (=true) or 1 (=false)
Syntax:
......@@ -201,10 +201,12 @@ Parameters:
Example:
Show a help if command line param ``-h`` was given - or no parameter.
```bash
bOptHelp=`ph.hasParamoption "h" "$@"`
ph.hasParamoption "h" "$@" ; bOptHelp=$?
if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then
if [ $bOptHelp -eq 0 -o $# -lt 1 ]; then
_usage
exit 0
fi
......
......@@ -38,6 +38,7 @@
# 2023-05-17 v1.10 <axel.hahn@unibe.ch> ph.getOS searches in os-release first
# 2023-06-22 v1.11 <axel.hahn@unibe.ch> fix ph.toUnit with float values; shell fixes
# 2023-08-24 v1.12 <axel.hahn@unibe.ch> toUnit got 3rd param for count of digits after "."
# 2023-08-30 v1.13 <axel.hahn@unibe.ch> reverse return code in ph.hasParamoption to unix like return codes: 0=true; <>0 = false
# ======================================================================
......@@ -169,13 +170,13 @@ function ph.hasParamoption(){
# echo "DEBUG: testing $_sParam in ${_opt} ..."
case "${_opt}" in
"$_sParam")
echo "1"
return 1
# echo "0"
return 0
;;
esac
done
echo "0"
return 0
# echo "1"
return 1
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment