From 3346311096bee29b81190ceb377ef5648aee1380 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 25 Sep 2010 23:37:23 -0300 Subject: New/renamed actions --- hydra | 2 +- lib/functions | 10 ---- lib/git | 33 -------------- lib/hydra/functions | 10 ++++ lib/hydra/git | 33 ++++++++++++++ lib/hydra/misc | 114 ++++++++++++++++++++++++++++++++++++++++++++++ lib/hydra/tmpfile | 45 ++++++++++++++++++ lib/misc | 114 ---------------------------------------------- lib/tmpfile | 45 ------------------ share/hydra/deploy | 1 + share/hydra/nodes | 4 ++ share/hydractl/install | 4 -- share/hydractl/ms-mailkey | 2 + share/hydractl/provision | 4 ++ 14 files changed, 214 insertions(+), 207 deletions(-) delete mode 100644 lib/functions delete mode 100644 lib/git create mode 100644 lib/hydra/functions create mode 100644 lib/hydra/git create mode 100644 lib/hydra/misc create mode 100644 lib/hydra/tmpfile delete mode 100644 lib/misc delete mode 100644 lib/tmpfile create mode 100755 share/hydra/deploy create mode 100755 share/hydra/nodes delete mode 100755 share/hydractl/install create mode 100755 share/hydractl/ms-mailkey create mode 100755 share/hydractl/provision diff --git a/hydra b/hydra index 489c412..a747830 100755 --- a/hydra +++ b/hydra @@ -46,7 +46,7 @@ function hydra_load { fi export ACTIONS="$APP_BASE/share/$BASENAME" - source $APP_BASE/lib/functions || exit 1 + source $APP_BASE/lib/hydra/functions || exit 1 } # Command-line parameters diff --git a/lib/functions b/lib/functions deleted file mode 100644 index 473ea9e..0000000 --- a/lib/functions +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# -# Common functions. -# - -# Setup environment -hydra_set_env $* -source $APP_BASE/lib/git -source $APP_BASE/lib/misc -source $APP_BASE/lib/tmpfile diff --git a/lib/git b/lib/git deleted file mode 100644 index 6e7f05a..0000000 --- a/lib/git +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# Add a pattern into gitignore -function hydra_git_ignore { - if [ ! -z "$BASEDIR/.gitignore" ]; then - echo $1 > $BASEDIR/.gitignore - hydra_exec git $BASEDIR add .gitignore - else - if ! grep -q -e "^$1$" $BASEDIR/.gitignore; then - echo $1 >> $BASEDIR/.gitignore - fi - fi -} - -# Check if a folder is inside a git repository -function hydra_is_git { - if [ -z "$1" ]; then - false - elif [ ! -d "$1" ]; then - false - elif [ -d "$1/.git" ]; then - true - else - cwd="`pwd`" - cd $1 && git="`git status &> /dev/null`" && cd $cwd - - if [ "$git" != "128" ]; then - true - else - false - fi - fi -} diff --git a/lib/hydra/functions b/lib/hydra/functions new file mode 100644 index 0000000..ad5861e --- /dev/null +++ b/lib/hydra/functions @@ -0,0 +1,10 @@ +#!/bin/bash +# +# Common functions. +# + +# Setup environment +hydra_set_env $* +source $APP_BASE/lib/hydra/git +source $APP_BASE/lib/hydra/misc +source $APP_BASE/lib/hydra/tmpfile diff --git a/lib/hydra/git b/lib/hydra/git new file mode 100644 index 0000000..6e7f05a --- /dev/null +++ b/lib/hydra/git @@ -0,0 +1,33 @@ +#!/bin/bash + +# Add a pattern into gitignore +function hydra_git_ignore { + if [ ! -z "$BASEDIR/.gitignore" ]; then + echo $1 > $BASEDIR/.gitignore + hydra_exec git $BASEDIR add .gitignore + else + if ! grep -q -e "^$1$" $BASEDIR/.gitignore; then + echo $1 >> $BASEDIR/.gitignore + fi + fi +} + +# Check if a folder is inside a git repository +function hydra_is_git { + if [ -z "$1" ]; then + false + elif [ ! -d "$1" ]; then + false + elif [ -d "$1/.git" ]; then + true + else + cwd="`pwd`" + cd $1 && git="`git status &> /dev/null`" && cd $cwd + + if [ "$git" != "128" ]; then + true + else + false + fi + fi +} diff --git a/lib/hydra/misc b/lib/hydra/misc new file mode 100644 index 0000000..5691465 --- /dev/null +++ b/lib/hydra/misc @@ -0,0 +1,114 @@ +#!/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 [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 +} diff --git a/lib/hydra/tmpfile b/lib/hydra/tmpfile new file mode 100644 index 0000000..886d61c --- /dev/null +++ b/lib/hydra/tmpfile @@ -0,0 +1,45 @@ +#!/bin/bash + +# Setup a temporary file +function hydra_set_tmpfile { + if [ -z "$BASEDIR" ]; then + echo "Please set BASEDIR before creating a tmp file" + exit 1 + fi + + if [ -z "$1" ]; then + template="$BASEDIR/tmp/hydra.XXXXXXXXXX" + else + template="$BASEDIR/tmp/$1.XXXXXXXXXX" + fi + + mkdir -p $BASEDIR/tmp + hydra_git_ignore 'tmp/*' + + if [ "$2" == "-d" ]; then + TMPWORK="`mktemp -d $template`" + else + TMPWORK="`mktemp $template`" + fi + + if [ "$?" != "0" ]; then + echo "Error: can't set TMPWORK $TMPWORK" + exit 1 + fi + + trap "hydra_unset_tmpfile $TMPWORK; exit" INT TERM EXIT +} + +# Remove a temporary file +function hydra_unset_tmpfile { + if [ -z "$1" ]; then + echo "No tmp file set" + fi + + rm -f $1 + + if [ "$?" != "0" ]; then + echo "Warning: could not delete file $1. Please delete it manually as it might have sensitive information." + exit 1 + fi +} 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 [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 -} diff --git a/lib/tmpfile b/lib/tmpfile deleted file mode 100644 index 886d61c..0000000 --- a/lib/tmpfile +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# Setup a temporary file -function hydra_set_tmpfile { - if [ -z "$BASEDIR" ]; then - echo "Please set BASEDIR before creating a tmp file" - exit 1 - fi - - if [ -z "$1" ]; then - template="$BASEDIR/tmp/hydra.XXXXXXXXXX" - else - template="$BASEDIR/tmp/$1.XXXXXXXXXX" - fi - - mkdir -p $BASEDIR/tmp - hydra_git_ignore 'tmp/*' - - if [ "$2" == "-d" ]; then - TMPWORK="`mktemp -d $template`" - else - TMPWORK="`mktemp $template`" - fi - - if [ "$?" != "0" ]; then - echo "Error: can't set TMPWORK $TMPWORK" - exit 1 - fi - - trap "hydra_unset_tmpfile $TMPWORK; exit" INT TERM EXIT -} - -# Remove a temporary file -function hydra_unset_tmpfile { - if [ -z "$1" ]; then - echo "No tmp file set" - fi - - rm -f $1 - - if [ "$?" != "0" ]; then - echo "Warning: could not delete file $1. Please delete it manually as it might have sensitive information." - exit 1 - fi -} diff --git a/share/hydra/deploy b/share/hydra/deploy new file mode 100755 index 0000000..a9bf588 --- /dev/null +++ b/share/hydra/deploy @@ -0,0 +1 @@ +#!/bin/bash diff --git a/share/hydra/nodes b/share/hydra/nodes new file mode 100755 index 0000000..93593e1 --- /dev/null +++ b/share/hydra/nodes @@ -0,0 +1,4 @@ +#!/bin/bash +# +# Node tool. +# diff --git a/share/hydractl/install b/share/hydractl/install deleted file mode 100755 index 488c2ea..0000000 --- a/share/hydractl/install +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# -# System installer. -# diff --git a/share/hydractl/ms-mailkey b/share/hydractl/ms-mailkey new file mode 100755 index 0000000..f4abb6e --- /dev/null +++ b/share/hydractl/ms-mailkey @@ -0,0 +1,2 @@ +#!/bin/bash +# Email monkeysphere key diff --git a/share/hydractl/provision b/share/hydractl/provision new file mode 100755 index 0000000..488c2ea --- /dev/null +++ b/share/hydractl/provision @@ -0,0 +1,4 @@ +#!/bin/bash +# +# System installer. +# -- cgit v1.2.3