From 30f1fbf2aab8ae6c45907bab2eafdb0e09998c15 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 28 Mar 2010 12:25:08 -0400 Subject: Rework rvs a lot (no longer needs complex C dependency tracker!) Rework ./configure, and how it uses `srcdir'. Probably broke all the other packages. Oh well, everything only half-works right now. --- wrapper/rvs.sh | 138 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 94 insertions(+), 44 deletions(-) (limited to 'wrapper/rvs.sh') diff --git a/wrapper/rvs.sh b/wrapper/rvs.sh index 0001d66..85586ea 100644 --- a/wrapper/rvs.sh +++ b/wrapper/rvs.sh @@ -1,7 +1,7 @@ #!/bin/sh name='@name@' ver='0.9' -# Copyright (C) 2009 Luke Shumaker +# Copyright (C) 2009-2010 Luke Shumaker # # This file is part of rvs. # @@ -14,93 +14,143 @@ ver='0.9' # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with rvs; see the file COPYING. -# If not, write to the Free Software Foundation, -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. +# If not, see . -RVS="$0" #RVS="@rvs@" -libexecdir="@libexecdir@/$name" +export RVS="$0" #RVS="@rvs@" +export BINDIR="@BINDIR@" +export TMPDIR="@TMPDIR@" +export LIBDIR="@LIBDIR@" +export ETCDIR="@ETCDIR@" + +################################################################################ +# Internal use # +################################################################################ + +# General ############################################################ _error() { - echo "$RVS: $1" >> /dev/stderr + echo "$RVS: $@" >> /dev/stderr exit 1 } +# Repository ######################################################### + _repo() { repo=".$name" pwd=`pwd` - owd="$pwd" + 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" } -_init() { - repo=`_repo 2> /dev/null` - if [ -z "$repo" ]; then - repo=".$name" - install -d "$repo" - install -m644 -T $libexecdir/plugins $repo/plugins - while read plugin; do - echo "initializing plugin \`$plugin'" - install -d "$repo/$plugin" - export REPO=.rvs/$plugin - if [ -e "$libexecdir/$plugin/init" ]; then - "$libexecdir/$plugin/init" - fi - done < $repo/plugins +# Modules ############################################################ + +_runcom() { + command=${$1?"usage: rvs runcom COMMAND"}; shift + if [ ! -e "$BINDIR/$command" ]; then + _error "cannot find command \`$command" else - _error "repository already exists at \`$repo'" + if [ -f "$BINDIR/$command" ]; then + exec "$BINDIR/$command" $@ | tee "$TMPDIR/$command" + elif [ -d "$BINDIR/$command" ] + for file in "$BINDIR/$command"/*; do + id=$(echo $file | sed 's/^[0-9]*-//') + exec "$file" $@ | tee "TMPDIR/$command/$id" + done + else + _error "cannot run \`$command'" + fi fi } -_install() { - id=$1 - dir=${2-$id} - name=`echo $id | sed 's/-.*$//'` - if (grep "^$name-" "$libexecdir/plugins" &> /dev/null); then - # an entry for this plugin already exists, though possibly a - # different version - sed -i "s/^$name-.*$/$id/" "$libexecdir/plugins" +_nextpriority() { + command=${1?"usage: rvs nextpriority COMMAND"} + for file in "$BINDIR/$command"/*; do + echo $file | sed 's/^\([0-9]*\)-.*/\1/' + done | sort -n | tail -n1 | xargs expr 1 + +} + +################################################################################ +# Builtin commands # +################################################################################ + +_init() { + REPO=`_repo 2> /dev/null` + if [ -z "$REPO" ]; then + export REPO="`pwd`.$name" + install -d "$REPO" + _runcom init else - echo "$id" >> "$libexecdir/plugins" + _error "repository already exists at \`$REPO'" fi - rm -rf "$libexecdir/$id" - cp -rpT "$dir" "$libexecdir/$id" } +################################################################################ +# Builtin commands -- installing modules # +################################################################################ + +_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]"} + priority=${4-"`_nextpriority "$command"`"} + + install -d "$BINDIR/$command" + install "$file" "$BINDIR/$command/$priority-$id" +} + + _uninstall() { - id=$1 - sed -i "/^$id$/ d" "$libexecdir/plugins" - rm -rf "$libexecdir/$id" + command=${1?"usage: $RVS uninstall COMMAND [ID]"} + id=$2 + + if [ -z "$id" ]; then + # no ID specified + rm "$BINDIR/$command" + else + # ID specified + rm "$BINDIR/$command/*-$id" + if [ -z "$(ls "$BINDIR/$command")" ]; then + rmdir "$BINDIR/$command" + fi + fi } +################################################################################ +# Main # +################################################################################ + # START OPTION HANDLING # com=$1; # END OPTION HANDLING # case "$com" in '') _error 'no command specified';; - # 'repo') _repo; exit $?;; - 'init') _init; exit $?;; + 'init' ) shift; _init $@; exit $?;; 'install') shift; _install $@; exit $?;; 'uninstall') shift; _uninstall $@; exit $?;; - *) REPO=`_repo` + *) + REPO=`_repo` if [ "$?" = '0' ]; then - export RVS libexecdir REPO - "$libexecdir/runcom" $@ < $REPO/plugins + export REPO + _runcom $@ exit $? else - _error "cannot find an existing repository" + _error 'cannot find an existing repository' fi :;; esac -- cgit v1.2.3-54-g00ecf