-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssq
executable file
·79 lines (69 loc) · 1.72 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
#!/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
# ssq jsonorg help # help for "jsonorg" schema
# ssq <schema> help # help for <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 <schema> ... # query on a schema
$PROG <schema> help # help for queries on this schema
$PROG ls # list queryable schemas
$PROG service <udig> # trace a blob through schemas service tables
$PROG [help|--help] # ...
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
ACTION="$1"
shift
case "$ACTION" in
service|ls)
exec libexec/ssq-$ACTION $@
;;
[a-z_]*)
;;
*)
die "unknown action: $ACTION"
;;
esac
SCHEMA=$ACTION
SCHEMA_DIR=schema/$SCHEMA
test -d $SCHEMA_DIR || die "not a schema: $SCHEMA"
cd $SCHEMA_DIR || die "cd $SCHEMA_DIR/ failed: exit status=$?"
#
# with no args ssq-<schema> runs ssq-<schema>-ls-recent
# schema
if [ $# = 0 -a libexec/ssq-$SCHEMA-ls-recent ]; then
LS_RECENT=libexec/ssq-$SCHEMA-ls-recent
test -x $LS_RECENT && exec $LS_RECENT
fi
SCHEMA_EXEC=libexec/ssq-$SCHEMA
test -e $SCHEMA_EXEC || die "no exec for schema: $SCHEMA"
test -x $SCHEMA_EXEC || die "libexec not executable: $SCHEMA_EXEC"
exec $SCHEMA_EXEC $@