diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-26 23:58:22 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-26 23:58:22 +0100 |
commit | 110ffae47db27a49bbc43f86ba3737bccc1b3085 (patch) | |
tree | d74934b12e2904b8aff5fe87421a6501b8ea5c8e /lib | |
parent | ca27d6f6d9ccc35bf55db3d360d1d464d5e206e7 (diff) | |
download | app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.gz app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.bz2 app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.xz app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.zip |
o Rewriting most of this stuff to make it feel more like git.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common | 168 | ||||
-rw-r--r-- | lib/default-config | 1 |
2 files changed, 169 insertions, 0 deletions
diff --git a/lib/common b/lib/common new file mode 100644 index 0000000..22c8cd0 --- /dev/null +++ b/lib/common @@ -0,0 +1,168 @@ +#!/bin/bash + +assert_is_app() { + local check_link=yes + + while getopts "C" opt + do + case $opt in + C) + check_link=no + ;; + esac + done + + if [ ! -d .app ] + then + echo "This is not an app, missing directory: '.app'" >&2 + exit 1 + fi + + if [[ $check_link == yes ]] + then + if [ ! -e current ] + then + echo "Missing 'current' link." >&2 + exit 1 + fi + fi +} + +list_apps() { + local filter_name=$1; shift + local filter_instnace=$1; shift + local vars="$@" + + sort $apps/.app/var/list | while read line + do + echo $line | (IFS=:; while read name instance version junk + do + if [ -n "$filter_name" -a "$filter_name" != "$name" ] + then + continue + fi + + if [ -n "$filter_instance" -a "$filter_instance" != "$instance" ] + then + continue + fi + + local line="" + IFS=" "; for var in $vars + do + case $var in + name) x=$name;; + instance) x=$instance;; + version) x=$version;; + current_version) x=`find_current_version $name $instance`;; + *) x="";; + esac + + if [ -z "$line" ] + then + line="$line$x" + else + line="$line:$x" + fi + done + echo $line + done) + done +} + +find_current_version() { + local name=$1 + local instance=$2 + + if [ ! -L $apps/$name/$instance/current ] + then + return 0 + fi + + ( + cd $apps/$name/$instance + ls -l current | sed -n "s,.* current -> versions/\(.*\)/root,\1,p" + ) +} + +find_versions() { + local name="$1" + local instance="$2" + + if [ ! -d $apps/$name/$instance/versions ] + then + return 0 + fi + + ( + cd $apps/$name/$instance/versions + ls -1d * + ) +} + +grep_path() { + local regex="$1"; shift + local path="$1"; shift + + find `echo $path | tr : " "` -type f -executable 2>/dev/null | (egrep "$regex" || exit 0) +# IFS=: +# for x in $path +# do +# ls $x/* 2>/dev/null | while read f +# do +# if [[ $f =~ $regex ]] +# then +# echo $f +# fi +# done +# done +} + +# TODO: set ulimit +# TODO: set umask +# TODO: change group newgrp/sg +run_app() { + local name=$1; shift + local instance=$1; shift + local bin=$1; shift + local method=$1; shift + + assert_is_instance operate_usage "$name" "$instance" + + local x="" + if [ ! -z "$APPSH_APPS" ] + then + x="$APPSH_APPS/" + fi + + ( + cd $x$name/$instance + APPSH_INSTANCE_HOME=`pwd` + cd current + + local e=`$APPSH_HOME/bin/app-cat-conf -f $apps/$name/$instance/current/etc/app.conf -g env | cut -f 2- -d .` + #e="`get_conf_in_group $apps $name $instance env`" + # This magically get the expansion of $u correct. + IFS=" +" + + # Set a default PATH which can be overridden by the application's settings + set +e + env -i \ + PATH=/bin:/usr/bin \ + $e \ + PWD="$PWD" \ + APPSH_METHOD=$method \ + APPSH_APPS=$apps \ + APPSH_HOME=$APPSH_HOME \ + APPSH_NAME=$name \ + APPSH_INSTANCE=$instance \ + APPSH_INSTANCE_HOME=$APPSH_INSTANCE_HOME \ + $bin "$@" + local ret=$? + set +x + set -e + + exit $ret + ) +} diff --git a/lib/default-config b/lib/default-config new file mode 100644 index 0000000..855cc8b --- /dev/null +++ b/lib/default-config @@ -0,0 +1 @@ +maven.repo=http://repo1.maven.org |