-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssq
executable file
·86 lines (78 loc) · 1.7 KB
/
ssq
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
#!/usr/bin/env bash
#
# Synopsis:
# Command line front end to sql queries for all schemas.
# Usage:
# ssq # help
# ssq ls # list all schemas
# ssq service <udig> # check of <schema>.service for udig
# ssq setcore help # help for "setcore" schema
# Note:
# In help() why are tabs aligned in vi but not in cat of message?
#
PROG=$(basename $0)
die()
{
cat >&2 <<END
ERROR: $@
usage: ssq [help | ls | service | [<schema>] [...options]]
END
exit 1
}
help()
{
cat <<END
Usage:
$PROG # list help
$PROG help # ..
$PROG ls # list queryable schemas
$PROG service <udig> # trace a blob through schemas
Environment:
SETSPACE_ROOT $SETSPACE_ROOT
END
}
# help message
if [ $# = 0 -o \( $# = 1 -a \( "$1" = help -o "$1" = --help \) \) ]; then
help
exit 0
fi
test -n "$SETSPACE_ROOT" || die "env not defined: SETSPACE_ROOT"
cd $SETSPACE_ROOT || die "cd failed: $SETSPACE_ROOT"
test -r etc/profile && . etc/profile
ls_schema()
{
SCHEMAS=$(
find-schema | while read SCH; do
test -e schema/$SCH/libexec/ssq-$SCH && echo $SCH
done
)
test -n "$SCHEMAS" || die "no schemas in $SETSPACE_ROOT/schema"
(
cat <<END
Schema
--------
END
echo $SCHEMAS | tr ' ' '\n' | while read SCH; do
echo $SCH
done
) | column -s ' ' -t | sed 's/ * //'
}
ACTION=$1
shift
case $ACTION in
service)
test $# = 1 || die "service: wrong argument count: expected 1, got $#"
exec libexec/ssq-service $1
;;
ls)
test $# = 0 || die "ls: wrong argument count: expected 0, got $#"
ls_schema
exit 0
;;
esac
SCHEMA=$1
SCHEMA_DIR=schema/$SCHEMA
test -d $SCHEMA_DIR || die "not a schema: $SCHEMA"
SCHEMA_EXEC=$SCHEMA_DIR/libexec/ssq-$SCHEMA
test -x $SCHEMA_EXEC || die "can not query schema: $SCHEMA"
exec $SCHEMA_EXEC "$@"