summaryrefslogtreecommitdiffstats
path: root/server/lib/ogfunctions.sh
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2018-10-10 11:02:55 +0200
committerRamón M. Gómez <ramongomez@us.es>2018-10-10 11:02:55 +0200
commit115525a55f2665f12fa938c7bdd0ab00123172d7 (patch)
tree8aee9d642495d2ce130a32ec73ef91ccc8effc57 /server/lib/ogfunctions.sh
parent9215580935651b48edc831a2f18adf52da9b3750 (diff)
#850: Script {{{checkrepo}}} creates the repository info file if it doesn't exist and uses a new global functions file.
Diffstat (limited to 'server/lib/ogfunctions.sh')
-rwxr-xr-xserver/lib/ogfunctions.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/server/lib/ogfunctions.sh b/server/lib/ogfunctions.sh
new file mode 100755
index 00000000..51de6b77
--- /dev/null
+++ b/server/lib/ogfunctions.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+#/**
+#@file ogfunctions.sh
+#@brief Generic functions for OpenGnsys Server and OpenGnsys Repository.
+#@version 1.1.1 - Initial version
+#@author Ramón M. Gómez, ETSII Universidad de Sevilla
+#@date 2017-10-08
+#*/
+
+
+# Showing an error message.
+function raiseError() {
+ case "$1" in
+ usage)
+ echo "$PROG: Usage error: Type \"$PROG help\"" >&2
+ exit 1 ;;
+ notfound)
+ echo "$PROG: Resource not found: $2" >&2
+ exit 2 ;;
+ access)
+ echo "$PROG: Access error: $2" >&2
+ exit 3 ;;
+ download)
+ echo "$PROG: Download error: $2" >&2
+ exit 4 ;;
+ *)
+ echo "$PROG: Unknown error" >&2
+ exit 1 ;;
+ esac
+}
+
+# Showing help message.
+function help() {
+ [ -n "$1" ] && DESCRIPTION="$1" || DESCRIPTION=$(grep "^#@brief" "$0" | cut -f2- -d" ")
+ shift
+ if [ -n "$1" ]; then
+ USAGE="$1"
+ shift
+ else
+ USAGE=$(grep "^#@usage" "$0" | cut -f2- -d" ")
+ [ -n "$USAGE" ] && PARAMS=$(awk '$1=="#@param" {sub($1,""); print "\t",$0}' "$0")
+ fi
+ # Showing help.
+ echo "$PROG: ${DESCRIPTION:-"no description"}"
+ echo "Usage: ${USAGE:-"no usage info"}"
+ [ -n "$PARAMS" ] && echo -e "$PARAMS"
+ if [ -n "$*" ]; then
+ echo "Examples:"
+ while (( "$#" )); do
+ echo -e "\t$1"
+ shift
+ done
+ fi
+ exit 0
+}
+
+# Metafunction to check if JSON result exists.
+JQ=$(which jq 2>/dev/null) || raiseError notfound "Need to install \"jq\"."
+function jq() {
+ local OUTPUT
+ OUTPUT=$($JQ "$@") || return $?
+ [[ "$OUTPUT" = "null" ]] && return 1
+ echo "$OUTPUT"
+}
+