#!/bin/sh # Install v1.3.2 (c) 27.5.99 by Andreas Ley (u) 24.10.2002 # Set up local apache http server global=/usr/machine/etc/httpd common=/usr/common/machine/etc/httpd doc=/usr/common/rzserv/doc/apache prefix=/usr/local/etc/httpd case `uname -sr` in HP-UX\ ?.1?.*) script=/sbin/init.d/httpd links="/sbin/rc2.d/S725httpd /sbin/rc1.d/K275httpd";; IRIX*) script=/etc/init.d/httpd links="/etc/rc2.d/S65httpd /etc/rc0.d/K25httpd";; Linux*) test -d /etc/rc2.d && rcd=/etc test -d /etc/rc.d/rc2.d && rcd=/etc/rc.d test -d /sbin/rc2.d && rcd=/sbin script=/${rcd}/init.d/httpd links="/${rcd}/rc2.d/S91httpd /${rcd}/rc3.d/S91httpd /${rcd}/rc4.d/S91httpd /${rcd}/rc5.d/S91httpd /${rcd}/rc0.d/K20httpd /${rcd}/rc1.d/K20httpd /${rcd}/rc6.d/K20httpd";; *) script=/etc/rc.d/rc.httpd;; esac scriptsrc=${common}/bin/init.httpd usage() { echo "Usage: `basename $0` [-s] [-c] [-b] [-i] [-a alias] [-m mailaddress] [-v] [-l interface] | [-u]" >&2 #echo "-G Set global path" >&2 # Unsupported #echo "-C Set common path" >&2 # Unsupported #echo "-P Set prefix (implies -c)" >&2 # Unsupported #echo "-B Don't install boot scripts" >&2 # Unsupported echo "-H Don't install links in htdocs/" >&2 echo "-s Install secure server (using host key)" >&2 echo "-S Install secure server with server local key (requires -a)" >&2 #echo "-g Generate self-signed certificate" >&2 echo "-c Install local conf (requires -m)" >&2 echo "-b Install local bin" >&2 echo "-i Install local cgi-bin" >&2 echo "-a Set server alias name (implies -c)" >&2 echo "-m Set server admin mail address (implies -c)" >&2 echo "-M Set host admin mail address (for -s)" >&2 echo "-v Add support for virtual hosts (implies -c)" >&2 echo "-l Listen on given interface (hostname or ip-addr) (implies -c)" >&2 echo "-u Uninstall http server" >&2 echo " (You will loose all log files, documents and local conf, binaries and cgi-scripts if installed!)" >&2 exit 1 } set -- `getopt G:C:P:BHsSgcbia:m:M:vl:uh $*` || usage htdocs="yes" while :; do case $1 in -h) sed '1d;s/^# *//;/^$/q' $0; usage;; -G) global=$2; shift 2;; -C) common=$2; shift 2;; -P) conf=yes; prefix=$2; shift 2;; -B) script=""; shift;; -H) htdocs=""; shift;; -s) test -n "${uninstall}" && usage; cert=host; shift;; -S) test -n "${uninstall}" && usage; conf=yes; cert=server; shift;; -g) test -n "${uninstall}" && usage; ssl_opts="-S"; shift;; -c) test -n "${uninstall}" && usage; conf=yes; shift;; -b) test -n "${uninstall}" && usage; bin=yes; shift;; -i) test -n "${uninstall}" && usage; cgibin=yes; shift;; -a) test -n "${uninstall}" && usage; conf=yes; alias=$2; shift 2;; -m) test -n "${uninstall}" && usage; conf=yes; mail=$2; shift 2;; -M) test -n "${uninstall}" && usage; hostmail=$2; shift 2;; -v) test -n "${uninstall}" && usage; conf=yes; vhost=yes; shift;; -l) test -n "${uninstall}" && usage; conf=yes; listen=$2; shift 2;; -u) test -n "${conf}${bin}${cgibin}" && usage; uninstall=yes; shift;; --) shift; break;; esac done test -n "${conf}" -a -z "${mail}" -o "${cert}" = "server" -a -z "${alias}" -o $# -ne 0 && usage if id | grep '^uid=0' >/dev/null; then :; else echo "Must be root to install." >&2 exit 1 fi PATH=/usr/machine/bin:/usr/machine/sbin:$PATH:/usr/segment/bin; export PATH umask 0022 tmpname=`basename $0` tmpname=`mktemp -c -p ${tmpname} 2>/dev/null || mktemp -q /tmp/${tmpname}.XXXXXX` trap "rm -f ${tmpname}; exit 0" 0 1 2 3 15 if test -n "${uninstall}"; then ############################################################################### # # Stop http daemon, delete cron entries, remove files # BUGS: passwd and group entries are not removed # if test -d ${prefix}; then ${script} stop crontab -l 2>/dev/null | grep -v "${prefix}/bin/www.daily" >${tmpname} && \ crontab ${tmpname} rm -rf ${links} ${script} ${prefix} else echo "httpd not installed." >&2 exit 1 fi else ############################################################################### # # Check alias name # if test -n "${alias}"; then if host -t a ${alias}. >/dev/null 2>&1; then :; else echo "Host alias ${alias} not defined." >&2 echo "To register an alias (usually www-..uni-karlsruhe.de)," >&2 echo "you may send mail to dns@rz.uni-karlsruhe.de." >&2 exit 1 fi fi ############################################################################### # # Set up passwd / group for the proper user and group ids # Make sure the entries are in the appropriate files, not only in NIS # grep '^www:' /etc/passwd >/dev/null 2>&1 && getpwent www >/dev/null 2>&1 || echo "www:*:600:600:WWW Server:${prefix}:/bin/sh" | chuser -PAA grep '^wwwadm:' /etc/passwd >/dev/null 2>&1 && getpwent wwwadm >/dev/null 2>&1 || echo "wwwadm:*:699:600:WWW Admin:${prefix}/htdocs:/bin/sh" | chuser -PAA grep '^www:' /etc/group >/dev/null 2>&1 && getgrent www >/dev/null 2>&1 || echo "www::600:wwwadm">>/etc/group grep '^wwwadm:' /etc/group >/dev/null 2>&1 && getgrent wwwadm >/dev/null 2>&1 || echo "wwwadm::699:">>/etc/group ############################################################################### # # Set up /etc/services for the provided ports # grep "^http[ ]" /etc/services >/dev/null || \ echo "http 80/tcp # HTTP" >>/etc/services if test -n "${cert}"; then grep "^https[ ]" /etc/services >/dev/null || \ echo "https 443/tcp # HTTP over TLS/SSL" >>/etc/services fi ############################################################################### # # Set up httpd starting directory # mkdir -p ${prefix} chown wwwadm ${prefix} chgrp wwwadm ${prefix} ############################################################################### # # Set up subdirectories for local documents and for access log files # mkdir -p ${prefix}/htdocs chown wwwadm ${prefix}/htdocs chgrp wwwadm ${prefix}/htdocs mkdir -p ${prefix}/logs chown wwwadm ${prefix}/logs chgrp www ${prefix}/logs chmod 770 ${prefix}/logs ############################################################################### # # Set up links to globally distributed directories # Install requested directories locally # test -n "${htdocs}" && \ su wwwadm -c "ln -s ${doc}/* ${prefix}/htdocs 2>/dev/null" su wwwadm -c "ln -s -f ${common}/icons ${prefix} 2>/dev/null" if test -z "${conf}"; then su wwwadm -c "ln -s -f ${common}/conf ${prefix} 2>/dev/null" else su wwwadm -c "rm -f ${prefix}/conf 2>/dev/null; mkdir -p ${prefix}/conf; rm -f ${prefix}/conf/srm.conf ${prefix}/conf/ssl.conf ${prefix}/conf/magic ${prefix}/conf/mime.types; ln -s ${common}/conf/srm.conf ${common}/conf/ssl.conf ${common}/conf/magic ${common}/conf/mime.types ${prefix}/conf; touch ${prefix}/conf/access.conf" sed 's/^ServerAdmin.*/ServerAdmin '"${mail}"'/' ${common}/conf/httpd.conf >${prefix}/conf/httpd.conf test -n "${alias}" && echo "ServerName ${alias}" >>${prefix}/conf/httpd.conf chown wwwadm ${prefix}/conf/httpd.conf chgrp wwwadm ${prefix}/conf/httpd.conf if test -n "${vhost}"; then if test -z "${cert}"; then grep '^NameVirtualHost \*$' ${prefix}/conf/access.conf >/dev/null || \ echo "NameVirtualHost *" >>${prefix}/conf/access.conf fi grep '^Include conf/vhosts/$' ${prefix}/conf/access.conf >/dev/null || \ echo "Include conf/vhosts/" >>${prefix}/conf/access.conf mkdir -p ${prefix}/conf/vhost ${prefix}/conf/vhosts chown wwwadm ${prefix}/conf/vhost ${prefix}/conf/vhosts chgrp wwwadm ${prefix}/conf/vhost ${prefix}/conf/vhosts if test -n "${cert}"; then mkdir -p ${prefix}/conf/ssl chown wwwadm ${prefix}/conf/ssl chgrp wwwadm ${prefix}/conf/ssl fi fi if test -n "${listen}" -o ${prefix} != /usr/local/etc/httpd; then rm -f ${prefix}/conf/srm.conf test -n "${listen}" && pattern="s%Listen *%&${listen}:%" test ${prefix} != /usr/local/etc/httpd && pattern="${pattern}${pattern:+;}s%/usr/local/etc/httpd%${prefix}%g" sed "${pattern}" ${common}/conf/srm.conf >${prefix}/conf/srm.conf chown wwwadm ${prefix}/conf/srm.conf chgrp wwwadm ${prefix}/conf/srm.conf fi fi if test -z "${bin}"; then su wwwadm -c "ln -s -f ${global}/bin ${prefix} 2>/dev/null" else su wwwadm -c "rm -f ${prefix}/bin; mkdir -p ${prefix}/bin; ln -s -f ${global}/bin/* ${prefix}/bin" fi if test -z "${cgibin}"; then su wwwadm -c "ln -s -f ${global}/cgi-bin ${prefix} 2>/dev/null" else su wwwadm -c "rm -f ${prefix}/cgi-bin 2>/dev/null; mkdir -p ${prefix}/cgi-bin; ln -s -f ${global}/cgi-bin/* ${prefix}/cgi-bin; ln -s -f user ${prefix}/cgi-bin/nph-user" fi ############################################################################### # # Set up cron entries # if test -f /usr/lib/cron/cron.allow; then grep root /usr/lib/cron/cron.allow >/dev/null || \ echo root >>/usr/lib/cron/cron.allow fi command="${prefix}/bin/www.daily" test ${prefix} != /usr/local/etc/httpd && command="${command} ${prefix}" test -z "${script}" && command="if test -x `echo ${command} | cut -d\ -f1`; then ${command}; fi" crontab -l 2>/dev/null | egrep -v "^# WWW server maintenance|${command}" >${tmpname} && \ echo "# WWW server maintenance" >>${tmpname} && \ echo "0 0 * * * ${command}" >>${tmpname} && \ crontab ${tmpname} ############################################################################### # # Set up boot start command # if test -n "${script}"; then mkdir -p `dirname ${script}` rm -f ${script} cp ${scriptsrc} ${script} for link in ${links}; do rm -f ${link} ln -s ${script} ${link} done fi ############################################################################### # # Create private key and certificate signing request # if test -n "${cert}"; then path=/etc/ssl/host test "${cert}" = server && path=${prefix}/conf/server if test ! -s ${path}.crt; then echo "WARNING: Your secure server key hasn't been certified yet." rm -f ${path}.csr ${path}.txt if test "${cert}" = server; then su wwwadm -c "/usr/segment/bin/ssl-request ${ssl_opts} `test -s ${path}.key || echo \"-g\"` -n ${alias:-`getfqdn`} -m ${mail} ${path}.key" else ssl-request ${ssl_opts} `test -s ${path}.key || echo "-g"` ${hostmail:+-m} ${hostmail} ${path}.key fi fi fi ############################################################################### # # Start up http daemon, but be sure to kill an already running 'loop' # if test -n "${script}"; then ${script} stop >/dev/null 2>&1 ${script} start fi ############################################################################### fi exit 0