summaryrefslogtreecommitdiff
path: root/lib/common
blob: 473c8b101bfa32ac2395d8fbf3224d17f0ac7884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash

# Sanity check to make sure that app.sh is installed
APPSH_HOME="`cd $APPSTORE_HOME/../app.sh; pwd`"

if [ ! -d "$APPSH_HOME" ]
then
  echo "app.sh has to be installed at $APPSH_HOME"
  exit 1
fi

PATH=$APPSH_HOME:$PATH

show_help() {
  message=${1-}

  if [[ $message != "" ]]
  then
    echo $message
  fi

  if [ "`declare -f usage_text >/dev/null; echo $?`" = 0 ]
  then
    usage_text
  else
    echo "The command $usage_app does not have any usage info."
  fi
  exit 1
}

usage() {
  message=${1-}

  if [[ $message != "" ]]
  then
    echo $message >&2
  fi

  if [ "`declare -f usage_text >/dev/null; echo $?`" = 0 ]
  then
    usage_text >&2
  fi
  exit 1
}

debug() {
  [[ $echo_debug == no ]] || echo "D: $usage_app: $@" 2>&1
}

info() {
  echo "I: $usage_app: $@" 2>&1
}

fatal() {
  echo "$usage_app: fatal: $@" 2>&1
  exit 1
}

grep_path() {
  local regex="$1"; shift
  local path="$1"; shift

  find `echo $path | tr : " "` -type f -executable 2>/dev/null | (egrep "$regex" || exit 0)
}