#!/bin/sh # sh Configure [args] # # This shell script does an installation of MajorCool # programs and files based upon user input. Some code # copied from metaconfig for the sake of portability. export PATH || (echo "This isn't sh. Feeding myself to sh."; sh $0 $*; kill $$) if [ ! -t 0 ]; then echo "Say 'sh Configure', not 'sh /dev/null 2>&1 && \ echo "(Korn shell detected. Some ksh's blow up on Configure." && \ echo "If so, try the Bourne shell instead.)" # This configuration script may be invoked with arguments. They may # be one of: # -f, fast don't ask "unnecessary" questions # variable=value set shell variable to value # file output filename [default: default.sh] # # Read them here to allow for changing defaults to support testing. # fastread=read config=default.sh while [ $# -ge 1 ]; do case "$1" in -f|fast) fastread='eval ans="" ; echo "" #' ;; *=*) eval $1 ;; *) config=$1 ;; esac shift done # Set up defaults for configuration # This information describes the configuration defaults. They will # be overwritten by any of the parameters saved in $config. # For yes/no values, 0=no, 1=yes DOMO_DIR=/usr/local/majordomo # Majordomo home directory DOMO_CONF= # Majordomo configuration file DOMO_VERSION= # Majordomo version number WEB_SCHEME="http" # Web server scheme/protocol WEB_ROOT=/usr/local/share/apache # Web server root directory WEB_CGIDIR= # Web server CGI directory WEB_CGIURL="/cgi-bin" # Web server CGI URL WEB_IMGDIR= # Web server images directory WEB_IMGURL="/icons" # Web server images URL WEB_DOCROOT=/usr/local/share/apache/htdocs # Root for served documents WEB_HEADER= # Header for common site look WEB_FOOTER= # Footer for common site look COOL_CF= # Config file for this installation COOL_SITENAME= # The name of this site COOL_SITEHOME= # Home page for this site COOL_TMPDIR="/tmp" # MajorCool scratch area COOL_CACHE= # MajorCool cache file COOL_NAME="majordomo" # MajorCool CGI program name COOL_USERID="bin" # User-id to install as COOL_GROUPID="bin" # Group-id to install as COOL_HELPFILE=/majorcool.html # MajorCool HTML info file location COOL_SITEADDR="simple" # The address lookup function to use COOL_CREATECMD= # Program to call on CREATE request COOL_RENAMECMD= # Program to call on RENAME request COOL_DELETECMD= # Program to call on DELETE request OPT_ALLOWBROWSE=1 # Allow sub/unsub browsing OPT_ALLOWMODIFY=1 # Allow list administration OPT_ALLOWCREATE=1 # Allow list creation OPT_ALLOWRENAME=1 # Allow list renaming OPT_ALLOWDELETE=1 # Allow list deletion OPT_HIDDENLISTS=0 # Hide list of lists from admins? OPT_HIDDENPASSWD=0 # Admin password not a visible config field? OPT_NOADVERTISED=0 # Do members see noadvertised lists? OPT_TRUSTIDENT=0 # Will users be faking their names? OPT_CMDVERIFY=0 # Paranoia mode. Return commands via e-mail? OPT_SUBVERIFY=0 # Similar to cmdverify, but only for sub/unsub. OPT_SENDCF=1 # Offer "send config via mail" option? OPT_COMMENTEDCF=1 # Include std comments when saving list configs? OPT_MULTIPART=1 # Use fancy multipart-mixed-replace effects? OPT_PREFSRETURN=0 # Return to prior screen from Prefs session? OPT_ROBOTS=1 # Allow Internet spiders to index the CGI? OPT_SCANSTEPS=50 # Update interval suring list scan. PERLBIN="/usr/bin/perl" # How to start a perl script #---------------------------------------------------------------------------- : some greps do not return status, grrr. echo "grimblepritz" >grimble if grep blurfldyick grimble >/dev/null 2>&1 ; then contains=contains elif grep grimblepritz grimble >/dev/null 2>&1 ; then contains=grep else contains=contains fi rm -f grimble : the following should work in any shell case "$contains" in contains*) echo " " echo "AGH! Grep doesn't return a status. Attempting remedial action." cat >contains <<'EOSS' grep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp EOSS chmod +x contains ;; esac echo "Checking echo to see how to suppress newlines..." (echo "hi there\c" ; echo " ") >.echotmp if $contains c .echotmp >/dev/null 2>&1 ; then n='-n'; c='' else n=''; c='\c' fi rm -f .echotmp echo $n "Type carriage return to continue. Your cursor should be here-->$c" $fastread ans COOL_CF=`echo "$config" | sed -n -e 's/\.sh//p'` TMPFILE=mc$$ trap "rm -f ${TMPFILE}* contains; exit 1 " 1 2 3 5 15 umask 022 # legacy [ -f config.sh ] && { echo " " echo "Found old config.sh file. Renaming to $config..." echo $n "Press the key to continue... $c" $fastread ans echo " " mv config.sh $config } [ -f majorcool.cf.common ] && { echo " " echo "Found old cf.common file. Moving to install directory." echo "You will have to transfer any customizations by hand." echo $n "Press the key to continue... $c" $fastread ans echo " " mv majorcool.cf.common install/majorcool.cf.common.old } [ -x cpset.sh ] && rm cpset.sh [ -x cpset ] && rm cpset # Print an error. Exit if exit value is greater than 0. # Syntax: error value message error() { exitval=$1; shift echo "ERROR: $*" >&2 [ $exitval -gt 0 ] && { rm -f ${TMPFILE}* exit $exitval } } # Compare two versions of a file with various list, select, and edit options. # Syntax: accept_new_file oldfile newfile selection # Return 0 if new version accepted and 1 if not accept_new_file() { _old=$1; _new=$2; _ans=$3 while : ; do case "$_ans" in [Dd]*) { echo "<>"; diff $_old $_new } | ${PAGER:-pg} ;; [Ll]*) ${PAGER:-pg} $_new ;; [Ee]*) ${EDITOR:-vi} $_new ;; [Yy]*) return 0 ;; [Nn]*) return 1 ;; *) cat < ${TMPFILE}B # we know the above var=value pairs in advance # module dependencies are on-the-fly for var in $MODULE_DEPENDENCIES; do sed -e "s;$var;`eval echo \"\\\$${var}\"`;g" ${TMPFILE}B \ > ${TMPFILE}C mv ${TMPFILE}C ${TMPFILE}B done $CPSET ${TMPFILE}B $2 $3 $4 $5 rm -f ${TMPFILE}B return 0 } #---------------------------------------------------------------------------- if [ -r $config ]; then cat < at every prompt. This shell script will use the values from the current configuration as the defaults for this upgrade of the MajorCool software. EOM . ./$config # legacy [ "$CPSET" = "./cpset.sh" ] && CPSET="install/cpset" [ "$CPSET" = "./cpset" ] && CPSET="install/cpset" [ -n "$COOL_USER" ] && COOL_NAME=$COOL_USER else cat < or before continuing echo " " echo $n "Press the key to continue... $c" read ans echo " " fi cat < key to continue... $c" $fastread ans echo " " # Locate the cpset program echo " " echo "Locating programs..." dirs="/bin /usr/bin /sbin /usr/sbin /usr/lbin /usr/local/bin install" for dir in $dirs; do [ -x "$dir/cpset" ] && { CPSET="$dir/cpset" break } done echo "...cpset is $CPSET." for dir in $dirs; do [ -x $dir/rolo ] && { ROLOPROGRAM=$dir/rolo break } done [ -x "$ROLOPROGRAM" ] || ROLOPROGRAM="not found" echo "...rolo is $ROLOPROGRAM." # If the Majordomo config file is present in the "standard" location, # we can use it to tell us some things. if [ -f /etc/majordomo.cf ]; then ans=`grep '$homedir =' /etc/majordomo.cf | sed -n -e '$s/.*"\(.*\)".*/\1/p'` [ "$DOMO_DIR" ] || { [ -n "$ans" ] && DOMO_DIR=$ans } [ "$DOMO_CONF" ] || DOMO_CONF="/etc/majordomo.cf" fi # Set up the majordomo directory cat < attributes) if you tell it where. (Use 'none' to erase the current values) EOM echo "Location of HTML header (if applicable)?" echo $n " [$WEB_HEADER]: $c" $fastread ans [ -n "$ans" ] && WEB_HEADER=$ans [ "$ans" = "none" ] && WEB_HEADER="" echo "Location of HTML footer (if applicable)?" echo $n " [$WEB_FOOTER]: $c" $fastread ans [ -n "$ans" ] && WEB_FOOTER=$ans [ "$ans" = "none" ] && WEB_FOOTER="" [ "$COOL_HELPFILE" ] || COOL_HELPFILE="/mc_${COOL_CF}_help.htm" cat < key to continue... $c" $fastread ans echo " " echo "The mapping functions currently provided include:" echo " " PWD=`pwd` # Determine what address modules are available at this site for module in $PWD/siteaddr/*; do [ -f $module ] || continue #name=`echo $module | sed -e 's;siteaddr/;;g'` name=`basename $module` [ "$name" = "none" ] && continue explain=`grep '^#~' $module | sed -e 's/^#~//g'` echo "o $name - $explain"; echo " " done while : ; do echo "Which address mapping function will you use?" echo $n " [$COOL_SITEADDR]: $c" $fastread ans echo " " [ -n "$ans" ] && COOL_SITEADDR=$ans if [ -f "$PWD/siteaddr/$COOL_SITEADDR" ]; then break else echo "SiteAddress file '$COOL_SITEADDR' not found" COOL_SITEADDR='' fi done require=`grep '^#+' $PWD/siteaddr/$COOL_SITEADDR | sed -e 's/^#+//g'` if [ -n "$require" ]; then echo "Module '$COOL_SITEADDR' has additional dependencies:" for r in $require; do MODULE_DEPENDENCIES="$MODULE_DEPENDENCIES $r" while : ; do echo "What is a value for $r?" echo $n " [`eval echo \"\\\$${r}\"`]: $c" $fastread ans echo " " [ -n "$ans" ] && eval $r=$ans [ "`eval echo \"\\\$${r}\"`" ] && break done done fi else # BROWSE not configured COOL_SITEADDR='none' fi if [ $OPT_ALLOWCREATE -ne 0 ]; then # prompt for list_create_cmd cat <$TMPFILE # Configuration file for MajorCool # These should only be modified through the use of the Configure script # For yes/no values, 0=no, 1=yes # SYSTEM DETAILS # How to start a perl script PERLBIN="$PERLBIN" # The cpset command for installations CPSET="$CPSET" # MAJORDOMO DETAILS # Home directory DOMO_DIR="$DOMO_DIR" # Configuration file location DOMO_CONF="$DOMO_CONF" # Version number DOMO_VERSION="$DOMO_VERSION" # WEB SERVER DETAILS # Server scheme (http, shttp, https) WEB_SCHEME="$WEB_SCHEME" # Server root directory WEB_ROOT="$WEB_ROOT" # CGI directory WEB_CGIDIR="$WEB_CGIDIR" # CGI URL WEB_CGIURL="$WEB_CGIURL" # Images directory WEB_IMGDIR="$WEB_IMGDIR" # Images URL WEB_IMGURL="$WEB_IMGURL" # Root for served documents WEB_DOCROOT="$WEB_DOCROOT" # Header & footer for common site look WEB_HEADER="$WEB_HEADER" WEB_FOOTER="$WEB_FOOTER" # MAJORCOOL CONFIG # The name of this site COOL_SITENAME="$COOL_SITENAME" # The URL of this site's home page COOL_SITEHOME="$COOL_SITEHOME" # TMP directory COOL_TMPDIR="$COOL_TMPDIR" # Location of key cache file COOL_CACHE="$COOL_CACHE" # CGI program name COOL_NAME="$COOL_NAME" # UNIX user/group-id owners COOL_USERID="$COOL_USERID" COOL_GROUPID="$COOL_GROUPID" # Help file for MajorCool COOL_HELPFILE="$COOL_HELPFILE" # The address lookup function to use COOL_SITEADDR="$COOL_SITEADDR" # The programs to invoke on CREATE/RENAME/DELETE COOL_CREATECMD="$COOL_CREATECMD" COOL_RENAMECMD="$COOL_RENAMECMD" COOL_DELETECMD="$COOL_DELETECMD" # MAJORCOOL OPTIONS # Module access OPT_ALLOWBROWSE="$OPT_ALLOWBROWSE" OPT_ALLOWMODIFY="$OPT_ALLOWMODIFY" OPT_ALLOWCREATE="$OPT_ALLOWCREATE" OPT_ALLOWRENAME="$OPT_ALLOWRENAME" OPT_ALLOWDELETE="$OPT_ALLOWDELETE" # Hide list of lists from admins? OPT_HIDDENLISTS="$OPT_HIDDENLISTS" # Admin passwd not in regular config? OPT_HIDDENPASSWD="$OPT_HIDDENPASSWD" # Members see noadvertised lists? OPT_NOADVERTISED="$OPT_NOADVERTISED" # Trust the address that users enter? OPT_TRUSTIDENT="$OPT_TRUSTIDENT" # Use paranoia mode? Sends commands in e-mail... OPT_CMDVERIFY="$OPT_CMDVERIFY" # Send sub/unsub commands in e-mail for user confirmation? OPT_SUBVERIFY="$OPT_SUBVERIFY" # Allow admins to request emailed config? OPT_SENDCF="$OPT_SENDCF" # Save comments in list config file? OPT_COMMENTEDCF="$OPT_COMMENTEDCF" # Use MIME screen update feature if supported? OPT_MULTIPART="$OPT_MULTIPART" # Return to prior screen after Prefs session? OPT_PREFSRETURN="$OPT_PREFSRETURN" # Allow Internet spiders to index this CGI? OPT_ROBOTS="$OPT_ROBOTS" # Update interval during list membership scan. OPT_SCANSTEPS="$OPT_SCANSTEPS" EOF echo "# SITEADDR OPTIONS (may be empty)" >>$TMPFILE for var in $MODULE_DEPENDENCIES; do echo " $var=`eval echo \"\\\$${var}\"`" >>$TMPFILE done # We need to know how to display stuff slowly to the screen. If the # PAGER variable is not set (or cannot be found) then try the sort of # names that make sense as pagers. [ "$PAGER" ] || { for PAGER in pg more less cat; do ( cat /dev/null | $PAGER >/dev/null 2>&1 ) && { echo "PAGER set to $PAGER." break } done } # Ask for or before continuing cat < or key to continue... $c" $fastread ans echo " " if [ -r $config ]; then old=$config else old=/dev/null fi if accept_new_file $old $TMPFILE list; then if cmp -s $old $TMPFILE; then echo "Configuration file has not changed." rm -f $TMPFILE else echo "Writing information to '$config' for later use." $CPSET -o $TMPFILE $config 644 $COOL_USERID $COOL_GROUPID if cmp -s $config OLD$config; then rm -f OLD$config #nothing changed elif [ -r OLD$config ]; then echo "The old configuration is saved as OLD$config." fi fi else cat <$TMPFILE sed_cpset $TMPFILE $DOMO_DIR/majorcool_$COOL_CF.cf 0755 $COOL_USERID $COOL_GROUPID echo "Installing 'majorcool.cgi' as '$WEB_CGIDIR/$COOL_NAME'" sed_cpset majorcool.cgi $WEB_CGIDIR/$COOL_NAME 0755 $COOL_USERID $COOL_GROUPID echo "Installing MajorCool icons in '$WEB_IMGDIR'" for file in `ls icons`; do if [ ! -f icons/$file ]; then continue; fi if cmp -s icons/$file $WEB_IMGDIR/$file; then continue; fi echo "...'icons/$file'..." $CPSET icons/$file $WEB_IMGDIR/$file 0644 $COOL_USERID $COOL_GROUPID done echo "Installing Help file as '$WEB_DOCROOT/$COOL_HELPFILE'" cat install/HelpHeader >$TMPFILE $PERLBIN install/extract INTRO Docs/usage.htm >>$TMPFILE [ $OPT_ALLOWBROWSE -ne 0 ] && { $PERLBIN install/extract BROWSE Docs/usage.htm >>$TMPFILE } [ $OPT_ALLOWMODIFY -ne 0 ] && { $PERLBIN install/extract MODIFY Docs/usage.htm >>$TMPFILE } [ $OPT_ALLOWCREATE -ne 0 ] && { $PERLBIN install/extract CREATE Docs/usage.htm >>$TMPFILE } [ $OPT_ALLOWRENAME -ne 0 ] && { $PERLBIN install/extract RENAME Docs/usage.htm >>$TMPFILE } [ $OPT_ALLOWDELETE -ne 0 ] && { $PERLBIN install/extract DELETE Docs/usage.htm >>$TMPFILE } $PERLBIN install/extract PREFS Docs/usage.htm >>$TMPFILE $PERLBIN install/extract PREFS Docs/config.htm >>$TMPFILE [ -f install/site.info ] && { cat install/site.info >>$TMPFILE } cat install/HelpFooter >>$TMPFILE $PERLBIN -pi -e "s|\.\./icons/|WEB_IMGURL/|g;" $TMPFILE sed_cpset $TMPFILE $WEB_DOCROOT/$COOL_HELPFILE 0644 $COOL_USERID $COOL_GROUPID rm -f ${TMPFILE}* # Now test out the installation to make sure that everything is okay. cat </dev/null || rm $COOL_CACHE } [ -f "$COOL_CACHE" ] || { echo "Creating initial Key Cache file in '$COOL_CACHE'." echo "You will need to automate this process..." set -ex $DOMO_DIR/wrapper mj_key_cache -v -K $COOL_CACHE -C $DOMO_CONF set +ex } fi cat <