aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-xhydra76
l---------[-rwxr-xr-x]hydractl51
-rw-r--r--lib/functions10
-rw-r--r--lib/git33
-rw-r--r--lib/misc114
-rw-r--r--lib/tmpfile45
-rwxr-xr-xshare/hydra/init12
-rwxr-xr-xshare/hydra/register3
-rwxr-xr-xshare/hydractl/backports7
-rwxr-xr-xshare/hydractl/install-puppet5
-rwxr-xr-xshare/hydractl/puppet-reset5
-rwxr-xr-xshare/hydractl/puppet-reset-stored2
-rwxr-xr-xshare/hydractl/puppet-trigger3
-rwxr-xr-xshare/hydractl/requirements2
-rwxr-xr-xshare/hydractl/upgrade3
16 files changed, 285 insertions, 87 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1377554
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.swp
diff --git a/hydra b/hydra
index 46a2e5b..489c412 100755
--- a/hydra
+++ b/hydra
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Hydra Process Command Tool.
+# Hydra Management Tool.
#
# Copyright (C) 2010 Sarava Group - sarava at lists.riseup.net
#
@@ -18,52 +18,54 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-# TODO: get all needed requirements
-function hydra_requirements {
-}
-
-# TODO: check debian version and if backports is enabled
-# TODO: check backports key signature
-function hydra_backports {
- echo "deb http://www.backports.org/debian lenny-backports main contrib non-free" >> /etc/apt/sources.list
- apt-get update ; apt-get install debian-backports-keyring ; apt-get update
- apt-get -t lenny-backports install puppet puppetmaster
-}
-
-function hydra_install_puppet {
- apt-get update
- # TODO: use option '-t lenny-backports' if installing from backports
- apt-get install puppet puppetmaster
-}
+# Load libraries
+function hydra_load {
+ local dest
+ local base
-# Initializes a new hydra from scratch
-function hydra_init {
- hydra_backports
- hydra_install_puppet
+ # Determine if we are in a local or system-wide install.
+ if [ -h "$0" ]; then
+ dest="$(readlink $0)"
- mkdir -p /etc/puppet/modules
- git clone git://git.sarava.org/puppet-bootstrap /etc/puppet/modules/bootstrap
+ # 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`"
+ fi
- # TODO: edit /etc/puppet/modules/bootstrap/manifests/site.pp to suit your needs.
+ # Deal with relative or absolute link
+ if [ "`basename $dest`" == "$dest" ]; then
+ export APP_BASE="$base"
+ else
+ export APP_BASE="$dest"
+ fi
+ else
+ export APP_BASE="`dirname $0`"
+ fi
- puppetd --no-daemonize --debug --verbose --onetime /etc/puppet/modules/bootstrap/manifests/init.pp
- puppetd --no-daemonize --debug --verbose
-}
-
-# Register an existing hydra
-function hydra_register {
- # TODO
+ export ACTIONS="$APP_BASE/share/$BASENAME"
+ source $APP_BASE/lib/functions || exit 1
}
# Command-line parameters
-COMMAND="$1"
BASENAME="`basename $0`"
+ACTION="$1"
# Command-line parser
-if [ -z "$COMMAND" ]; then
- echo "usage: $BASENAME <comman> [arguments]"
+if [ -z "$ACTION" ]; then
+ echo "usage: $BASENAME <command> [arguments]"
+ exit 1
fi
+# Load functions
+hydra_load $*
+
# Dispatch
-hydra_requirements
-hydra_$COMMAND
+if hydra_has_action $ACTION; then
+ hydra_dispatch $*
+else
+ echo "No such action $ACTION"
+ exit 1
+fi
diff --git a/hydractl b/hydractl
index 2e2fa25..29084b0 100755..120000
--- a/hydractl
+++ b/hydractl
@@ -1,50 +1 @@
-#!/bin/bash
-#
-# Hydra Process Control 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/>.
-#
-
-function hydractl_requirements {
- # TODO
-}
-
-function hydractl_reset_puppetd {
- /etc/init.d/puppet stop
- rm -rf /var/lib/puppet/ssl
- puppetd --server puppet.`facter domain` --waitforcert 60 --test --ca_port 8141
-}
-
-function hydractl_upgrade {
- aptitude safe-upgrade -y
-}
-
-function hydractl_puppet_trigger {
- kill -USR1 `cat /var/run/puppet/puppetd.pid`
-}
-
-# Command-line parameters
-COMMAND="$1"
-BASENAME="`basename $0`"
-
-# Command-line parser
-if [ -z "$COMMAND" ]; then
- echo "usage: $BASENAME <comman> [arguments]"
-fi
-
-# Dispatch
-hydractl_requirements
-hydractl_$COMMAND
+hydra \ No newline at end of file
diff --git a/lib/functions b/lib/functions
new file mode 100644
index 0000000..473ea9e
--- /dev/null
+++ b/lib/functions
@@ -0,0 +1,10 @@
+#!/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
new file mode 100644
index 0000000..6e7f05a
--- /dev/null
+++ b/lib/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/misc b/lib/misc
new file mode 100644
index 0000000..5691465
--- /dev/null
+++ b/lib/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 <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
+}
diff --git a/lib/tmpfile b/lib/tmpfile
new file mode 100644
index 0000000..886d61c
--- /dev/null
+++ b/lib/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/share/hydra/init b/share/hydra/init
new file mode 100755
index 0000000..f1b4afe
--- /dev/null
+++ b/share/hydra/init
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+hydra backports
+hydra install_puppet
+
+mkdir -p /etc/puppet/modules
+git clone git://git.sarava.org/puppet-bootstrap /etc/puppet/modules/bootstrap
+
+# TODO: edit /etc/puppet/modules/bootstrap/manifests/site.pp to suit your needs.
+
+puppetd --no-daemonize --debug --verbose --onetime /etc/puppet/modules/bootstrap/manifests/init.pp
+puppetd --no-daemonize --debug --verbose
diff --git a/share/hydra/register b/share/hydra/register
new file mode 100755
index 0000000..5364f58
--- /dev/null
+++ b/share/hydra/register
@@ -0,0 +1,3 @@
+#!/bin/bash
+# Register an existing hydra
+# TODO
diff --git a/share/hydractl/backports b/share/hydractl/backports
new file mode 100755
index 0000000..dbf9ec1
--- /dev/null
+++ b/share/hydractl/backports
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# TODO: check debian version and if backports is enabled
+# TODO: check backports key signature
+echo "deb http://www.backports.org/debian lenny-backports main contrib non-free" >> /etc/apt/sources.list
+apt-get update ; apt-get install debian-backports-keyring ; apt-get update
+apt-get -t lenny-backports install puppet puppetmaster
diff --git a/share/hydractl/install-puppet b/share/hydractl/install-puppet
new file mode 100755
index 0000000..11a0048
--- /dev/null
+++ b/share/hydractl/install-puppet
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+apt-get update
+# TODO: use option '-t lenny-backports' if installing from backports
+apt-get install puppet puppetmaster
diff --git a/share/hydractl/puppet-reset b/share/hydractl/puppet-reset
new file mode 100755
index 0000000..04d02b1
--- /dev/null
+++ b/share/hydractl/puppet-reset
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+/etc/init.d/puppet stop
+rm -rf /var/lib/puppet/ssl
+puppetd --server puppet.`facter domain` --waitforcert 60 --test --ca_port 8141
diff --git a/share/hydractl/puppet-reset-stored b/share/hydractl/puppet-reset-stored
new file mode 100755
index 0000000..000933b
--- /dev/null
+++ b/share/hydractl/puppet-reset-stored
@@ -0,0 +1,2 @@
+#!/bin/bash
+# TODO: reset stored configs
diff --git a/share/hydractl/puppet-trigger b/share/hydractl/puppet-trigger
new file mode 100755
index 0000000..2326d37
--- /dev/null
+++ b/share/hydractl/puppet-trigger
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+kill -USR1 `cat /var/run/puppet/puppetd.pid`
diff --git a/share/hydractl/requirements b/share/hydractl/requirements
new file mode 100755
index 0000000..dc96894
--- /dev/null
+++ b/share/hydractl/requirements
@@ -0,0 +1,2 @@
+#!/bin/bash
+# TODO: get all needed requirements
diff --git a/share/hydractl/upgrade b/share/hydractl/upgrade
new file mode 100755
index 0000000..f129b79
--- /dev/null
+++ b/share/hydractl/upgrade
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+aptitude safe-upgrade -y