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
|
#!/bin/bash
# {{{ Copyright
# A shell version of the clc-send-command program.
# Copyright (C) 2003 The Free Software Foundation
#
# This program 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 of the License, or
# (at your option) any later version.
#
# This program 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; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
# Authors: Matthew Kennedy <mkennedy@gentoo.org>
# }}}
# {{{ Commentary...
# Traditionally, the controller consisted of two programs:
# clc-send-command and clc-build-daemon, The former invokes the later
# via an Internet super-server such as inetd and xinetd.
#
# Why the contoller requires a Internet super-sever is beyond my
# comprehension, hence this program.
#
# This program works exactly like the original clc-send-command
# program, however it bypasses clc-build-daemon to call the controller
# implementation scripts (/usr/lib/common-lisp/bin/*.sh) directly.
# }}}
# {{{ Utility functions
function error {
echo "Error: $1"
exit 255
}
function warning {
echo "Warning: $1"
exit 0
}
function is_valid_impl {
local impl=$1
for i in /usr/lib/common-lisp/bin/*.sh; do
i=$(basename ${i} .sh)
if [ "x${i}" == "x${impl}" ]; then
return 0
fi
done
return 1
}
function is_valid_package {
local impl=$1 package=$2
test -d /usr/lib/common-lisp/${impl}/${package}
}
function su-maybe {
if [ "x`whoami`" == "xroot" ]; then
su - cl-builder -c "$@"
else
$@
fi
}
function remove_package {
local impl=$1 package=$2
# su - cl-builder -c "/usr/lib/common-lisp/bin/${impl}.sh remove ${package}"
su-maybe "/usr/lib/common-lisp/bin/${impl}.sh remove ${package}"
}
function recompile_package {
local impl=$1 package=$2
su - cl-builder -c "/usr/lib/common-lisp/bin/${impl}.sh rebuild ${package}"
}
# }}}
declare -a ARGS
i=0; while [ ! -z "$1" ]; do
# collect the arguments we're interested in, discard all else
case $1 in
-d | --debug | -q | --quiet | -v | --verbose)
# ignore these for now
;;
-? | --help | --usage)
cat <<EOF
clc-send-command [OPTION...] recompile <package> <implementation>
clc-send-command [OPTION...] remove <package> <implementation>
EOF
exit 1
;;
--verbose | -V)
# mimic the original clc-send-command program's output
echo 'version 1.0 for clc v3'
exit 1
;;
*)
ARGS[$i]=$1 i=$[$i + 1]
;;
esac
shift
done
if [ ${#ARGS[*]} -ne 3 ]; then
error 'Invalid number of arguments.'
fi
command=${ARGS[0]} package=${ARGS[1]} impl=${ARGS[2]}
is_valid_impl ${impl} \
|| error "Invalid implementaion: ${impl}"
case ${command} in
remove)
is_valid_package ${impl} ${package} \
|| warning "Package ${package} for implementation ${impl} does not exist or has not been compiled yet."
remove_package ${impl} ${package} \
|| error "Cannot remove package: ${package} for implementation: ${impl}"
;;
recompile)
recompile_package ${impl} ${package} \
|| error "Cannot recompile package: ${package} for implementation: ${impl}"
;;
*)
error "Unrecognized command: ${command}"
;;
esac
exit 0
# Local Variables: ***
# mode: shell-script ***
# indent-tabs-mode: nil ***
# End: ***
|