This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dev-env.sh
297 lines (264 loc) · 7.74 KB
/
dev-env.sh
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/bin/bash
# Beah - Test harness. Part of Beaker project.
#
# Copyright (C) 2009 Red Hat, Inc.
#
# 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
if [[ "$0" == "dev-env.sh" ]]; then
echo "*** This script should be sourced \". $0\" not executed." >&2
exit 1
fi
BEAH_FUNCTIONS=
BEAH_PRIVATE=
function file_path()
(
[[ -n "$2" ]] && cd "$2"
local path="$(dirname "$1")"
[[ -n "$path" ]] && cd $path &>/dev/null
echo $PWD
)
function script_path()
{
file_path "${BASH_SOURCE[0]}"
}
################################################################################
# SETUP:
################################################################################
export BEAH_DIR="$(script_path)"
export PATH=$PATH:$BEAH_DIR/bin:$BEAH_DIR/beah/bin
export PYTHONPATH=$PYTHONPATH:$BEAH_DIR
# Path to search for config files:
export BEAH_ROOT=$BEAH_DIR
# If present use developmental .tmp conf files (``.tmp'' is used to match
# .gitignore)
if [[ -f $BEAH_DIR/beah.conf.tmp ]]; then
export BEAH_CONF=$BEAH_DIR/beah.conf.tmp
fi
if [[ -f $BEAH_DIR/beah_beaker.conf.tmp ]]; then
export BEAH_BEAKER_CONF=$BEAH_DIR/beah_beaker.conf.tmp
fi
################################################################################
# FUNCTIONS:
################################################################################
function beah() { python -c "from beah.bin.cli import main; main()" "$@"; }
function beahsh() { python -c "from beah.tools.beahsh import main; main()" "$@"; }
function beah-srv() { python -c "from beah.bin.srv import main; main()" "$@"; }
function beah-out-backend() { python -c "from beah.bin.out_backend import main; main()" "$@"; }
function beah-cmd-backend() { python -c "from beah.bin.cmd_backend import main; main()" "$@"; }
function beah-fakelc() { python -c "from beah.tools.fakelc import main; main()" "$@"; }
function beah-beaker-backend() { python -c "from beah.backends.beakerlc import main; main()" "$@"; }
function beah-fwd-backend() { python -c "from beah.backends.forwarder import main; main()" "$@"; }
function beah-rhts-task() { python -c "from beah.tasks.rhts_xmlrpc import main; main()" "$@"; }
function beah-root() { python -c "from beah import tools; tools.main_root()" "$@"; }
function beah-data-root() { python -c "from beah import tools; tools.main_data_root()" "$@"; }
function beah-data-file() { python -c "from beah import tools; tools.main_data_file()" "$@"; }
function beah-data-dir() { python -c "from beah import tools; tools.main_data_dir()" "$@"; }
function json-env() { python -c "from beah.bin.jsonenv import main; main()"; "$@"; }
BEAH_FUNCTIONS="$BEAH_FUNCTIONS beah $(echo beah-{srv,{out,cmd,beaker,fwd}-backend,fakelc,root,data-{root,file,dir}}) json-env"
function inst1() { if [[ ! -z "$LABM1" ]]; then inst_all -m $LABM1; fi }
function inst2() { if [[ ! -z "$LABM2" ]]; then inst_all -m $LABM2; fi }
function inst3() { if [[ ! -z "$LABM3" ]]; then inst_all -m $LABM3; fi }
function inst4() { if [[ ! -z "$LABM4" ]]; then inst_all -m $LABM4; fi }
function inst5() { if [[ ! -z "$LABM5" ]]; then inst_all -m $LABM5; fi }
BEAH_PRIVATE="$BEAH_PRIVATE $(echo inst{_all,1,2,3,4,5})"
function _labms()
{
if [[ ! -z "$1" ]]; then
echo -n "$1 "
fi
}
function labms()
{
for i in $*; do
eval "_labms \"\$LABM$i\""
done
echo
}
function lmcall()
{
local lms=
local append=
while [[ ! -z "$1" ]]; do
case "$1" in
-m)
shift
lms="$lms $1"
shift
;;
-a)
shift
append="$append $1"
shift
;;
-n)
shift
append="$append $(labms $1)"
shift
;;
--)
shift
break
;;
-*)
echo "--- ERROR: Unknow option $1" >&2
return 1
;;
*)
break
;;
esac
done
for labm in ${lms:-$LABMS} $append; do
LABM=$labm "$@"
done
}
function xlm()
{
TITLE=$LABM xt
}
function xlm1() { LABM=$LABM1 xlm; }
function xlm2() { LABM=$LABM2 xlm; }
function xlm3() { LABM=$LABM3 xlm; }
function xlm4() { LABM=$LABM4 xlm; }
function xlm5() { LABM=$LABM5 xlm; }
function gxlm()
{
lmcall "$@" xlm
}
BEAH_PRIVATE="$BEAH_PRIVATE gxlm $(echo xlm{,1,2,3,4,5})"
function inst_all()
{
pushd $BEAH_ROOT
lmcall "$@" ./lm-install.sh
popd
}
function pwdless()
{
ssh root@$LABM mkdir -p .ssh
cat ~/.ssh/id_rsa.pub | ssh root@$LABM 'cat >> .ssh/authorized_keys'
}
function gpwdless()
{
lmcall "$@" pwdless
}
BEAH_PRIVATE="$BEAH_PRIVATE $(echo {,g}pwdless)"
export LM_ROOT=/mnt/testarea
export LM_LOGS="/mnt/testarea/beah*.out $LM_ROOT/var/log/beah*.log /mnt/testarea/var/log/rhts_task*.log"
function lm_logs()
{
vim -o $LM_LOGS
}
function lm_results()
{
local uploads=$LM_ROOT/var/beah/beah_fakelc/fakelc-uploads
vim -o $uploads/ $uploads/task_*/debug/task_log
}
function lm_rm_logs()
{
rm -f $LM_LOGS
rm -rf /mnt/testarea/beah-fakelc-logs
}
function lm_rm_runtime()
{
rm -rf $LM_ROOT/var/beah/*
rm -rf /mnt/testarea/beah-fakelc-logs/*
}
function lm_clean()
{
lm_rm_logs
lm_rm_runtime
rm -rf /var/cache/rhts
}
function launcher()
(
default="s o l"
all="s o c"
function view_logs()
{
local server=log_list
if ! { gvim --serverlist | grep -i $server; }; then
gvim --servername $server --remote /mnt/testarea/logs
gvim --servername $server --remote-send ":set readonly nomodifiable<CR>gh"
fi
}
function xt()
{
a1=$1
eval "temp=\$running_$a1"
if [[ -n $temp ]]; then
return 1
fi
eval "running_$a1=1"
shift
local geo=$1
shift
if [[ -z "$redir" ]]; then
xterm -geometry $geo -title "$*" -n "$*" -e "$@" &
else
# FIXME: this does not work properly! I would like to see
# output in runtime...
xterm -geometry $geo -title "$*" -n "$*" -e redir "beah_${a1}_$(date +%Y%m%d_%H%M%S)" "$@" &
fi
}
function runner()
{
if [[ -n "$redir" ]]; then
view_logs
fi
for i in $@; do
case $i in
a|A) runner $all ;;
s|S) xt s 80x35-0-0 beah-srv & ;;
c|C) xt c 80x20+0+0 beah-cmd-backend & ;;
o|O) xt o 80x35-0+0 beah-out-backend & ;;
l|L) xt l 80x20+0-0 beah-fakelc $BEAH_FAKELC_OPTS & ;;
b|B) sleep 2 && # beaker backend should wait for fakelc.
xt b 80x20+0+0 beah-beaker-backend & ;;
esac
done
}
cd $BEAH_ROOT
if [[ "$1" == "-r" || "$1" == "--redir" ]]; then
redir=1
shift
fi
if [[ -z "$@" ]]; then
runner $default
elif [[ "$1" == '-h' || "$1" == '--help' ]]; then
cat <<END
USAGE: launcher [-r|--redir] [-h|--help] [ (a|s|o|c|l|b) ... ]
OPTIONS:
-r --redir - redirect all output to files
-h --help - display this message
COMMANDS:
s - start the controller - srv
c - start the command backend - cmd_backend
o - start the output backend - out_backend
a - start all three programs
- if no arguments are provided, start server and output backend
l - start fake lab controller
b - start beaker backend
NOTE: programs are started in separate xterm windows
END
else
runner $@
fi
)
BEAH_FUNCTIONS="$BEAH_FUNCTIONS launcher"
export -f $BEAH_FUNCTIONS
cat <<END
** Environment is set. **
Run ${BEAH_FUNCTIONS/ /, }
END