Cross Reference: /opengrok/tools/Groups
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#!/bin/sh
# Supported Environment Variables:
# - OPENGROK_STANDARD_ENV Run Time Shell Environment (Shell Script)
# - OPENGROK_CONFIGURATION User Configuration (Shell Script)
#
# Supported Environment Variables for configuring the default setup:
# - OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution
# - containing the opengrok.jar
# - OPENGROK_JAR Directly specify the opengrok.jar file
# - OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area
# - determining the configuration
# switch), default is DATA_ROOT/etc/ctags.config
# - JAVA_HOME Full Path to Java Installation Root
# - JAVA Full Path to java binary (to enable 64bit JDK)
# - JAVA_OPTS Java options (e.g. for JVM memory increase view
# - READ_XML_CONFIGURATION file with read only configuration
# - determining the configuration
PROGNAME=`basename $0`
SCRIPT_DIRECTORY=`dirname "${0}"`
SCRIPT_DIRECTORY=`cd "${SCRIPT_DIRECTORY}"; pwd`
Usage()
{
exec >&2
echo ""
echo "Usage: ${PROGNAME} <add|delete|match|list|help> [--help] [--verbose] [-d]"
echo " ${PROGNAME} add <name> <pattern>"
echo " ${PROGNAME} delete <name>"
echo " ${PROGNAME} match <project name>"
echo ""
echo " The script searches for the configuration in"
echo " OPENGROK_INSTANCE_BASE/etc/configuration.xml or"
echo " READ_XML_CONFIGURATION files or"
echo " you can use the -i option."
echo " When no such file exists it uses an empty configuration."
echo ""
echo " Optional environment variables:"
echo " OPENGROK_CONFIGURATION - location of your configuration"
echo " e.g. $ OPENGROK_CONFIGURATION=/var/opengrok/myog.conf ${0} ... "
echo ""
echo " See the code for more information on configuration options /" \
"variables"
echo ""
}
CommonInvocation()
{
${DO} \
${JAVA} \
${JAVA_OPTS} \
${JAVA_CLASSPATH:+-classpath} ${JAVA_CLASSPATH} \
${MAIN_CLASS} \
${INPUT_FILE:+-i} ${INPUT_FILE:+"$INPUT_FILE"} \
${OUTPUT_FILE:+-o} ${OUTPUT_FILE:+"$OUTPUT_FILE"} \
"${@}"
}
StdInvocation()
{
CommonInvocation \
${NAME:+-n} ${NAME:+"$NAME"} \
${PATTERN:+-r} ${PATTERN:+"$PATTERN"} \
${PARENT:+-p} ${PARENT:+"$PARENT"} \
${MATCH:+-m} ${MATCH:+"$MATCH"} \
${LIST:+-l} \
${DELETE:+-d} \
"${@}"
}
CheckInputFile()
{
if [ -n "$INPUT_FILE" ] && ( [ ! -e "$INPUT_FILE" ] || [ ! -f "$INPUT_FILE" ] )
then
echo "input file does not exist or is not readable"
LocalUsage
exit 5
fi
}
OneArgument()
{
if [ $# -gt 0 ]
then
echo "$1"
fi
}
ExpectOption()
{
if [ $# -lt 2 ]
then
echo "Argument \"$1\" expects a value"
exit 3
fi
}
Info()
{
if $VERBOSE
then
echo "Configuration loaded"
echo "\tJAVA_HOME = "${JAVA_HOME}
if [ -n "$JAVA_HOME" ]
then
echo "\tJAVA = $JAVA_HOME/bin/java"
else
echo "\tJAVA ="
fi
echo "\tJAVA_OPTS = "${JAVA_OPTS}
echo "\tJAVA_CLASSPATH = "${JAVA_CLASSPATH}
echo "\tOPENGROK_JAR = "${OPENGROK_JAR}
echo "\tOPENGROK_CONFIGURATION = "${OPENGROK_CONFIGURATION}
echo "\tOPENGROK_STANDARD_ENV = "${OPENGROK_STANDARD_ENV}
echo "\tOPENGROK_INSTANCE_BASE = "${OPENGROK_INSTANCE_BASE}
echo "\tOPENGROK_DISTRIBUTION_BASE = "${OPENGROK_DISTRIBUTION_BASE}
echo "\tREAD_XML_CONFIGURATION = "${READ_XML_CONFIGURATION}
echo "\tOPENGROK_JAR = "${OPENGROK_JAR}
echo ""
echo "Files used"
echo "\tINPUT_FILE = "${INPUT_FILE:-empty configuration}
echo "\tOUTPUT_FILE = "${OUTPUT_FILE:-standard output}
echo "\tPATTERN = "${PATTERN:-$PATTERN}
echo "\tNAME = "${NAME:-$NAME}
echo "\tPARENT = "${PARENT:-$PARENT}
echo ""
fi
}
Progress()
{
if $VERBOSE
then
echo "$@"
fi
}
Match ()
{
LocalUsage()
{
echo "Usage:"
echo "${PROGNAME} match <project name> [-i|--input <file>] [-v|--verbose] [-d]"
echo ""
echo " Lists which groups would match the project name (description)"
echo ""
echo "Options:"
echo " -d option performs dry run with verbose mode"
echo " -i option can be used for specifying the input file"
}
while [ $# -gt 0 ]
do
opt="$1"
case $opt in
-i|--input)
ExpectOption "$@"
shift
INPUT_FILE=$(OneArgument "$@")
;;
-d)
DO=echo
VERBOSE=true
;;
-v|--verbose)
VERBOSE=true
;;
-h|--help)
LocalUsage
exit 0
;;
-*)
echo "Uknown option \"$opt\"" && LocalUsage && exit 5
;;
*)
if [ "x$MATCH" = "x" ]
then
MATCH=$(OneArgument "$@")
else
echo "match must be specified only once" && LocalUsage && exit 5
fi
;;
esac
shift
done
[ -z "$MATCH" ] && echo "project name must be specified" && LocalUsage && exit 5
CheckInputFile
Info
StdInvocation
}
List ()
{
LocalUsage()
{
echo "Usage:"
echo "${PROGNAME} list [-i|--input <file>] [-v|--verbose] [-d]"
echo ""
echo " Lists the current configuration"
echo ""
echo "Options:"
echo " -d option performs dry run with verbose mode"
echo " -i option can be used for specifying the input file"
}
while [ $# -gt 0 ]
do
opt="$1"
case $opt in
-i|--input)
ExpectOption "$@"
shift
INPUT_FILE=$(OneArgument "$@")
;;
-d)
DO=echo
VERBOSE=true
;;
-v|--verbose)
VERBOSE=true
;;
-h|--help)
LocalUsage
exit 0
;;
-*)
echo "Uknown option \"$opt\"" && LocalUsage && exit 5
;;
*)
echo "this requires no other parameter"
LocalUsage
exit 5
;;
esac
shift
done
LIST=true
CheckInputFile
Info
StdInvocation
}
Delete ()
{
LocalUsage()
{
echo "Usage:"
echo "${PROGNAME} delete <name> [-i|--input <file>] [-o|--output <file>] [-l] [-v|--verbose] [-u|--update] [-d]"
echo ""
echo " Deletes a group with given name from the input configuration"
echo ""
echo "Options:"
echo " -d option performs dry run with verbose mode"
echo " -i option can be used for specifying the input file"
echo " -l option prints the overview to stdout (still -o can be used)"
echo " -o option can be used for saving the result"
echo " -u option forces the script to use same output file as input file (overwrite)"
}
while [ $# -gt 0 ]
do
opt="$1"
case $opt in
-i|--input)
ExpectOption "$@"
shift
INPUT_FILE=$(OneArgument "$@")
;;
-o|--output)
ExpectOption "$@"
shift
OUTPUT_FILE=$(OneArgument "$@")
;;
-u|--update)
OUTPUT_FILE="$INPUT_FILE"
;;
-l|--list)
LIST=true
;;
-d)
DO=echo
VERBOSE=true
;;
-v|--verbose)
VERBOSE=true
;;
-h|--help)
LocalUsage
exit 0
;;
-*)
echo "Uknown option \"$opt\"" && LocalUsage && exit 5
;;
*)
if [ "x$NAME" = "x" ]
then
NAME=$(OneArgument "$@")
else
echo "name must be specified only once" && LocalUsage && exit 5
fi
;;
esac
shift
done
[ -z "$NAME" ] && echo "name must be specified" && LocalUsage && exit 5
DELETE=true
CheckInputFile
Info
StdInvocation
}
Add ()
{
LocalUsage()
{
echo "Usage:"
echo "${PROGNAME} add <name> <pattern> [-i|--input <file>] [-o|--output <file>] [-l] [-v|--verbose] [-u|--update] [-d]"
echo ""
echo " Adds or updates a group with given name"
echo " 1) If given group name already exists, the pattern is updated."
echo " 2) If given group name does not exist, the group is inserted"
echo " 3) If the parent group exists, the group is inserted as its child"
echo ""
echo "Options:"
echo " -d option performs dry run with verbose mode"
echo " -i option can be used for specifying the input file"
echo " -l option prints the overview to stdout (still -o can be used)"
echo " -o option can be used for saving the result"
echo " -u option forces the script to use same output file as input file (overwrite)"
}
NAME=""
PATTERN=""
while [ $# -gt 0 ]
do
opt="$1"
case $opt in
-i|--input)
ExpectOption "$@"
shift
INPUT_FILE=$(OneArgument "$@")
;;
-o|--output)
ExpectOption "$@"
shift
OUTPUT_FILE=$(OneArgument "$@")
;;
-p|--parent)
ExpectOption "$@"
shift
PARENT=$(OneArgument "$@")
;;
-u|--update)
OUTPUT_FILE="$INPUT_FILE"
;;
-l|--list)
LIST=true
;;
-d)
DO=echo
VERBOSE=true
;;
-v|--verbose)
VERBOSE=true
;;
-h|--help)
LocalUsage
exit 0
;;
-*)
echo "Uknown option \"$opt\"" && LocalUsage && exit 5
;;
*)
if [ "x$NAME" = "x" ]
then
NAME=$(OneArgument "$@")
elif [ "x$PATTERN" = "x" ]
then
PATTERN=$(OneArgument "$@")
else
echo "name and pattern must be specified only once" && LocalUsage && exit 5
fi
;;
esac
shift
done
[ -z "$NAME" ] && echo "name must be specified" && LocalUsage && exit 5
[ -z "$PATTERN" ] && echo "pattern must be specified" && LocalUsage && exit 5
CheckInputFile
Info
StdInvocation
}
# Find and load relevant configuration
#
# Taken (and modified) from original OpenGrok shell wrapper
#
SetupInstanceConfiguration()
{
VERBOSE="${VERBOSE:-false}"
OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/var/opengrok}"
if [ -f "${OPENGROK_STANDARD_ENV}" ]
then
Progress "Loading ${OPENGROK_STANDARD_ENV} ..."
. "${OPENGROK_STANDARD_ENV}"
fi
if [ -n "${OPENGROK_CONFIGURATION}" -a -f "${OPENGROK_CONFIGURATION}" ]
then
# Load the Local OpenGrok Configuration Environment
Progress "Loading ${OPENGROK_CONFIGURATION} ..."
. "${OPENGROK_CONFIGURATION}"
fi
# REQUIRED: Java Home
JAVA_HOME="${JAVA_HOME:-`FindJavaHome`}"
# REQUIRED: Java Virtual Machine
JAVA="${JAVA:-$JAVA_HOME/bin/java}"
if [ -z "${OPENGROK_DISTRIBUTION_BASE}" ]
then
if [ -d "${SCRIPT_DIRECTORY}/../dist" -a \
-f "${SCRIPT_DIRECTORY}/../dist/opengrok.jar" -a \
-f "${SCRIPT_DIRECTORY}/../dist/source.war" \
]
then
# Handle Developer Build Environments
OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/../dist"
else
# Handle Binary Distributions
OPENGROK_DISTRIBUTION_BASE="${SCRIPT_DIRECTORY}/../lib"
fi
fi
# REQUIRED: Java Archive of OpenGrok (Installation Location)
OPENGROK_JAR="${OPENGROK_JAR:-${OPENGROK_DISTRIBUTION_BASE}/opengrok.jar}"
JAVA_CLASSPATH="$CLASSPATH"
JAVA_CLASSPATH="${JAVA_CLASSPATH}:${OPENGROK_JAR}"
JAVA_OPTS="${JAVA_OPTS:--Xmx2048m}"
MAIN_CLASS="org.opensolaris.opengrok.configuration.Groups"
unset NAME
unset PATTERN
unset PARENT
unset DELETE
unset MATCH
unset LIST
if [ -n "$OPENGROK_INSTANCE_BASE" ] && [ -f "$OPENGROK_INSTANCE_BASE/etc/configuration.xml" ]
then
INPUT_FILE="$OPENGROK_INSTANCE_BASE/etc/configuration.xml"
elif [ -n "$READ_XML_CONFIGURATION" ] && [ -f "$READ_XML_CONFIGURATION" ]
then
INPUT_FILE="$READ_XML_CONFIGURATION"
fi
}
# Find java home based on your system information
#
# Taken from original OpenGrok shell wrapper
#
FindJavaHome()
{
if [ -x "/bin/uname" ]; then
OS_NAME="`/bin/uname -s`"
OS_VERSION="`/bin/uname -r`"
elif [ -x "/usr/bin/uname" ]; then
OS_NAME="`/usr/bin/uname -s`"
OS_VERSION="`/usr/bin/uname -r`"
else
echo "Cannot determine operating system version"
exit 3
fi
javaHome=""
case "${OS_NAME}:${OS_VERSION}" in
SunOS:5.10) javaHome="/usr/jdk/instances/jdk1.7.0" ;;
SunOS:5.11) javaHome="/usr/jdk/latest" ;;
SunOS:5.12) javaHome="/usr/jdk/latest" ;;
Darwin:*) javaHome=`/usr/libexec/java_home` ;;
Linux:*)
if [ -f /etc/alternatives/java ]
then
javaHome=`ls -l /etc/alternatives/java | cut -f 2 -d \> `
javaHome=`dirname $javaHome`
javaHome=`dirname $javaHome`
fi
;;
esac
if [ -z "${javaHome}" ]
then
echo "Unable to determine Java Home" \
"for ${OS_NAME} ${OS_VERSION}"
exit 3
fi
if [ ! -d "${javaHome}" ]
then
echo "Missing Java Home ${javaHome}"
exit 3
fi
echo "${javaHome}"
}
if [ $# -eq 0 ]
then
Usage
exit 1
fi
SetupInstanceConfiguration
case "${1}" in
match)
shift
Match "$@"
;;
delete)
shift
Delete "$@"
;;
add)
shift
Add "$@"
;;
list)
shift
List "$@"
;;
help)
Usage
exit 0
;;
*)
Usage
exit 5
;;
esac