1#!/bin/sh
2#
3# Licensed to the Apache Software Foundation (ASF) under one or more
4# contributor license agreements.  See the NOTICE file distributed with
5# this work for additional information regarding copyright ownership.
6# The ASF licenses this file to You under the Apache License, Version 2.0
7# (the "License"); you may not use this file except in compliance with
8# the License.  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# Usage: install-bindist.sh [ServerRoot]
20# This script installs the Apache binary distribution and
21# was automatically created by binbuild.sh.
22 
23lmkdir()
24{
25  path=""
26  dirs=`echo $1 | sed -e 's%/% %g'`
27  mode=$2
28 
29  set -- ${dirs}
30 
31  for d in ${dirs}
32  do
33    path="${path}/$d"
34    if test ! -d "${path}" ; then
35      mkdir ${path}
36      if test $? -ne 0 ; then
37        echo "Failed to create directory: ${path}"
38        exit 1
39      fi
40      chmod ${mode} ${path}
41    fi
42  done
43}
44 
45lcopy()
46{
47  from=$1
48  to=$2
49  dmode=$3
50  fmode=$4
51 
52  test -d ${to} || lmkdir ${to} ${dmode}
53  (cd ${from} && tar -cf - *) | (cd ${to} && tar -xf -)
54 
55  if test "X${fmode}" != X ; then
56    find ${to} -type f -print | xargs chmod ${fmode}
57  fi
58  if test "X${dmode}" != X ; then
59    find ${to} -type d -print | xargs chmod ${dmode}
60  fi
61}
62 
63##
64##  determine path to (optional) Perl interpreter
65##
66PERL=no-perl5-on-this-system
67perls='perl5 perl'
68path=`echo $PATH | sed -e 's/:/ /g'`
69found_perl=0
70 
71for dir in ${path} ;  do
72  for pperl in ${perls} ; do
73    if test -f "${dir}/${pperl}" ; then
74      if `${dir}/${pperl} -v >/dev/null 2>&1` ; then
75        PERL="${dir}/${pperl}"
76        found_perl=1
77        break
78      fi
79    fi
80  done
81  if test $found_perl = 1 ; then
82    break
83  fi
84done
85 
86if [ .$1 = . ]
87then
88  SR=@default_dir@
89else
90  SR=$1
91fi
92echo "Installing binary distribution for platform @os@"
93echo "into directory $SR ..."
94lmkdir $SR 755
95lmkdir $SR/proxy 750
96lmkdir $SR/logs 755
97lmkdir $SR/build 755
98lcopy bindist/build $SR/build 750 750
99lcopy bindist/man $SR/man 755 644
100if [ -d bindist/modules ]
101then
102  lcopy bindist/modules $SR/modules 750 750
103fi
104lcopy bindist/include $SR/include 755 644
105lcopy bindist/icons $SR/icons 755 644
106lcopy bindist/manual $SR/manual 755 644
107lcopy bindist/cgi-bin $SR/cgi-bin 750 750
108if [ -f $SR/bin/envvars ]
109then
110  echo "[Preserving existing envvars settings.]"
111  cp -p $SR/bin/envvars ./envvars.orig
112  HAD_ENVVARS=yes
113else
114  HAD_ENVVARS=no
115fi
116lcopy bindist/bin $SR/bin 750 750
117if [ $HAD_ENVVARS = yes ]
118then
119  cp -p ./envvars.orig $SR/bin/envvars
120  rm ./envvars.orig
121fi
122lcopy bindist/lib $SR/lib 750 750
123if [ -d $SR/conf ]
124then
125  echo "[Preserving existing configuration files.]"
126  cp bindist/conf/*-std.conf $SR/conf/
127else
128  lcopy bindist/conf $SR/conf 750 640
129  sed -e "s%@default_dir@%$SR%" $SR/conf/httpd-std.conf > $SR/conf/httpd.conf
130fi
131if [ -d $SR/htdocs ]
132then
133  echo "[Preserving existing htdocs directory.]"
134else
135  lcopy bindist/htdocs $SR/htdocs 755 644
136fi
137if [ -d $SR/error ]
138then
139  echo "[Preserving existing error documents directory.]"
140else
141  lcopy bindist/error $SR/error 755 644
142fi
143 
144sed -e "s;^#!\@perlbin\@.*;#!$PERL;" -e "s;\@exp_installbuilddir\@;$SR/build;" \
145	support/apxs.in > $SR/bin/apxs
146PRE=`grep "^prefix = " bindist/build/config_vars.mk`
147PRE=`echo $PRE | sed -e "s;prefix = ;;"`
148sed -e "s;$PRE;$SR;" bindist/build/config_vars.mk > $SR/build/config_vars.mk
149sed -e "s;^#!/.*;#!$PERL;" bindist/bin/dbmmanage > $SR/bin/dbmmanage
150sed -e "s%@default_dir@%$SR%" \
151        -e "s%^HTTPD=.*$%HTTPD=\"$SR/bin/httpd -d $SR\"%" bindist/bin/apachectl > $SR/bin/apachectl
152sed -e "s%@default_dir@%$SR%" \
153        bindist/bin/envvars-std > $SR/bin/envvars-std
154if [ $HAD_ENVVARS = no ]
155then
156    cp -p $SR/bin/envvars-std $SR/bin/envvars
157fi
158 
159echo "Ready."
160echo " +--------------------------------------------------------+"
161echo " | You now have successfully installed the Apache @ver@  |"
162echo " | HTTP server. To verify that Apache actually works      |"
163echo " | correctly you should first check the (initially        |"
164echo " | created or preserved) configuration files:             |"
165echo " |                                                        |"
166echo " |   $SR/conf/httpd.conf"
167echo " |                                                        |"
168echo " | You should then be able to immediately fire up         |"
169echo " | Apache the first time by running:                      |"
170echo " |                                                        |"
171echo " |   $SR/bin/apachectl start "
172echo " |                                                        |"
173echo " | Thanks for using Apache.       The Apache Group        |"
174echo " |                                http://www.apache.org/  |"
175echo " +--------------------------------------------------------+"
176echo " "
177