Shell Script Application Installation

An application is virtually certain to change design quite drastically from initial conception to launch. A well-conceived shell script that combines the application database schema with the Istarel Workshop Application Framework's object-relational mapping (ORM) tool makes it quite simple to cleanly handle change.

Listing: /iw/install/install.sh

#!/bin/bash
. conf/sh.conf

echo "Deleting database..."
dropdb -U $DATABASE_USER $DATABASE_NAME

echo "Creating database..."
createdb -U $DATABASE_USER --encoding UNICODE --template template0 $DATABASE_NAME

echo "Applying schema..."
psql -q -U $DATABASE_USER -f sql/schema.sql -d $DATABASE_NAME

echo "Import redirects..."
psql -q -U $DATABASE_USER -f sql/redirects.sql -d $DATABASE_NAME

echo "Import application data..."
psql -q -U $DATABASE_USER -f sql/projects.sql -d $DATABASE_NAME
psql -q -U $DATABASE_USER -f sql/categories.sql -d $DATABASE_NAME
psql -q -U $DATABASE_USER -f sql/articles.sql -d $DATABASE_NAME

echo "Creating model object classes..."
$FRAMEWORK_DIR/install/orm_install -n Istarel Workshop -w $WEBROOT_DIR
    -a $PROJECT_DIR --all-relations --with-foreign-keys

The last command invokes the framework ORM tool, which parses the PostgreSQL database and constructs a hierarchy of PHP model object and factory classes to interact with the database.

The configuration file referenced in the installation script defines the executable paths and application-related constants.

Listing: /iw/install/conf/sh.conf

#!/bin/sh

DATABASE_NAME=iw
DATABASE_USER=iwuser
PHP=/opt/local/bin/php
PSQL=/opt/local/lib/postgresql84/bin/psql
WEBROOT_DIR=/Users/markf/Sites
PROJECT_DIR=/iw
FRAMEWORK_DIR=/Users/markf/Sites/fw