918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change
on this file since 37481d8 was
115525a,
checked in by Ramón M. Gómez <ramongomez@…>, 7 years ago
|
#850: Script checkrepo creates the repository info file if it doesn't exist and uses a new global functions file.
|
-
Property mode set to
100755
|
File size:
1.7 KB
|
Rev | Line | |
---|
[115525a] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file ogfunctions.sh |
---|
| 4 | #@brief Generic functions for OpenGnsys Server and OpenGnsys Repository. |
---|
| 5 | #@version 1.1.1 - Initial version |
---|
| 6 | #@author Ramón M. Gómez, ETSII Universidad de Sevilla |
---|
| 7 | #@date 2017-10-08 |
---|
| 8 | #*/ |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | # Showing an error message. |
---|
| 12 | function raiseError() { |
---|
| 13 | case "$1" in |
---|
| 14 | usage) |
---|
| 15 | echo "$PROG: Usage error: Type \"$PROG help\"" >&2 |
---|
| 16 | exit 1 ;; |
---|
| 17 | notfound) |
---|
| 18 | echo "$PROG: Resource not found: $2" >&2 |
---|
| 19 | exit 2 ;; |
---|
| 20 | access) |
---|
| 21 | echo "$PROG: Access error: $2" >&2 |
---|
| 22 | exit 3 ;; |
---|
| 23 | download) |
---|
| 24 | echo "$PROG: Download error: $2" >&2 |
---|
| 25 | exit 4 ;; |
---|
| 26 | *) |
---|
| 27 | echo "$PROG: Unknown error" >&2 |
---|
| 28 | exit 1 ;; |
---|
| 29 | esac |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | # Showing help message. |
---|
| 33 | function help() { |
---|
| 34 | [ -n "$1" ] && DESCRIPTION="$1" || DESCRIPTION=$(grep "^#@brief" "$0" | cut -f2- -d" ") |
---|
| 35 | shift |
---|
| 36 | if [ -n "$1" ]; then |
---|
| 37 | USAGE="$1" |
---|
| 38 | shift |
---|
| 39 | else |
---|
| 40 | USAGE=$(grep "^#@usage" "$0" | cut -f2- -d" ") |
---|
| 41 | [ -n "$USAGE" ] && PARAMS=$(awk '$1=="#@param" {sub($1,""); print "\t",$0}' "$0") |
---|
| 42 | fi |
---|
| 43 | # Showing help. |
---|
| 44 | echo "$PROG: ${DESCRIPTION:-"no description"}" |
---|
| 45 | echo "Usage: ${USAGE:-"no usage info"}" |
---|
| 46 | [ -n "$PARAMS" ] && echo -e "$PARAMS" |
---|
| 47 | if [ -n "$*" ]; then |
---|
| 48 | echo "Examples:" |
---|
| 49 | while (( "$#" )); do |
---|
| 50 | echo -e "\t$1" |
---|
| 51 | shift |
---|
| 52 | done |
---|
| 53 | fi |
---|
| 54 | exit 0 |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | # Metafunction to check if JSON result exists. |
---|
| 58 | JQ=$(which jq 2>/dev/null) || raiseError notfound "Need to install \"jq\"." |
---|
| 59 | function jq() { |
---|
| 60 | local OUTPUT |
---|
| 61 | OUTPUT=$($JQ "$@") || return $? |
---|
| 62 | [[ "$OUTPUT" = "null" ]] && return 1 |
---|
| 63 | echo "$OUTPUT" |
---|
| 64 | } |
---|
| 65 | |
---|
Note: See
TracBrowser
for help on using the repository browser.