summaryrefslogtreecommitdiff
path: root/utils.sh
diff options
context:
space:
mode:
Diffstat (limited to 'utils.sh')
-rwxr-xr-xutils.sh79
1 files changed, 58 insertions, 21 deletions
diff --git a/utils.sh b/utils.sh
index 880028c..8a41433 100755
--- a/utils.sh
+++ b/utils.sh
@@ -1,41 +1,78 @@
#!/bin/sh
+# Shell library for service installation and general tools
+# Author: Christoph Helma, Andreas Maunz
+
+# Functions to install ruby and install services with bundler.
+# Ensures presence of ~/.opentox (CONFIG) and OT_PREFIX.
+
check_dest()
{
- if ! [ -d "$OT_PREFIX" ]; then
- if ! mkdir -p "$OT_PREFIX"; then
- echo "Could not create target directory '$OT_PREFIX'! Aborting..."
- exit 1
- fi
+ [ -d "$OT_PREFIX/tmp" ] || mkdir -p "$OT_PREFIX/tmp"
+ if ! [ -d "$OT_PREFIX/tmp" ]; then
+ echo "Could not create OT_PREFIX directory! Aborting..."
+ exit 1
+ fi
+ [ -d "$HOME/.opentox/log" ] || mkdir -p "$HOME/.opentox/log"
+ if ! [ -d "$HOME/.opentox/log" ]; then
+ echo "Could not create CONFIG (~/.opentox) directory! Aborting..."
+ exit 1
fi
}
run_cmd ()
{
- local cmd="$1"
- local title="$2"
-
- printf "%30s" "'$title'"
+ local cmd="$1"; local title="$2"
+ printf "%50s" "$title"
if ! eval $cmd >>$LOG 2>&1 ; then
- printf "%50s\n" "FAIL"
+ printf " [ \033[31m%s\033[m ]\n" "FAIL"
echo "Last 10 lines of log:"
tail -10 "$LOG"
exit 1
fi
- printf "%50s\n" "DONE"
+ printf " [ \033[32m%s\033[m ]\n" "OK"
+}
+
+check_utils() {
+ for u in $1; do
+ eval `echo $u | tr "[:lower:]" "[:upper:]" | tr "-" "_"`=`which $u` || (echo "'$u' missing. Install '$u' first." 1>&2 && exit 1)
+ done
}
-abs_path()
-{
- local path="$1"
- case "$path" in
- /*) absolute=1 ;;
- *) absolute=0 ;;
- esac
+
+install_ruby() {
+ printf "\n%50s\n" "RUBY"
+ local DIR=`pwd`
+ check_utils "rbenv curl make"
+ if ! $RBENV versions $RUBY_NUM_VER | grep $RUBY_NUM_VER>/dev/null 2>&1; then
+ [ -d $DIR/tmp ] || mkdir -p $DIR/tmp && cd $DIR/tmp
+ ([ -d $DIR/tmp/ruby-$RUBY_NUM_VER ] || $CURL $RUBY_DWL/ruby-$RUBY_NUM_VER.tar.gz 2>/dev/null | tar xz) && cd ruby-$RUBY_NUM_VER
+ cmd="./configure --prefix=$RUBY_DIR" && run_cmd "$cmd" "Configure"
+ cmd="$MAKE -j2" && run_cmd "$cmd" "Make"
+ cmd="$MAKE install" && run_cmd "$cmd" "Install"
+ fi
+ cd $DIR
+ cmd="$RBENV rehash" && run_cmd "$cmd" "Rbenv rehash"
+ cmd="$RBENV local $RUBY_NUM_VER" && run_cmd "$cmd" "Rbenv set ruby"
}
-. "`pwd`/config.sh"
-touch "$OT_UI_CONF"
-. "$OT_UI_CONF"
+
+install_with_bundler() {
+ printf "\n%50s\n" "INSTALL"
+ check_utils "gem rbenv"
+ $GEM list | grep bundler >/dev/null 2>&1 || (cmd="$GEM install bundler" && run_cmd "$cmd" "Install bundler")
+ cmd="$RBENV rehash" && run_cmd "$cmd" "Rbenv rehash"
+ cmd="bundle install" && run_cmd "$cmd" "Install using bundler"
+}
+
+
+if [ -z "$OT_PREFIX" ]; then
+ . ./config.sh
+else
+ . $HOME/.opentox/config/install/config.sh
+fi
check_dest
+touch "$OT_UI_CONF"
+. "$OT_UI_CONF" 2>/dev/null
+