summaryrefslogtreecommitdiff
path: root/rvs/wrapper/rvs.sh
diff options
context:
space:
mode:
Diffstat (limited to 'rvs/wrapper/rvs.sh')
-rw-r--r--rvs/wrapper/rvs.sh71
1 files changed, 48 insertions, 23 deletions
diff --git a/rvs/wrapper/rvs.sh b/rvs/wrapper/rvs.sh
index bac92e5..e2e94e6 100644
--- a/rvs/wrapper/rvs.sh
+++ b/rvs/wrapper/rvs.sh
@@ -19,7 +19,7 @@ ver='0.9'
# If not, see <http://www.gnu.org/licenses>.
export RVS="$0" #RVS="@RVS@"
-export BINDIR="@BINDIR@"
+ BINDIR="@BINDIR@"
baseTMPDIR="@TMPDIR@"
export LIBDIR="@LIBDIR@"
export ETCDIR="@ETCDIR@"
@@ -31,44 +31,56 @@ export ETCDIR="@ETCDIR@"
# General ############################################################
_error() {
- echo "$RVS: $@" >> /dev/stderr
- exit 1
+ echo "$RVS: $1" >> /dev/stderr
+ exit ${2-1}
}
# Repository #########################################################
_repo() {
- repo=".$name"
- owd="`pwd`" # old working directory
-
- # [----can ascend-----] && [-haven't found repo-]
- while [ "$pwd" != "`pwd`" ] && [ ! -e "`pwd`/$repo" ]; do
- pwd=`pwd`
- cd ..
- done
-
- if [ -e "`pwd`/$repo" ]; then
- # we found a repository
- echo "`pwd`/$repo"
- else
- # we didn't find a repository
- _error "no $name repository found"
+ if [ -z "$REPO" ]; then # we aren't getting a value from then env
+ repo=".$name"
+ owd="`pwd`" # old working directory
+
+ # [----can ascend-----] && [-haven't found repo-]
+ while [ "$pwd" != "`pwd`" ] && [ ! -e "`pwd`/$repo" ]; do
+ pwd=`pwd`
+ cd ..
+ done
+
+ if [ -e "`pwd`/$repo" ]; then
+ # we found a repository
+ echo "`pwd`/$repo"
+ else
+ # we didn't find a repository
+ _error "no $name repository found"
+ fi
+ cd "$owd"
fi
- cd "$owd"
}
# Modules ############################################################
_runcom() {
+ # exit states
+ # 0 - fine
+ # 1 - could not find command
+ # 2 - could not run command
usage="usage: $RVS runcom COMMAND"
command=${1?"$usage"}; shift
if [ ! -e "$BINDIR/$command" ]; then
- _error "cannot find command \`$command"
+ exit 1
else
mkdir -p "$baseTMPDIR"
export TMPDIR=`mktemp -d --tmpdir="$baseTMPDIR"`
+ if [ -z "RVS_LEVEL" ]; then
+ export RVS_LEVEL=0;
+ else
+ export RVS_LEVEL=`expr $RVS_LEVEL + 1`
+ fi
+
if [ -f "$BINDIR/$command" ]; then
exec "$BINDIR/$command" $@ | tee "$TMPDIR/$command"
elif [ -d "$BINDIR/$command" ]; then
@@ -79,7 +91,7 @@ _runcom() {
done
cat "$TMPDIR/$command/$id"
else
- _error "cannot run \`$command'"
+ exit 2
fi
rm -rf "$TMPDIR"
fi
@@ -98,13 +110,22 @@ _nextpriority() {
################################################################################
_init() {
+ # exit states:
+ # 0 - fine
+ # 1 - repo already exists
+ # 2 - error running init commands
REPO=`_repo 2> /dev/null`
if [ -z "$REPO" ]; then
export REPO="`pwd`/.$name"
install -d "$REPO"
_runcom init
+ case "$?" in
+ 0) exit 0;;
+ 1) exit 0;;
+ 2) _error 'error running init scripts' 2;;
+ esac
else
- _error "repository already exists at \`$REPO'"
+ _error "repository already exists at \`$REPO'" 1
fi
}
@@ -158,7 +179,11 @@ case "$com" in
if [ "$?" = '0' ]; then
export REPO
_runcom $@
- exit $?
+ case "$?" in
+ 0) exit 0;;
+ 1) _error "could not find command \`$1'" 1;;
+ 2) _error "could not run command \`$1'" 2;;
+ esac
else
exit 1
fi