xref: /5.5.2/couchdb/bin/couchjs.tpl.in (revision df7ac136)
1#! /bin/sh -e
2
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#   http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15SCRIPT_OK=0
16SCRIPT_ERROR=1
17
18DEFAULT_VERSION=170
19
20basename=`basename $0`
21
22display_version () {
23    cat << EOF
24$basename - %package_name% %version%
25
26Licensed under the Apache License, Version 2.0 (the "License"); you may not use
27this file except in compliance with the License. You may obtain a copy of the
28License at
29
30  http://www.apache.org/licenses/LICENSE-2.0
31
32Unless required by applicable law or agreed to in writing, software distributed
33under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
34CONDITIONS OF ANY KIND, either express or implied. See the License for the
35specific language governing permissions and limitations under the License.
36EOF
37}
38
39display_help () {
40    cat << EOF
41Usage: $basename [FILE]
42
43The $basename command runs the %package_name% JavaScript interpreter.
44
45The exit status is 0 for success or 1 for failure.
46
47Options:
48
49  -h  display a short help message and exit
50  -V  display version information and exit
51  -H  install couchjs cURL bindings (only avaiable
52      if CouchDB was built with cURL available)
53
54Report bugs at <%bug_uri%>.
55EOF
56}
57
58display_error () {
59    if test -n "$1"; then
60        echo $1 >&2
61    fi
62    echo >&2
63    echo "Try \`"$basename" -h' for more information." >&2
64    exit $SCRIPT_ERROR
65}
66
67run_couchjs () {
68    exec %locallibbindir%/%couchjs_command_name% $@
69}
70
71parse_script_option_list () {
72    set +e
73    options=`getopt hVH $@`
74    if test ! $? -eq 0; then
75        display_error
76    fi
77    set -e
78    eval set -- $options
79    while [ $# -gt 0 ]; do
80        case "$1" in
81            -h) shift; display_help; exit $SCRIPT_OK;;
82            -V) shift; display_version; exit $SCRIPT_OK;;
83            --) shift; break;;
84            *) break;;
85        esac
86    done
87    script_name=`echo $@ | sed -e 's/.*--[[:blank:]]*//'`
88    if test -z "$script_name"; then
89        display_error "You must specify a FILE."
90    fi
91    options=`echo $@ | sed -e 's/--//'`
92    run_couchjs $options
93}
94
95parse_script_option_list $@
96