#!/bin/sh name='@name@' ver='0.9' # Copyright (C) 2009-2010 Luke Shumaker # # This file is part of rvs. # # rvs is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 2, or (at your option) any later version. # # rvs is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # 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 this program; see the file COPYING. # If not, see . export RVS="$0" #RVS="@RVS@" BINDIR="@BINDIR@" baseTMPDIR="@TMPDIR@" export LIBDIR="@LIBDIR@" export ETCDIR="@ETCDIR@" ################################################################################ # Internal use # ################################################################################ # General ############################################################ _error() { echo "$RVS: $1" >> /dev/stderr exit ${2-1} } # Repository ######################################################### _repo() { 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 } # 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 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 mkdir -p "$TMPDIR/$command" for file in "$BINDIR/$command"/*; do id=`basename "$file" | sed 's/^[0-9]*-//'` "$file" $@ > "$TMPDIR/$command/$id" done cat "$TMPDIR/$command/$id" else exit 2 fi rm -rf "$TMPDIR" fi } _nextpriority() { 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 + } ################################################################################ # Builtin commands # ################################################################################ _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'" 1 fi } ################################################################################ # Builtin commands -- installing modules # ################################################################################ _install() { 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" install "$file" "$BINDIR/$command/$priority-$id" } _uninstall() { usage="usage: $RVS uninstall COMMAND [ID]" command=${1?"$usage"} 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' ) shift; _init $@; exit $?;; 'install') shift; _install $@; exit $?;; 'uninstall') shift; _uninstall $@; exit $?;; *) REPO=`_repo` if [ "$?" = '0' ]; then export REPO _runcom $@ 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 :;; esac # Copy/Paste Virus 1.3c Please copy and paste this text anywhere. Track # its progress by searching for this MD5#f7eac285ebfe21c4587bfebb9582f90d