aboutsummaryrefslogtreecommitdiff
path: root/.app/lib/app-common
diff options
context:
space:
mode:
Diffstat (limited to '.app/lib/app-common')
-rw-r--r--.app/lib/app-common160
1 files changed, 0 insertions, 160 deletions
diff --git a/.app/lib/app-common b/.app/lib/app-common
deleted file mode 100644
index fabdad4..0000000
--- a/.app/lib/app-common
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/bin/bash
-
-assert_is_instance() {
- local usage=$1
- local name=$2
- local instance=$3
- local check_link=$4
-
- if [ -z "$name" ]
- then
- $usage "Missing required option -n."
- fi
-
- if [ -z "$instance" ]
- then
- $usage "Missing required option -i."
- fi
-
- # Use $APPSH_APPS as prefix if it's set
- local x=""
- if [ ! -z "$APPSH_APPS" ]
- then
- x="$APPSH_APPS/"
- fi
-
- if [ ! -d $x$name/$instance ]
- then
- echo "No such instance: $name/$instance." >&2
- exit 1
- fi
-
- if [ "$check_link" != "no" ]
- then
- if [ ! -e $x$name/$instance/current ]
- then
- echo "Missing 'current' link." >&2
- exit 1
- fi
- fi
-}
-
-list_apps() {
- filter_name=$1; shift
- filter_instnace=$1; shift
- 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() {
- name=$1
- 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() {
- name=$1
- instance=$2
-
- if [ ! -d $apps/$name/$instance/versions ]
- then
- return 0
- fi
-
- (
- cd $apps/$name/$instance/versions
- ls -1d *
- )
-}
-
-# 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
-
- 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
- )
-}