-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssq-common.bash
More file actions
73 lines (63 loc) · 1.17 KB
/
ssq-common.bash
File metadata and controls
73 lines (63 loc) · 1.17 KB
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
#
# Synopsis:
# Common routines for all ssq-* scripts across <schema>/libexec
# Usage:
# source $SETSPACE_ROOT/lib/ssq-common.bash
#
PROG=$(basename $0)
die()
{
echo "$PROG: ERROR: $@" >&2
exit 1
}
#
# psql for tab separated records for front-end scripts
#
# Usage:
# PSQL=$SSQ_COMMON_PSQL_TSV
# $PSQL --file lib/sql-setcore-service.sql <udig>
#
SSQ_COMMON_PSQL_TSV=$SETSPACE_ROOT/libexec/ssq-common-psql-tsv
#
# psql for expanded format meant for humans
#
# Usage:
# PSQL=$SSQ_COMMON_PSQL_EXPAND
# $PSQL --file lib/sql-setcore-udig.sql <udig> --set blob=$BLOB
#
SSQ_COMMON_PSQL_EXPAND=$SETSPACE_ROOT/libexec/ssq-common-psql-expand
usage()
{
echo "usage: $PROG $USAGE"
STATUS=$1
exit $STATUS
}
is_udig()
{
[[ "$1" =~ ^[a-z][a-z0-9]{0,7}:[[:graph:]]{32,128}$ ]] && return 0
return 1
}
frisk_udig()
{
local U="$1"
is_udig "$U" || die "not a udig: $U"
}
exec_udig()
{
is_udig "$1" || return
LIBEXEC=libexec/$PROG-udig
test -x $LIBEXEC || die 'no libexec udig'
exec $LIBEXEC $@
}
exec_help()
{
[ $# = 0 -o "$1" = help ] && usage
}
exec_action()
{
ACTION=$1
shift
LIBEXEC="libexec/$PROG-$ACTION"
test -x $LIBEXEC || die "action not found: $ACTION"
exec $LIBEXEC $@
}