aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-27 15:00:27 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-27 15:00:27 +0100
commite1daac32c5b7ca0d902c16135d361aa5303f5124 (patch)
tree3ebe514ae823d23b26c96d8d2db9c6b97e191de4 /lib
parent11c930f71db58201994265b71a8f76187f1dbda1 (diff)
downloadapp.sh-e1daac32c5b7ca0d902c16135d361aa5303f5124.tar.gz
app.sh-e1daac32c5b7ca0d902c16135d361aa5303f5124.tar.bz2
app.sh-e1daac32c5b7ca0d902c16135d361aa5303f5124.tar.xz
app.sh-e1daac32c5b7ca0d902c16135d361aa5303f5124.zip
o Creating an initial version of install-file.
Diffstat (limited to 'lib')
-rw-r--r--lib/common75
1 files changed, 51 insertions, 24 deletions
diff --git a/lib/common b/lib/common
index 22c8cd0..8c33209 100644
--- a/lib/common
+++ b/lib/common
@@ -2,13 +2,17 @@
assert_is_app() {
local check_link=yes
+ local version=
- while getopts "C" opt
+ while getopts "Cv:" opt
do
case $opt in
C)
check_link=no
;;
+ v)
+ version=$OPTARG
+ ;;
esac
done
@@ -22,12 +26,24 @@ assert_is_app() {
then
if [ ! -e current ]
then
- echo "Missing 'current' link." >&2
- exit 1
+ fatal "Missing 'current' link." >&2
+ fi
+ fi
+
+ if [[ $version != "" ]]
+ then
+ if [[ ! -d versions/$version ]]
+ then
+ fatal "No such version: $version"
fi
fi
}
+fatal() {
+ echo "$usage_app: fatal: $@" 2>&1
+ exit 1
+}
+
list_apps() {
local filter_name=$1; shift
local filter_instnace=$1; shift
@@ -121,27 +137,33 @@ grep_path() {
# TODO: set ulimit
# TODO: set umask
# TODO: change group newgrp/sg
+# usage: run_app [-v version] [bin to execute]
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"
+ version=
+ while getopts "v:" opt
+ do
+ case $opt in
+ v)
+ version=$OPTARG
+ shift 2
+ OPTIND=1
+ ;;
+ esac
+ done
- local x=""
- if [ ! -z "$APPSH_APPS" ]
- then
- x="$APPSH_APPS/"
- fi
+ local bin=$1; shift
+ local e=`app-cat-conf -f .app/config -n "env\..*" | cut -f 2- -d .`
(
- cd $x$name/$instance
- APPSH_INSTANCE_HOME=`pwd`
- cd current
+ if [[ $version == "" ]]
+ then
+ assert_is_app
+ cd current
+ else
+ assert_is_app -v "$version"
+ cd "versions/$version"
+ fi
- 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="
"
@@ -152,12 +174,7 @@ run_app() {
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
@@ -166,3 +183,13 @@ run_app() {
exit $ret
)
}
+
+#####################################################################
+# Common init
+
+# Add the app-* apps to PATH. They're added last to allow the user to
+# overload their implementations.
+PATH=$PATH:$APPSH_HOME/bin:$APPSH_HOME/libexec
+
+# Save for later
+usage_app=$0