blob: 2e8f4ca7b5ade4c3dc1dba23d4925ab5b76a26a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#!/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 <http://www.gnu.org/licenses>.
export RVS="$0" #RVS="@rvs@"
export BINDIR="@BINDIR@"
export TMPDIR="@TMPDIR@"
export LIBDIR="@LIBDIR@"
export ETCDIR="@ETCDIR@"
################################################################################
# Internal use #
################################################################################
# General ############################################################
_error() {
echo "$RVS: $@" >> /dev/stderr
exit 1
}
# Repository #########################################################
_repo() {
repo=".$name"
pwd=`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"
}
# Modules ############################################################
_runcom() {
command=${$1?"usage: rvs runcom COMMAND"}; shift
if [ ! -e "$BINDIR/$command" ]; then
_error "cannot find command \`$command"
else
if [ -f "$BINDIR/$command" ]; then
exec "$BINDIR/$command" $@ | tee "$TMPDIR/$command"
elif [ -d "$BINDIR/$command" ]; then
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
}
_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
_error "repository already exists at \`$REPO'"
fi
}
################################################################################
# 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() {
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';;
'init' ) shift; _init $@; exit $?;;
'install') shift; _install $@; exit $?;;
'uninstall') shift; _uninstall $@; exit $?;;
*)
REPO=`_repo`
if [ "$?" = '0' ]; then
export REPO
_runcom $@
exit $?
else
_error 'cannot find an existing repository'
fi
:;;
esac
# Copy/Paste Virus 1.3c Please copy and paste this text anywhere. Track
# its progress by searching for this MD5#f7eac285ebfe21c4587bfebb9582f90d
|