summaryrefslogtreecommitdiff
path: root/lib/misc
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2010-09-25 23:37:23 -0300
committerSilvio Rhatto <rhatto@riseup.net>2010-09-25 23:37:23 -0300
commit3346311096bee29b81190ceb377ef5648aee1380 (patch)
tree84f99fb82853416b2e2cd1c3b0f09ae86eff1d8d /lib/misc
parentc36794e899731be16f1045a9ae19878813fd9896 (diff)
downloadhydra-3346311096bee29b81190ceb377ef5648aee1380.tar.gz
hydra-3346311096bee29b81190ceb377ef5648aee1380.tar.bz2
New/renamed actions
Diffstat (limited to 'lib/misc')
-rw-r--r--lib/misc114
1 files changed, 0 insertions, 114 deletions
diff --git a/lib/misc b/lib/misc
deleted file mode 100644
index 5691465..0000000
--- a/lib/misc
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/bin/bash
-
-# Setup main configuration and load preferences
-function hydra_config_load {
- if [ -f "$HOME/.$NAME" ]; then
- echo "Converting legacy configuration scheme..."
- mv $HOME/.$NAME $HOME/.$NAME.tmp
- mkdir $HOME/.$NAME
- mv $HOME/.$NAME.tmp $CONFIG
- fi
-
- if [ ! -e "$CONFIG" ]; then
- echo "Creating $CONFIG..."
- mkdir `dirname $CONFIG`
- touch $CONFIG
- chmod 600 $CONFIG
- echo "# Hydra config file." > $CONFIG
- echo "" >> $CONFIG
- fi
-
- hydra_config_load_preferences
-}
-
-# Load config preferences
-function hydra_config_load_preferences {
- # Load custom keyring preferences
- if [ ! -z "$PREFERENCES" ] && [ -f "$PREFERENCES" ]; then
- source $PREFERENCES
- fi
-}
-
-# Load a parameter from config
-function hydra_config {
- if [ -z "$CONFIG" ]; then
- echo "Your have to set CONFIG variable in the code"
- exit 1
- elif [ -e "$CONFIG" ]; then
- grep -e "^$1=" $CONFIG | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//'
- else
- echo "Config file not found: $CONFIG"
- exit 1
- fi
-}
-
-# Check if there is a given action
-function hydra_has_action {
- if [ -z "$ACTIONS" ]; then
- echo "Your have to set ACTIONS variable in the code"
- exit 1
- fi
-
- if [ -e "$ACTIONS/$1" ]; then
- true
- else
- false
- fi
-}
-
-# Execute an action
-function hydra_exec {
- # Setup
- action="$1"
- basedir="$2"
- shift 2
-
- # Dispatch
- if hydra_has_action $action; then
- $ACTIONS/$action $basedir $*
- fi
-}
-
-# Set needed environment variables and do basic checks.
-function hydra_set_env {
- if [ -z "$1" ]; then
- echo "Error: missing arguments for hydra_set_env"
- exit 1
- fi
-}
-
-# Get a command argument
-function hydra_get_command {
- # Aditional parameters
- COMMAND="$1"
-
- if [ -z "$COMMAND" ]; then
- hydra_action_usage command
- exit 1
- fi
-}
-
-# Run the action usage
-function hydra_action_usage {
- if [ "`type -t "hydra_usage_$BASENAME"`" == "function" ]; then
- # Use custom action usage
- hydra_usage_$BASENAME
- else
- # Default usage
- echo "Usage: hydra|hydractl <command> [arguments]"
- fi
-}
-
-function hydra_dispatch {
- BASEDIR="`hydra_config $KEYRING`"
-
- # Dispatch
- if [ ! -z "$BASEDIR" ]; then
- shift 2
- hydra_exec $ACTION $BASEDIR $*
- exit $?
- else
- echo "No keydir configured for $KEYRING"
- exit 1
- fi
-}