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
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
# -*- sh -*- 
# Support functions for the startscript and some other scripts. 
# 
# $Id$ 
# 
 
# Default number of generations for log rotation. 
GENERATIONS=5 
export GENERATIONS 
 
rotate () { 
  b="$GENERATIONS"; 
  while test "$b" -gt 1; do 
    a=`expr "$b" - 1`; 
    mv -f "$1.$a" "$1.$b" 2> /dev/null; 
    b=$a; 
  done 
} 
 
setup_environment() { 
  # Check if TMPDIR is set to a user specific temp directory in 
  # /var/folders (c.f. "getconf DARWIN_USER_TEMP_DIR") - this breaks 
  # e.g. the patch system if the uid is changed or similar. 
  case "$TMPDIR" in 
    /var/folders/*) 
      TMPDIR=/tmp/ 
      export TMPDIR 
      ;; 
  esac 
 
  # If environment file doesn't exist, try to create it. 
  if test ! -f "$LOCALDIR"/environment && test -f bin/buildenv.pike;  then 
    if [ $verbose -gt 0 ]; then 
      dp "Building environment: $pike bin/buildenv.pike" 
    fi 
    $pike bin/buildenv.pike 
    touch "$LOCALDIR"/environment 
  fi 
 
  # Set up environment 
  if test -f "$LOCALDIR"/environment; then 
    . "$LOCALDIR"/environment 
  fi 
 
  # Also source environment2, which will not be modified by updates 
  if test -f "$LOCALDIR"/environment2; then 
    . "$LOCALDIR"/environment2 
  fi 
 
  # Make sure $CLASSPATH contains the servlet stuff 
  CLASSPATH="java/classes${CLASSPATH:+:}$CLASSPATH" 
  for jar in java/classes/*.jar; do 
    CLASSPATH="$jar:$CLASSPATH" 
  done 
  export CLASSPATH 
} 
 
dp() { 
  if [ "x$SILENT_START" = "xy" ] ; then  
     : 
  elif [ "x$self_test" = "xy" ]; then 
    echo "$@" >&2 
  else 
    echo "                    :" "$@" >&2 
  fi 
} 
 
dp_no_nl() { 
  if [ "x$SILENT_START" = "xy" ] ; then  
     : 
  elif [ "x$self_test" = "xy" ]; then 
    echo "$@" | tr -d ' 
' >&2 
  else 
    echo "                    :" "$@" | tr -d ' 
' >&2 
  fi 
} 
 
roxen_version() { 
   VERSION="`sed <etc/include/version.h -e '/roxen_ver/s/[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)[^0-9]*/\1/p' -n | head -1`" 
   BUILD="`sed <etc/include/version.h -e '/roxen_build/s/[^0-9]*\([0-9][0-9]*\)[^0-9]*/\1/p' -n | head -1`" 
   if [ -f "RELEASE" ] ; then 
     RELEASE="`head -1 <RELEASE`" 
   else 
     RELEASE="-cvs" 
   fi 
   echo "$VERSION.$BUILD$RELEASE" 
} 
 
fullpath() { 
  ( 
    IFS=: 
    for path in $PATH ; do 
      if [ -x "$path/$1" ] ; then 
        full="$path/$1" 
        break 
      fi 
    done 
    ( test "x$full" != "x" && echo "$full" ) || echo "$1" 
  ) 
} 
 
change_owner( ) { 
 uid="$1";  shift 
 gid="$1";  shift 
 
 for a in "$@" ; do  
    ok=`ls -lgd $a 2>/dev/null | grep "$uid" | grep "$gid" | wc -l` 
    ok=`echo $ok` 
    if [ x$ok = x1 ] ; then  
      dp "$a already has the correct ownership" 
    else 
      if [ x"$gid" = x ] ; then 
        gid=root 
      fi 
      dp "Changing ownership of $a to $uid:$gid" 
      if chown -R "$uid" "$a" 2>/dev/null ; then 
        if  chgrp -R "$gid" "$a" 2>/dev/null ; then 
          : 
        else 
          dp "Group change failed" 
        fi 
       else 
        dp "Ownership change failed" 
       fi 
     fi 
 done 
} 
 
 
find_pike() { 
 pike="`fullpath pike`" 
 if [ -x bin/pike ] ; then pike="$roxendir/bin/pike"; fi 
 if [ -x bin/roxen ] ; then  pike="$roxendir/bin/roxen"; fi 
 if [ -x "$LOCALDIR/bin/pike" ] ; then pike="$LOCALDIR/bin/pike"; fi 
 if [ -x "$LOCALDIR/bin/roxen" ] ; then pike="$LOCALDIR/bin/roxen"; fi 
 if [ "x$PIKE" = "x" ]; then :; else 
   if [ -x "$PIKE" ]; then  
     pike="$PIKE" 
   else 
     pikepath="`fullpath \"$PIKE\"`" 
     if [ -x "$pikepath" ]; then  
       pike="$pikepath" 
     else  
       dp "$PIKE is not executable - ignored." 
     fi 
   fi 
 fi 
 
 if [ x"$pike" = "x" ] ; then 
   dp "No pike binary found. Aborting." 
   exit 1 
 fi 
 
 if [ ! -f "$pike" ] ; then 
   dp "No pike binary found. Aborting." 
   exit 1 
 fi 
 
 # Check pike version if we're targeting something older than the latest. 
# if [ x`"$pike" -e 'if (__VERSION__ > 8.0) write("new");'` = "xnew" ]; then 
#   DEFINES="-V8.0 $DEFINES" 
#   export DEFINES 
# fi 
 
 PIKE="$pike" 
 export PIKE 
} 
 
raise_limit() { 
  if ulimit -n unlimited 2>/dev/null ; then  
   : 
  else 
    nfds=1048576 
    while [ $nfds -gt "`ulimit -n`" ] ; do  
      nfds=`expr $nfds / 4` 
      ulimit -n $nfds 2>/dev/null 
    done 
  fi 
  if [ "x$1" = "x" ] ; then 
    nn="`ulimit -n`" 
    if [ $verbose -gt 0 ]; then 
      if [ "x$nn" = xunlimited ] ; then 
        dp "Maximum number of open FDs: unlimited (2147483648)" 
      else 
        dp "Maximum number of open FDs: $nn" 
        if [ "$nn" -lt 1024 ] 2>/dev/null; then 
          dp "Warning: This is dangerously low" 
        fi 
      fi 
    fi 
  fi 
}