Projects
Wiki     Timeline     Roadmap     Browse Source     View Tickets     New Ticket     Search

root/CalendarServer/trunk/bin/caldavd

Revision 2706, 4.1 kB (checked in by cdaboo@…, 7 weeks ago)

We require Python 2.5 now so reflect that in the docs and test for 2.5 only in the scripts.

  • Property svn:executable set to *
Line 
1#!/bin/bash
2
3##
4# Copyright (c) 2005-2007 Apple Inc. All rights reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17##
18
19#PATH
20#PYTHONPATH
21
22daemonize="";
23username="";
24groupname="";
25configfile="";
26twistdpath="$(type -p twistd)";
27plugin_name="caldav";
28service_type="";
29profile="";
30twistd_reactor="";
31child_reactor=""
32
33py_version ()
34{
35  local python="$1"; shift
36  echo "$("${python}" -c "from distutils.sysconfig import get_python_version; print get_python_version()")";
37}
38
39try_python ()
40{
41  local python="$1"; shift
42
43  if [ -z "${python}" ]; then return 1; fi;
44
45  if ! type "${python}" > /dev/null 2>&1; then return 1; fi;
46  local py_version="$(py_version "${python}")";
47  if [ "${py_version/./}" -lt "24" ]; then return 1; fi;
48
49  return 0;
50}
51
52for v in "" "2.5"; do
53  for p in                                                              \
54    "${PYTHON:=}"                                                       \
55    "python${v}"                                                        \
56    "/usr/local/bin/python${v}"                                         \
57    "/usr/local/python/bin/python${v}"                                  \
58    "/usr/local/python${v}/bin/python${v}"                              \
59    "/opt/bin/python${v}"                                               \
60    "/opt/python/bin/python${v}"                                        \
61    "/opt/python${v}/bin/python${v}"                                    \
62    "/Library/Frameworks/Python.framework/Versions/${v}/bin/python"     \
63    "/opt/local/bin/python${v}"                                         \
64    "/sw/bin/python${v}"                                                \
65    ;
66  do
67    if try_python "${p}"; then python="${p}"; break; fi;
68  done;
69  if [ -n "${python:-}" ]; then break; fi;
70done;
71
72if [ -z "${python:-}" ]; then
73  echo "No suitable python found.";
74  exit 1;
75fi;
76
77usage ()
78{
79    program="$(basename "$0")";
80
81    if [ "${1--}" != "-" ]; then echo "$@"; echo; fi;
82
83    echo "Usage: ${program} [-hX] [-u username] [-g groupname] [-T twistd] [-t type] [-f caldavd.plist] [-p statsfile]";
84    echo "Options:";
85    echo "        -h Print this help and exit";
86    echo "        -X Do not daemonize";
87    echo "        -u User name to run as";
88    echo "        -g Group name to run as";
89    echo "        -f Configuration file to read";
90    echo "        -T Path to twistd binary";
91    echo "        -t Process type (Master, Slave or Combined)";
92    echo "        -p Path to the desired pstats file.";
93    echo "        -R The Twisted Reactor to run [${reactor}]";
94
95    if [ "${1-}" == "-" ]; then return 0; fi;
96    exit 64;
97}
98
99while getopts 'hXu:g:f:T:P:t:p:R:' option; do
100    case "${option}" in
101        '?') usage; ;;
102        'h') usage -; exit 0; ;;
103        'X') daemonize="-n"; ;;
104        'f') configfile="-f ${OPTARG}"; ;;
105        'T') twistdpath="${OPTARG}"; ;;
106        'u') username="-u ${OPTARG}"; ;;
107        'g') groupname="-g ${OPTARG}"; ;;
108        'P') plugin_name="${OPTARG}"; ;;
109        't') service_type="-o ProcessType=${OPTARG}"; ;;
110        'p') profile="-o Profiling/Enabled=True -o Profiling/BaseDirectory=${OPTARG}"; ;;
111        'R') twistd_reactor="--reactor=${OPTARG}"; child_reactor="-o Twisted/reactor=${OPTARG}"; ;;
112    esac;
113done;
114
115shift $((${OPTIND} - 1));
116
117if [ $# != 0 ]; then usage "Unrecognized arguments:" "$@"; fi;
118
119export PYTHONPATH
120
121echo exec "${python}" "${twistdpath}" "${twistd_reactor}" ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type} ${profile} "${child_reactor}";
122
123exec "${python}" "${twistdpath}" ${twistd_reactor} ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type} ${profile} ${child_reactor};
Note: See TracBrowser for help on using the browser.