diff options
Diffstat (limited to 'wrapper')
-rw-r--r-- | wrapper/rvs.sh | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/wrapper/rvs.sh b/wrapper/rvs.sh index 2e8f4ca..bac92e5 100644 --- a/wrapper/rvs.sh +++ b/wrapper/rvs.sh @@ -18,9 +18,9 @@ ver='0.9' # along with this program; see the file COPYING. # If not, see <http://www.gnu.org/licenses>. -export RVS="$0" #RVS="@rvs@" +export RVS="$0" #RVS="@RVS@" export BINDIR="@BINDIR@" -export TMPDIR="@TMPDIR@" + baseTMPDIR="@TMPDIR@" export LIBDIR="@LIBDIR@" export ETCDIR="@ETCDIR@" @@ -39,8 +39,7 @@ _error() { _repo() { repo=".$name" - pwd=`pwd` - owd="$pwd" # old working directory + owd="`pwd`" # old working directory # [----can ascend-----] && [-haven't found repo-] while [ "$pwd" != "`pwd`" ] && [ ! -e "`pwd`/$repo" ]; do @@ -61,25 +60,34 @@ _repo() { # Modules ############################################################ _runcom() { - command=${$1?"usage: rvs runcom COMMAND"}; shift + usage="usage: $RVS runcom COMMAND" + command=${1?"$usage"}; shift + if [ ! -e "$BINDIR/$command" ]; then _error "cannot find command \`$command" else + mkdir -p "$baseTMPDIR" + export TMPDIR=`mktemp -d --tmpdir="$baseTMPDIR"` + if [ -f "$BINDIR/$command" ]; then exec "$BINDIR/$command" $@ | tee "$TMPDIR/$command" elif [ -d "$BINDIR/$command" ]; then + mkdir -p "$TMPDIR/$command" for file in "$BINDIR/$command"/*; do - id=$(echo $file | sed 's/^[0-9]*-//') - exec "$file" $@ | tee "TMPDIR/$command/$id" + id=`basename "$file" | sed 's/^[0-9]*-//'` + "$file" $@ > "$TMPDIR/$command/$id" done + cat "$TMPDIR/$command/$id" else _error "cannot run \`$command'" fi + rm -rf "$TMPDIR" fi } _nextpriority() { - command=${1?"usage: rvs nextpriority COMMAND"} + usage="usage: $RVS nextpriority COMMAND" + command=${1?"$usage"} for file in "$BINDIR/$command"/*; do echo $file | sed 's/^\([0-9]*\)-.*/\1/' done | sort -n | tail -n1 | xargs expr 1 + @@ -92,7 +100,7 @@ _nextpriority() { _init() { REPO=`_repo 2> /dev/null` if [ -z "$REPO" ]; then - export REPO="`pwd`.$name" + export REPO="`pwd`/.$name" install -d "$REPO" _runcom init else @@ -105,9 +113,10 @@ _init() { ################################################################################ _install() { - file=${1?"usage: $RVS install FILE COMMAND ID [PRIORITY]"} - command=${2?"usage: $RVS install FILE COMMAND ID [PRIORITY]"} - id=${3?"usage: $RVS install FILE COMMAND ID [PRIORITY]"} + usage="usage: $RVS install FILE COMMAND ID [PRIORITY]" + file=${1?"$usage"} + command=${2?"$usage"} + id=${3?"$usage"} priority=${4-"`_nextpriority "$command"`"} install -d "$BINDIR/$command" @@ -115,7 +124,8 @@ _install() { } _uninstall() { - command=${1?"usage: $RVS uninstall COMMAND [ID]"} + usage="usage: $RVS uninstall COMMAND [ID]" + command=${1?"$usage"} id=$2 if [ -z "$id" ]; then @@ -139,6 +149,7 @@ com=$1; # END OPTION HANDLING # case "$com" in '') _error 'no command specified';; + repo) _repo; exit $?;; 'init' ) shift; _init $@; exit $?;; 'install') shift; _install $@; exit $?;; 'uninstall') shift; _uninstall $@; exit $?;; @@ -149,7 +160,7 @@ case "$com" in _runcom $@ exit $? else - _error 'cannot find an existing repository' + exit 1 fi :;; esac |