#!/bin/sh
# drupal.install - Drupal installer for SDF MOTD project

unset IFS
PATH=/usr/local/bin/:/usr/bin:/bin

srcpath=/sys/motd/drupal/drupal-current
motdpath=$HOME/html/motd
dbhost=ol.sdf.org
dbpasswd=$USER
dbprefix=dru_

cat <<EOF
---------------------------------------------------------------------
Install Drupal on your MOTD Site

This script starts a new[*] Drupal installation on your MOTD site.

The installation process requires the following steps:

1. Create target directory and copy Drupal files (this script)

2. Set Drupal configuration (web-based)

3. Define cron job for update process (use MKCRON)

[*] If target directory contains a previous Drupal installation,
   all files will be OVER-WRITTEN! To upgrade an existing Drupal
   installation, see Drupal documentation.

Press Ctrl-C at any prompt to abort.
---------------------------------------------------------------------

EOF

# 1. Query for installation target

echo "Installation target MOTD subdirectory?"
echo -n "[(install in MOTD site root directory)] "
read motddir
if [ $motddir ]; then
   destpath=$motdpath/$motddir
   desturl=http://$USER.motd.org/$motddir
else
   destpath=$motdpath
   desturl=http://$USER.motd.org
fi

cat <<EOF

Proposed installation target:
Drupal base path:      $destpath
Drupal base URL:       $desturl

EOF

echo -n "Press Enter to install, Ctrl-C to abort: "
read a

# 2. Create target directory if necessary

if [ ! -e $destpath ]; then
   if [ $destpath = $motdpath ]; then
       echo "Error: MOTD base directory does not exist. Aborting."
       exit 1
   else

       mkdir -p $destpath

       if [ ! $? = 0 ]; then
           echo "Error creating directory $destpath. Aborting."
           exit 1
       fi
   fi
elif [ ! -d $destpath ]; then
   echo "Error: $destpath is not a directory. Aborting."
   exit 1
fi

# 3. Copy Drupal files to target directory

cp -fR $srcpath/.htaccess $srcpath/* $destpath/

if [ ! $? = 0 ]; then
   echo "Error copying source files. Aborting."
   exit 1
fi

# 4. Set target directory file permissions

mkhomepg -p

# Next step ...

cat <<EOF

---------------------------------------------------------------------
Drupal shell-based installation complete.

To configure your Drupal installation, access the following URL with
your web browser (See ...):

    $desturl

(Open the "Advanced Options" submenu to set your database configuration.)

Then run at the shell MKCRON and use the CREATE command to create a
cron job for your Drupal's update process.

Recommended cron job parameters are:

| PROMPT                      | INPUT                                            |
|-----------------------------+--------------------------------------------------|
| Enter the full path ...     | /usr/pkg/bin/curl --silent --compressed <URI>[*] |
| What day of the week ...    | (return)                                         |
| What month ...              | (return)                                         |
| What day of the month ...   | (return)                                         |
| What hour of the day ...    | (return)                                         |
| How often ...               | 1                                                |
| What minute of the hour ... | 45                                               |
| Is this ok?                 | y                                                |

Use the SYNC command before exiting MKCRON.

[*] Copy URI from your Drupal web site under Reports > Status report >
   "To run cron from outside the site, go to".

---------------------------------------------------------------------
EOF

exit 0

#$Id: drupal.install,v 1.3 2013/02/11 05:58:49 papa Exp papa $