aboutsummaryrefslogtreecommitdiff
path: root/hydra
blob: 51c146884ad3488e02de9dbadca264395e28e497 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# Hydra Management Tool.
#
# Copyright (C) 2010 Sarava Group - sarava at lists.riseup.net
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Load libraries
function hydra_load {
  local dest
  local base

  # Determine if we are in a local or system-wide install.
  if [ -h "$0" ]; then
    dest="$(readlink $0)"

    # Check again as the caller might be a symlink as well
    if [ -h "$dest" ]; then
      base="`dirname $dest`"
      dest="$(dirname $(readlink $dest))"
    else
      base="`dirname $0`"
      dest="`dirname $dest`"
    fi

    # Deal with relative or absolute links
    if [ "`basename $dest`" == "$dest" ]; then
      export APP_BASE="$base"
    else
      export APP_BASE="$dest"
    fi
  else
    export APP_BASE="`dirname $0`"
  fi

  export ACTIONS="$APP_BASE/share/$BASENAME"
  source $APP_BASE/lib/hydra/functions || exit 1
}

# Name and basename configuration
BASENAME="`basename $0`"
export NAME="$BASENAME"

# Adjust hydra parameter
if [ "$BASENAME" == "hydra" ]; then
  export HYDRA="$1"
  export ACTION="$2"
  shift
else
  export ACTION="$1"
fi

# Load
hydra_load $*

# Command-line parser
if [ -z "$ACTION" ]; then
  hydra_action_usage
  exit 1
fi

# Dispatch
if hydra_has_action $ACTION; then
  hydra_dispatch $*
else
  echo "No such action $ACTION"
  exit 1
fi