[med-svn] [openemr] 01/01: Added install, man page, and current pre/post install scripts from Brady Miller's production scripts but won't work due to hard coded dirs.

Ian Wallace iankarlwallace-guest at moszumanska.debian.org
Mon Jun 9 05:56:18 UTC 2014


This is an automated email from the git hooks/post-receive script.

iankarlwallace-guest pushed a commit to branch master
in repository openemr.

commit 3dbdbbd5f76daaba050ce9a8ee3b7ceeaee273b8
Author: Ian Wallace <iankarlwallace at gmail.com>
Date:   Sun Jun 8 22:56:05 2014 -0700

    Added install, man page, and current pre/post install scripts from Brady Miller's production scripts but won't work due to hard coded dirs.
---
 debian/config           |  25 ++
 debian/dirs             |   1 +
 debian/install          |   4 +-
 debian/openemr.8        |  13 ++
 debian/openemr.manpages |   1 +
 debian/postinst         | 605 ++++++++++++++++++++++++++++++++++++++++++++++++
 debian/postrm           |  80 +++++++
 debian/preinst          | 356 ++++++++++++++++++++++++++++
 debian/prerm            | 209 +++++++++++++++++
 debian/rules            |  68 ++----
 debian/templates        | 195 ++++++++++++++++
 11 files changed, 1505 insertions(+), 52 deletions(-)

diff --git a/debian/config b/debian/config
new file mode 100644
index 0000000..41a705a
--- /dev/null
+++ b/debian/config
@@ -0,0 +1,25 @@
+#!/bin/bash -e
+#
+#This program is free software; you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation; either version 2 of the License, or
+#(at your option) any later version.
+#
+# Copyright 2011
+# authors: Brady Miller <brady at sparmy.com>
+#
+# Debian package configure script steps:
+#  1) Collect the mysql root password
+#
+# summary of how this script can be called:
+#        * <config> `configure' <installed-version>
+#        * <config> `reconfigure' <installed-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+# DUMMY CONFIG FILE
+
+# Source debconf library.
+. /usr/share/debconf/confmodule
+
+# Dummy script to allow prompting within other maintainer scripts
diff --git a/debian/dirs b/debian/dirs
new file mode 100644
index 0000000..35c38d8
--- /dev/null
+++ b/debian/dirs
@@ -0,0 +1 @@
+etc/openemr/conf.d
diff --git a/debian/install b/debian/install
index 18e1626..d7aea3b 100644
--- a/debian/install
+++ b/debian/install
@@ -1,3 +1,5 @@
+Documentation									usr/share/doc/openemr
+
 accounting										usr/share/openemr
 acknowledge_license_cert.html	usr/share/openemr
 acl_setup.php									usr/share/openemr
@@ -9,7 +11,6 @@ contrib												usr/share/openemr
 controller.php								usr/share/openemr
 controllers										usr/share/openemr
 custom												usr/share/openemr
-Documentation									usr/share/openemr
 DocumentTreeMenu.js						usr/share/openemr
 images												usr/share/openemr
 includes											usr/share/openemr
@@ -28,4 +29,3 @@ sql_upgrade.php								usr/share/openemr
 templates											usr/share/openemr
 version.php										usr/share/openemr
 
-
diff --git a/debian/openemr.8 b/debian/openemr.8
new file mode 100644
index 0000000..a0767ca
--- /dev/null
+++ b/debian/openemr.8
@@ -0,0 +1,13 @@
+.TH OpenEMR
+.SH NAME
+OpenEMR - A comprehensive Open Source Medical Practice Management Application.
+.SH INSTRUCTIONS
+
+To use OpenEMR, go to http://localhost/openemr :  user is 'admin' and password is 'pass' (recommend changing password after login)
+
+To ensure a consistent look and feel through out the application using Firefox is recommended.
+
+The OpenEMR project home page, wiki (documentation) and forums can be found at http://www.open-emr.org
+
+We pursue grants to help fund the future development of OpenEMR.  To apply for these grants, we need to estimate how many times this program is installed and how many practices are evaluating or using this software.  It would be awesome if you would email us at drbowen at openmedsoftware.org if you have installed this software. The more details about your plans with this software, the better, but even just sending us an email stating you just installed it is very helpful.
+
diff --git a/debian/openemr.manpages b/debian/openemr.manpages
new file mode 100644
index 0000000..1d11083
--- /dev/null
+++ b/debian/openemr.manpages
@@ -0,0 +1 @@
+debian/openemr.8
diff --git a/debian/postinst b/debian/postinst
new file mode 100644
index 0000000..6d34753
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,605 @@
+#!/bin/bash -e
+#
+#This program is free software; you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation; either version 2 of the License, or
+#(at your option) any later version.
+#
+# Copyright 2012
+# authors: Amalu Obinna <amaluobinna at aol.com>
+#          Brady Miller <brady at sparmy.com>
+#
+# Debian package post installation script steps:
+#  1) Collect setting from package configuration file
+#  2) Install or Upgrade
+#    -Install
+#      a) Collect the MySQL root password (if possible)
+#      b) Ensure OpenEMR MySQL database and user do not exist. (if applicable)
+#      c) Configure OpenEMR (if applicable)
+#      d) Configure Apache
+#      e) Configure PHP
+#    -Upgrade
+#      a) Modify new OpenEMR version configuration files
+#      b) Upgrade MySQL database(s)
+#      c) Upgrade Access Controls
+#      d) Copy over old configuration files
+#          (Copy to files with .OLD extension to allow manual comparisons by user)
+#  3) Modify permissions for writable directories
+#  4) Secure the php installation/upgrading scripts (if applicable)
+#  5) Modify the package configuration file
+#  6) Display instructions on starting openemr
+#
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <postinst> `abort-remove'
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+# Source debconf library.
+. /usr/share/debconf/confmodule
+
+case "$1" in
+   configure)
+
+      #constants and paths
+      LOGDIR=/var/log/openemr
+      LOG=$LOGDIR/install
+      CONFIGDIR=/etc/openemr
+      CONFIG=$CONFIGDIR/openemr.conf
+      TMPDIR=/tmp/openemr-tmp
+      WEB=/var/www
+      OPENEMR=$WEB/openemr
+      SITEDIR=$OPENEMR/sites
+      #hardcoded mysql user and database for install (not pertinent for upgrading)
+      # upgrading can use whatever is found in openemr/library/sqlconf.php
+      INSTALL_USER=openemr
+      INSTALL_DATABASE=openemr
+      #auto install scripts
+      INST=$OPENEMR/contrib/util/installScripts/InstallerAuto.php
+      INSTTEMP=$OPENEMR/contrib/util/installScripts/InstallerAutoTemp.php
+      #php and apache files
+      PHP=/etc/php5/apache2/php.ini
+      APACHE=/etc/apache2/httpd.conf
+      #web user and group
+      WEB_GROUP=www-data
+      WEB_USER=www-data
+
+      #Standardized echo function to send to only log file
+      #  requires one parameter (string)
+      log_only () {
+         echo "`date`: $1" >> $LOG
+      }
+
+      #Standardized exit functions to be used
+      #  requires one parameter (string with reason for exiting)
+      unable_exit () {
+         echo "`date`: $1" >> $LOG
+         echo "`date`: EXITING.........." >> $LOG
+         exit 1
+      }
+
+      #function to check mysql for selected databases
+      # 1st param is password, 2nd param database, 3rd param is host (optional), 4th param is user (optional)
+      check_mysql () {
+         if [ -n "$3" ]; then
+            HOST=$3
+         else
+            HOST=localhost
+         fi
+         if [ -n "$4" ]; then
+            USE=$4
+         else
+            USE=root
+         fi
+
+         if [ "`mysql -u "$USE" -h "$HOST" --password="$1" -e 'show databases' 2>/dev/null | awk '{ print $1}' | grep "^$2$"`" == "$2" ]; then
+            return 0
+         else
+            return 1
+         fi
+      }
+
+      #function to collect variables from config files
+      # 1st param is variable name, 2nd param is filename 
+      collect_var () {
+         echo `grep -i "^[[:space:]]*$1[[:space:]=]" $2 | cut -d \= -f 2 | cut -d \; -f 1 | sed "s/[ 	'\"]//gi"`
+      }      
+
+      #function to insert variables into config files
+      # 1st param is variable name, 2nd param is variable, 3rd param is filename
+      insert_var () {
+         sed -i 's@^[ 	]*'"$1"'[ 	=].*$@'"$1"' = '"$2"'@' "$3"
+      }
+
+      #function to prompt for input
+      # 1st param is name, 2nd param is priority, 3rd param is where result gets sent back in
+      # return the input
+      prompt_input () {
+         db_set "$1" ""
+         db_fset "$1" seen false
+         db_input "$2" "$1" || true
+         db_go || true
+         db_get "$1"
+         local input_value="$RET"
+         db_set "$1" ""
+         db_fset "$1" seen false
+         local __result=$3
+         eval $__result="'$input_value'"
+      }
+
+      #collect scripting information from config file
+      PROCESS=$(collect_var process $CONFIG)
+      PLAN=$(collect_var plan $CONFIG)
+
+      #Don't allow re-configuration
+      if [ "$PROCESS" == "complete" ] ; then
+         unable_exit "OpenEMR has already been configured."
+      elif [ "$PROCESS" == "pending" ] ; then
+         #continue with configuration
+         log_only "Configuring package..."
+      else
+         unable_exit "Error reading process variable in configuration file."
+      fi
+
+      if [ "$PLAN" == "upgrade" ] ; then       
+         #continue with upgrade
+         OLD_VERSION=$(collect_var previous_version $CONFIG)
+         log_only "Continuing Upgrade from ($OLD_VERSION)"
+
+         #go to openemr directory
+         cd $OPENEMR
+
+         #To support the multisite module, go through each site
+         for dir in $(find $SITEDIR/* -maxdepth 0 -type d ); do
+            #collect sitename
+            SITENAME=$(basename "$dir")
+            log_only "Configuring Site ($SITENAME)"
+
+            #collect more information from config file
+            SQLLOCATION=$(collect_var ${SITENAME}_sqllocation $CONFIG)
+            SQLUSER=$(collect_var ${SITENAME}_sqluser $CONFIG)
+            SQLPASSWORD=$(collect_var ${SITENAME}_sqlpassword $CONFIG)
+            SQLDATABASE=$(collect_var ${SITENAME}_sqldatabase $CONFIG)
+            SQLUTFFLAG=$(collect_var ${SITENAME}_sqlutfflag $CONFIG)
+
+            #configure database configuration file
+            insert_var "\$host" "\'$SQLLOCATION\';"             $SITEDIR/$SITENAME/sqlconf.php
+            insert_var "\$login" "\'$SQLUSER\';"                $SITEDIR/$SITENAME/sqlconf.php
+            insert_var "\$pass" "\'$SQLPASSWORD\';"             $SITEDIR/$SITENAME/sqlconf.php
+            insert_var "\$dbase" "\'$SQLDATABASE\';"            $SITEDIR/$SITENAME/sqlconf.php
+            insert_var "\$disable_utf8_flag" "$SQLUTFFLAG;"     $SITEDIR/$SITENAME/sqlconf.php
+            sed -i "s/^[   ]*\$config[     =].*0/\$config = 1/" $SITEDIR/$SITENAME/sqlconf.php
+
+            #upgrade the sql database
+            CONC_VERSION=$(echo $OLD_VERSION | cut -d \- -f 1)
+            echo "<?php \$_GET['site'] = '$SITENAME'; ?>" > $OPENEMR/TEMPsql_upgrade.php
+            cat $OPENEMR/sql_upgrade.php >> $OPENEMR/TEMPsql_upgrade.php
+            sed -i "/input type='submit'/d" $OPENEMR/TEMPsql_upgrade.php
+            sed -i "s/!empty(\$_POST\['form_submit'\])/empty(\$_POST\['form_submit'\])/" $OPENEMR/TEMPsql_upgrade.php
+            sed -i "s/^[   ]*\$form_old_version[   =].*$/\$form_old_version = \"$CONC_VERSION\";/" $OPENEMR/TEMPsql_upgrade.php
+            php -f $OPENEMR/TEMPsql_upgrade.php >> $LOG 2>&1
+            rm -f $OPENEMR/TEMPsql_upgrade.php
+
+            #copy the old config file into new with the OLD at end to allow manual configuration of old
+            # optional settings.
+            if [ -d "$TMPDIR/openemr_web_$OLD_VERSION/sites/$SITENAME" ]; then
+              cp -f "$TMPDIR/openemr_web_$OLD_VERSION/sites/$SITENAME/config.php" "$SITEDIR/$SITENAME/config.php.OLD"
+            else
+              #need to move from old location, so sitename will always be default in this case
+              cp -f $TMPDIR/openemr_web_$OLD_VERSION/includes/config.php $SITEDIR/default/config.php.OLD
+            fi
+
+            #log
+            log_only "Upgraded OpenEMR site ($SITENAME) with sql database ($SQLDATABASE) and sql user ($SQLUSER)."
+
+         done
+
+         # if site-specific directories are in the old locations, move them.
+         if [ -d $OPENEMR/documents ]; then
+           if [ "$(ls $OPENEMR/documents)" ]; then
+             mv -f  $OPENEMR/documents/* $SITEDIR/default/documents/
+           fi
+           rm -rf $OPENEMR/documents
+         fi
+         if [ -d $OPENEMR/era ]; then
+           if [ "$(ls $OPENEMR/era)" ]; then
+             mv -f  $OPENEMR/era/* $SITEDIR/default/era/
+           fi
+           rm -rf $OPENEMR/era
+         fi
+         if [ -d $OPENEMR/edi ]; then
+           if [ "$(ls $OPENEMR/edi)" ]; then
+             mv -f  $OPENEMR/edi/* $SITEDIR/default/edi/
+           fi
+           rm -rf $OPENEMR/edi
+         fi
+         if [ -d $OPENEMR/custom/letter_templates ]; then
+           if [ "$(ls $OPENEMR/custom/letter_templates)" ]; then
+             mv -f  $OPENEMR/custom/letter_templates/* $SITEDIR/default/letter_templates/
+           fi
+           rm -rf $OPENEMR/custom/letter_templates
+         fi
+
+         #secure openemr
+         chown -Rf root:root $OPENEMR
+         chmod 600 $OPENEMR/acl_setup.php
+         chmod 600 $OPENEMR/acl_upgrade.php
+         chmod 600 $OPENEMR/sl_convert.php
+         chmod 600 $OPENEMR/setup.php
+         chmod 600 $OPENEMR/sql_upgrade.php
+         chmod 600 $OPENEMR/ippf_upgrade.php
+         chmod 600 $OPENEMR/gacl/setup.php
+
+         #set writable directories (that are not within sites directory)
+         chown -R $WEB_GROUP.$WEB_USER $OPENEMR/library/freeb
+         chown -R $WEB_GROUP.$WEB_USER $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/cache 
+         chown -R $WEB_GROUP.$WEB_USER $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/compiled 
+         chown -R $WEB_GROUP.$WEB_USER $OPENEMR/gacl/admin/templates_c 
+
+         #set writable directories (that are within sites directory)
+         # (go through each site)
+         for dir in $(find $SITEDIR/* -maxdepth 0 -type d ); do
+            #collect sitename
+            SITENAME=$(basename "$dir")
+            #set the writable directories
+            chown -R $WEB_GROUP.$WEB_USER $SITEDIR/$SITENAME/documents
+            chown -R $WEB_GROUP.$WEB_USER $SITEDIR/$SITENAME/edi
+            chown -R $WEB_GROUP.$WEB_USER $SITEDIR/$SITENAME/era
+            chown -R $WEB_GROUP.$WEB_USER $SITEDIR/$SITENAME/letter_templates
+         done
+
+         #update config file, change process to complete and remove others
+         sed -i "s/^[ 	]*process[ 	=].*$/process=complete/" $CONFIG
+         sed -i "/^[ 	]*plan[ 	=].*$/d" $CONFIG
+         sed -i "/^[ 	]*previous_version[ 	=].*$/d" $CONFIG
+         sed -i "/^[ 	]*.*sqllocation[ 	=].*$/d" $CONFIG
+         sed -i "/^[ 	]*.*sqluser[ 	=].*$/d" $CONFIG
+         sed -i "/^[ 	]*.*sqlpassword[ 	=].*$/d" $CONFIG
+         sed -i "/^[ 	]*.*sqldatabase[ 	=].*$/d" $CONFIG
+         sed -i "/^[ 	]*.*sqlutfflag[ 	=].*$/d" $CONFIG
+
+         #done upgrading
+         prompt_input openemr/success_upgrade critical ret_result 
+         log_only "OpenEMR upgrade is complete."
+         log_only "Recommend setting optional configuration settings in:"
+         log_only "$SITEDIR/<sitename>/config.php"
+         log_only "(We have renamed your old configuration files to *.OLD)"
+         log_only "(We recommend you delete the *.OLD files when done)"
+         log_only "We have placed backup of your old OpenEMR in $TMPDIR"
+         log_only "(We recommend you copy this somewhere protected since it"
+         log_only "contains confidential patient information)"
+
+         exit 0
+
+      elif [ "$PLAN" == "install" ] ; then
+         #continue with installation
+         log_only "Installing OpenEMR"
+      else
+         unable_exit "Error reading plan variable in configuration file."
+      fi      
+
+      #collect the mysql root password (if applicable)
+      MPASS=""
+      if check_mysql "$MPASS" "mysql"; then
+         log_only "Passed the mysql check loop"
+      else
+         #the blank initial mysql password didn't work, so prompt for password
+         # (will give 3 chances to provide correct password)
+         COUNTDOWN=1
+         while true; do
+            prompt_input openemr/mysql_p_install_${COUNTDOWN} critical ret_result
+            MPASS="$ret_result"
+            if check_mysql "$MPASS" "mysql"; then
+               #the mysql root password works, so can exit loop
+               log_only "Passed the mysql check loop"
+               break
+            else
+               #the mysql root password did not work
+               if [ "$COUNTDOWN" -ge "3" ]; then
+                  prompt_input openemr/no_configure_mysql_root high ret_result
+                  log_only "Will install OpenEMR, however will not configure OpenEMR. (unable to provide root password)"
+                  break
+               fi
+            fi
+            let "COUNTDOWN += 1"
+         done
+      fi
+
+      #decide whether to configure OpenEMR after it is installed
+      configure_flag=true 
+      if check_mysql "$MPASS" "mysql"; then
+         #before auto configuration, ensure the openemr user and database do not exist
+         # Check for openemr database in mysql, if exist then will not configure
+         if check_mysql "$MPASS" "$INSTALL_DATABASE"; then
+            prompt_input openemr/no_configure_mysql_database high ret_result
+            log_only "Will install OpenEMR, however will not automatically configure OpenEMR. (MySQL database already exists)"
+            configure_flag=false;
+         fi
+         # Check for OpenEMR user in mysql.user, if exist then will not configure
+         USER=$(mysql -s -u root -h localhost --password="$MPASS" -e "SELECT User from mysql.user where User='$INSTALL_USER'")
+         if [ "$USER" == "$INSTALL_USER" ]; then
+            prompt_input openemr/no_configure_mysql_user high ret_result
+            log_only "Will install OpenEMR, however will not automatically configure OpenEMR. (MySQL user already exists)"
+            configure_flag=false;
+         fi
+      else
+         #the mysql root password didn't work, so do not configure OpenEMR
+         log_only "Will install OpenEMR, however will not automatically configure OpenEMR. (root password did not work)"
+         configure_flag=false;
+      fi
+
+      #go to openemr directory
+      cd $OPENEMR
+
+      #secure openemr
+      chown -Rf root:root $OPENEMR
+
+      #INSTALL/CONFIGURE OPENEMR
+      # Install openemr
+      if $configure_flag; then
+         log_only "Installing/Configuring OpenEMR..."
+      else
+         log_only "Installing OpenEMR ..."
+      fi
+
+      # Set file and directory permissions (note use default site directory for new install)
+      chmod 666 $SITEDIR/default/sqlconf.php
+      chown -R $WEB_GROUP.$WEB_USER $SITEDIR/default/documents
+      chown -R $WEB_GROUP.$WEB_USER $SITEDIR/default/edi
+      chown -R $WEB_GROUP.$WEB_USER $SITEDIR/default/era
+      chown -R $WEB_GROUP.$WEB_USER $OPENEMR/library/freeb
+      chown -R $WEB_GROUP.$WEB_USER $SITEDIR/default/letter_templates
+      chown -R $WEB_GROUP.$WEB_USER $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/cache
+      chown -R $WEB_GROUP.$WEB_USER $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/compiled
+      chown -R $WEB_GROUP.$WEB_USER $OPENEMR/gacl/admin/templates_c
+
+      if $configure_flag; then
+         # Create a random password for the openemr mysql user
+         password=$(makepasswd --char=12)
+
+         # openemr installation VARIABLES
+         if [ "$MPASS" == "" ] ; then
+           rootpass="rootpass=BLANK" #MySQL server root password
+         else
+           rootpass="rootpass=$MPASS" #MySQL server root password
+         fi
+         login="login=$INSTALL_USER" #username to MySQL openemr database
+         pass="pass=$password" #password to MySQL openemr database
+         dbname="dbname=$INSTALL_DATABASE" #MySQL openemr database name
+ 
+         # 
+         # Run Auto Installer 
+         #
+         sed -e 's@^exit;@ @' <$INST >$INSTTEMP
+         php -f $INSTTEMP $rootpass $login $pass $dbname >> $LOG 2>&1
+         rm -f $INSTTEMP
+
+         #remove global permission to all setup scripts
+         chmod 600 $OPENEMR/acl_setup.php
+         chmod 600 $OPENEMR/acl_upgrade.php
+         chmod 600 $OPENEMR/sl_convert.php
+         chmod 600 $OPENEMR/setup.php
+         chmod 600 $OPENEMR/sql_upgrade.php
+         chmod 600 $OPENEMR/ippf_upgrade.php
+         chmod 600 $OPENEMR/gacl/setup.php
+
+         log_only "Done configuring OpenEMR"
+      fi
+
+      #This section configures Apache for OpenEMR
+      log_only "Configuring Apache for OpenEMR"
+
+      #Check to ensure the apache configuration files exists
+      if [ -f $APACHE ]; then
+
+         # First, backup the httpd.conf file before modifying
+         cp -f $APACHE $APACHE.BAK
+
+         # Second, append information to secure selected directories in OpenEMR
+         echo "#This is the start of the Apache configuration for OpenEMR." >> $APACHE
+         echo "#Below will secure directories with patient information." >> $APACHE
+         echo "<Directory \"$SITEDIR/*/documents\">" >> $APACHE
+         echo " order deny,allow" >> $APACHE
+         echo " Deny from all" >> $APACHE
+         echo "</Directory>" >> $APACHE
+         echo "<Directory \"$SITEDIR/*/edi\">" >> $APACHE
+         echo " order deny,allow" >> $APACHE
+         echo " Deny from all" >> $APACHE
+         echo "</Directory>" >> $APACHE
+         echo "<Directory \"$SITEDIR/*/era\">" >> $APACHE
+         echo " order deny,allow" >> $APACHE
+         echo " Deny from all" >> $APACHE
+         echo "</Directory>" >> $APACHE
+         echo "#This is the end of the Apache configuration for OpenEMR." >> $APACHE
+
+         #let user know the plan
+         prompt_input openemr/apache_configure high ret_result
+         log_only "Added entries to apache configuration to secure directories with patient information."
+         log_only "Placed backup of your original apache configuration file to $APACHE.BAK"
+
+      else
+         #can't find apache config file, so just echo instructions
+         log_only "We recommend placing below lines into your apache configuration file:"
+         log_only "#This is the start of the Apache configuration for OpenEMR."
+         log_only "#Below will secure directories with patient information."
+         log_only "<Directory \"$SITEDIR/*/documents\">"
+         log_only " order deny,allow"
+         log_only " Deny from all"
+         log_only "</Directory>"
+         log_only "<Directory \"$SITEDIR/*/edi\">"
+         log_only " order deny,allow"
+         log_only " Deny from all"
+         log_only "</Directory>"
+         log_only "<Directory \"$SITEDIR/*/era\">"
+         log_only " order deny,allow"
+         log_only " Deny from all"
+         log_only "</Directory>"
+         log_only "#This is the end of the Apache configuration for OpenEMR."
+      fi
+
+      log_only "Done configuring Apache"
+
+      #This Section edits the php.ini file to accomodate the proper functioning of OpenEMR using php
+      log_only "Configuring PHP for OpenEMR"
+
+      #check to ensure the php configuration file exists
+      if [ -f $PHP ]; then
+         # First, collect php variables
+         collect_php () {
+            echo `grep -i "^[[:space:]]*$1[[:space:]=]" $PHP | cut -d \= -f 2 | cut -d \; -f 1 | sed 's/[ 	M]//gi'`
+         }
+         TAG_TEXT="short_open_tag"
+         TAG=$(collect_php "$TAG_TEXT")
+         EXEC_TEXT="max_execution_time"
+         EXEC=$(collect_php "$EXEC_TEXT")
+         INPUT_TEXT="max_input_time"
+         INPUT=$(collect_php "$INPUT_TEXT")
+         MEM_TEXT="memory_limit"
+         MEM=$(collect_php "$MEM_TEXT")
+         DISP_TEXT="display_errors"
+         DISP=$(collect_php "$DISP_TEXT")
+         LOGG_TEXT="log_errors"
+         LOGG=$(collect_php "$LOGG_TEXT")
+         GLOB_TEXT="register_globals"
+         GLOB=$(collect_php "$GLOB_TEXT")
+         POST_TEXT="post_max_size"
+         POST=$(collect_php "$POST_TEXT")
+         UPLOAD_TEXT="file_uploads"
+         UPLOAD=$(collect_php "$UPLOAD_TEXT")
+         FILESIZE_TEXT="upload_max_filesize"
+         FILESIZE=$(collect_php "$FILESIZE_TEXT")
+         MAXINPUTVARS_TEXT="max_input_vars"
+         MAXINPUTVARS=$(collect_php "$MAXINPUTVARS_TEXT")
+
+         # Second, backup the php.ini file before modifying
+         cp $PHP $PHP.BAK
+
+         # Third, edit the required entries
+         #  Do this in a for loop.
+         #   First iteration will discover the recommended changes
+         #   Second iteration will make the changes (if user request this)
+         FLAG_ON=0
+         process_php () {
+            if [ "$3" -eq "1" ]; then
+               # make rec to php.ini
+               if [ "$FLAG_ON" -eq "0" ]; then
+                  log_only "We changed the following setting(s) in your php configuration file at $PHP :"
+               fi      
+               FLAG_ON=1
+            else
+               # modify php.ini
+               sed -i "s/^[ 	]*$1[ 	=].*$/$1 = $2/" $PHP
+               log_only "Successfully set $1 = $2"  
+            fi
+         }
+         for i in `seq 1 2`; do
+            if [ "$TAG" != "On" ]; then
+               process_php "$TAG_TEXT" "On" $i
+            fi
+            if [ "$EXEC" -lt "60" ]; then
+               process_php "$EXEC_TEXT" "60" $i
+            fi
+            if [ "$INPUT" -lt "90" ]; then
+               process_php "$INPUT_TEXT" "90" $i
+            fi
+            if [ "$MEM" -lt "128" ]; then
+               process_php "$MEM_TEXT" "128M" $i
+            fi
+            if [ "$DISP" != "Off" ]; then
+               process_php "$DISP_TEXT" "Off" $i
+            fi
+            if [ "$LOGG" != "On" ]; then
+               process_php "$LOGG_TEXT" "On" $i
+            fi
+            if [ "$GLOB" != "Off" ]; then
+               process_php "$GLOB_TEXT" "Off" $i
+            fi
+            if [ "$POST" -lt "30" ]; then
+               process_php "$POST_TEXT" "30M" $i
+            fi
+            if [ "$UPLOAD" != "On" ]; then
+               process_php "$UPLOAD_TEXT" "On" $i
+            fi
+            if [ "$FILESIZE" -lt "30" ]; then
+               process_php "$FILESIZE_TEXT" "30M" $i
+            fi
+            if [ "$MAXINPUTVARS" -lt "3000" ]; then
+               process_php "$MAXINPUTVARS_TEXT" "3000" $i
+            fi
+            if [ "$FLAG_ON" -eq "0" ]; then
+              log_only "Your PHP configuration is perfect for OpenEMR."
+              break
+            else
+              if [ "$i" -eq "1" ]; then
+                prompt_input openemr/php_configure high ret_result
+              fi
+            fi
+            if [ "$i" -eq "1" ]; then
+               log_only "(We have placed a backup of your php configuration at $PHP.BAK)"
+            fi
+         done
+      else
+         #can't find php config file, so just echo instructions
+         log_only "We recommend ensuring you have below settings in your php configuration file:"
+         log_only "short_open_tag = On"
+         log_only "max_execution_time = 60"
+         log_only "max_input_time = 90"
+         log_only "memory_limit = 128M"
+         log_only "display_errors = Off"
+         log_only "log_errors = On"
+         log_only "register_globals = Off"
+         log_only "post_max_size = 30M"
+         log_only "file_uploads = On"
+         log_only "upload_max_filesize = 30M"
+         log_only "max_input_vars = 3000"
+         log_only "(note max_input_vars setting only exists since php 5.3.9)"
+      fi
+
+      log_only "Done configuring PHP"
+
+      log_only "Restarting Apache service"
+      invoke-rc.d apache2 restart >> $LOG 2>&1
+
+      if $configure_flag; then
+         prompt_input openemr/success_install_config high ret_result
+         log_only "You can now use OpenEMR by browsing to:"
+         log_only "http://localhost/openemr"
+         log_only "user is 'admin' and password is 'pass'"
+         log_only "See the openemr man page for further instructions:"
+         log_only "type 'man openemr' at command line"
+      else
+         prompt_input openemr/success_install high ret_result
+         log_only "You can now configure OpenEMR by browsing to:"
+         log_only "http://localhost/openemr"
+         log_only "See the openemr man page for further instructions:"
+         log_only "type 'man openemr' at command line"
+      fi
+
+      #update config file, change process to complete and remove plan and pass
+      sed -i "s/^[ 	]*process[ 	=].*$/process=complete/" $CONFIG
+      sed -i "/^[ 	]*plan[ 	=].*$/d" $CONFIG
+
+      #stop db
+      db_stop
+
+      exit 0
+   ;;
+   abort-upgrade|abort-remove|abort-deconfigure)
+   
+      echo "postinst asked to do $1"
+      exit 0
+   ;;
+   *)
+      echo "postinst called with unknown argument \`$1'" >&2
+      exit 1
+   ;;
+esac
+
+sleep 5
+exit 0
diff --git a/debian/postrm b/debian/postrm
new file mode 100644
index 0000000..48961d7
--- /dev/null
+++ b/debian/postrm
@@ -0,0 +1,80 @@
+#!/bin/bash -e
+#
+#This program is free software; you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation; either version 2 of the License, or
+#(at your option) any later version.
+#
+# Copyright 2011
+# authors: Amalu Obinna <amaluobinna at aol.com>
+#          Brady Miller <brady at sparmy.com>
+#
+# Un-install script steps:
+#  1) Remove OpenEMR log directory
+#
+# summary of how this script can be called:
+#        * <postrm> `remove'
+#        * <postrm> `purge'
+#        * <old-postrm> `upgrade' <new-version>
+#        * <new-postrm> `failed-upgrade' <old-version>
+#        * <new-postrm> `abort-install'
+#        * <new-postrm> `abort-install' <old-version>
+#        * <new-postrm> `abort-upgrade' <old-version>
+#        * <disappearer's-postrm> `disappear' <overwriter>
+#          <overwriter-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+#
+
+# Source debconf library.
+. /usr/share/debconf/confmodule
+
+#constants
+
+LOGDIR=/var/log/openemr
+
+case "$1" in
+   remove)
+      #remove log directory
+      rm -rf $LOGDIR
+      # Remove db prompt stuff.
+      db_purge
+      exit 0
+   ;;
+
+   purge)
+      echo "postrm asked to do purge"
+      exit 0
+   ;;
+
+   upgrade)
+      #echo "No need for upgrade instructions in postrm script to version $2"
+      exit 0
+   ;;
+
+   failed-upgrade)
+      echo "postrm asked to do failed-upgrade from version $2"
+      exit 0
+   ;;
+
+   abort-install)
+      echo "postrm asked to do abort-install"
+      exit 0
+   ;;
+
+   abort-upgrade)
+      echo "postrm asked to do abort-upgrade from version $2"
+      exit 0
+   ;;
+
+
+   disappear)
+      echo "postrm asked to do disappear"
+      exit 0
+   ;;
+
+   *)
+      echo "postrm called with unknown argument \`$1'" >&2
+      exit 1
+   ;;
+esac
diff --git a/debian/preinst b/debian/preinst
new file mode 100644
index 0000000..9d8bf92
--- /dev/null
+++ b/debian/preinst
@@ -0,0 +1,356 @@
+#!/bin/bash -e
+#
+#This program is free software; you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation; either version 2 of the License, or
+#(at your option) any later version.
+#
+# Copyright 2013
+# authors: Amalu Obinna <amaluobinna at aol.com>
+#          Brady Miller <brady at sparmy.com>
+#
+# Debian package pre-installation script steps:
+#  1) Create log file
+#  2) New install or Upgrade
+#    -Install
+#      a) If OpenEMR web directory already exist, then attempt an upgrade.
+#    -Upgrade (also works for multisite module, so can be mutliple databases)
+#      a) Ensure OpenEMR web directory does exist
+#      b) Collect package version and ensure appropriate upgrade
+#      c) Collect webpath and sql settings from current version
+#      d) Verify the mysql user(s)/database(s) exist
+#      e) Backup the current version mysql database(s)
+#      f) Backup the current version web folder
+#      g) Clear the cache directories in current version    
+#  3) Create config file
+#
+#  Output log file:
+#   /var/log/openemr/install
+#
+#
+# summary of how this script can be called:
+#        * <new-preinst> `install'
+#        * <new-preinst> `install' <old-version>
+#        * <new-preinst> `upgrade' <old-version>
+#        * <old-preinst> `abort-upgrade' <new-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+# Source debconf library.
+. /usr/share/debconf/confmodule
+
+#constants and paths
+LOGDIR=/var/log/openemr
+LOG=$LOGDIR/install
+CONFIGDIR=/etc/openemr
+CONFIG=$CONFIGDIR/openemr.conf
+TMPDIR=/tmp/openemr-tmp
+WEB=/var/www
+OPENEMR=$WEB/openemr
+SITEDIR=$OPENEMR/sites
+#hardcoded mysql user and database for install (not pertinent for upgrading)
+# upgrading can use whatever is found in openemr/library/sqlconf.php
+INSTALL_USER=openemr
+INSTALL_DATABASE=openemr
+
+#Standardized echo function to send to only log file
+#  requires one parameter (string)
+log_only () {
+   echo "`date`: $1" >> $LOG
+}
+
+#Standardized exit function to be used when unable to install the openemr package
+#  requires one parameter (string with reason for exiting)
+unable_exit () {
+   echo "`date`: $1" >> $LOG
+   echo "`date`: EXITING.........." >> $LOG
+   exit 1
+}
+
+#function to prompt for input
+# 1st param is name, 2nd param is priority, 3rd param is where result gets sent back in
+# return the input
+prompt_input () {
+   db_set "$1" ""
+   db_fset "$1" seen false
+   db_input "$2" "$1" || true
+   db_go || true
+   db_get "$1"
+   local input_value="$RET"
+   db_set "$1" ""
+   db_fset "$1" seen false
+   local __result=$3
+   eval $__result="'$input_value'"
+}
+
+#function to check mysql for selected databases
+# 1st param is password, 2nd param database, 3rd param is host (optional), 4th param is user (optional)
+check_mysql () {
+   if [ -n "$3" ]; then
+      HOST=$3
+   else
+      HOST=localhost
+   fi
+   if [ -n "$4" ]; then
+      USE=$4
+   else
+      USE=root
+   fi
+
+   if [ "`mysql -u "$USE" -h "$HOST" --password="$1" -e 'show databases' 2>/dev/null | awk '{ print $1}' | grep "^$2$"`" == "$2" ]; then
+      return 0
+   else
+      return 1
+   fi
+}
+
+#function to collect variables from config files
+# 1st param is variable name, 2nd param is filename 
+collect_var () {
+   echo `grep -i "^[[:space:]]*$1[[:space:]=]" $2 | cut -d \= -f 2 | cut -d \; -f 1 | sed "s/[ 	'\"]//gi"`
+}
+
+#function to check database before preparing to upgrade
+# 1st param is the directory of database configuration script
+# no return, but will exit the upgrade if database check fails
+upgrade_check_database () {
+
+   #Collect the path of database configuration script
+   DATABASE_PATH="$1"
+
+   #Collect variables
+   SQL_LOCATION=$(collect_var \$host $DATABASE_PATH/sqlconf.php)
+   SQL_USER=$(collect_var \$login $DATABASE_PATH/sqlconf.php)
+   SQL_PASSWORD=$(collect_var \$pass $DATABASE_PATH/sqlconf.php)
+   SQL_DATABASE=$(collect_var \$dbase $DATABASE_PATH/sqlconf.php)
+
+   #ensure the mysql database and user exist
+   if check_mysql "$SQL_PASSWORD" "$SQL_DATABASE" "$SQL_LOCATION" "$SQL_USER"; then
+      log_only "For upgrade, confirmed that the mysql database ($SQL_DATABASE) and mysql user ($SQL_USER) exist"
+   else
+      prompt_input openemr/upgrade_not_database critical ret_result
+      unable_exit "MySQL '$SQL_DATABASE' database does not exist (or can't be accessed), unable to upgrade."
+   fi
+}
+
+#function to process database to prepare for upgrade
+# 1st param is the directory of database configuration script
+# 2nd param is the sitename
+# returns(via echo) pertinent configuration file information
+upgrade_prepare_database () {
+
+   #Collect the path of database configuration script
+   DATABASE_PATH="$1"
+
+   #Collect the site name
+   SITE_NAME="$2"
+
+   #Collect variables
+   SQL_LOCATION=$(collect_var \$host $DATABASE_PATH/sqlconf.php)
+   SQL_USER=$(collect_var \$login $DATABASE_PATH/sqlconf.php)
+   SQL_PASSWORD=$(collect_var \$pass $DATABASE_PATH/sqlconf.php)
+   SQL_DATABASE=$(collect_var \$dbase $DATABASE_PATH/sqlconf.php)
+   SQL_UTFFLAG=$(collect_var \$disable_utf8_flag $DATABASE_PATH/sqlconf.php)
+
+   #if SQLUTFFLAG variable is empty, then make it false
+   if [ "$SQL_UTFFLAG" == "" ]; then
+      SQL_UTFFLAG="false"
+   fi
+
+   #write variables to config file string
+   TEMP_SETTING=""
+   TEMP_SETTING=$TEMP_SETTING$SITE_NAME"_sqllocation=$SQL_LOCATION\n"
+   TEMP_SETTING=$TEMP_SETTING$SITE_NAME"_sqluser=$SQL_USER\n"
+   TEMP_SETTING=$TEMP_SETTING$SITE_NAME"_sqlpassword=$SQL_PASSWORD\n"
+   TEMP_SETTING=$TEMP_SETTING$SITE_NAME"_sqldatabase=$SQL_DATABASE\n"
+   TEMP_SETTING=$TEMP_SETTING$SITE_NAME"_sqlutfflag=$SQL_UTFFLAG\n"
+
+   #create the tmp sql directory
+   mkdir -p "$TMPDIR/openemr_mysql_${OLD_VERSION}_${SITE_NAME}"
+
+   #backup mysql database to tmp
+   mysqldump -u "$SQL_USER" -h "$SQL_LOCATION" --password="$SQL_PASSWORD" "$SQL_DATABASE" > "$TMPDIR/openemr_mysql_${OLD_VERSION}_${SITE_NAME}/openemr_mysql_${OLD_VERSION}_${SITE_NAME}.sql"
+
+   #return the settings (to be used for the config file passed to postinst
+   echo $TEMP_SETTING
+}
+
+#function to hold the upgrade code (allow more flexible upgrading)
+# 1st param is the previous version,
+# 2nd param is whether raw or package upgrade
+upgrade_function () {
+
+      #Check for /var/www/openemr. If does not exist, then exit.
+      if ! [ -d "$OPENEMR" ]; then
+         prompt_input openemr/upgrade_not_installed critical ret_result
+         unable_exit "OpenEMR is not installed ($OPENEMR), so can not upgrade the OpenEMR Package."
+      fi
+
+      #collect previous version
+      OLD_VERSION=$1
+
+      #collect type of upgrade (either package or raw)
+      UPGRADETYPE=$2
+
+      #ensure version is appropriate for upgrade (if not, then exit!!)
+      #
+      # ONLY acceptable for raw is 3.0.0 or 3.0.0.1 or 3.1.0 (need to convert these)
+      #
+      if [ "$UPGRADETYPE" == "raw" ]; then
+         if [ "$OLD_VERSION" == "3.0.0" ]; then
+            OLD_VERSION="3.0.1-1"
+         elif [ "$OLD_VERSION" == "3.0.0.1" ]; then
+            OLD_VERSION="3.0.1-1"
+         elif [ "$OLD_VERSION" == "3.0.1" ]; then
+            OLD_VERSION="3.0.1-1"
+         elif [ "$OLD_VERSION" == "3.1.0" ]; then
+            OLD_VERSION="3.1.0-1" 
+         elif [ "$OLD_VERSION" == "3.2.0" ]; then
+            OLD_VERSION="3.2.0-1"
+         elif [ "$OLD_VERSION" == "3.2.0.1" ]; then
+            OLD_VERSION="3.2.0-1"
+         elif [ "$OLD_VERSION" == "4.0.0" ]; then
+            OLD_VERSION="4.0.0-1"
+         elif [ "$OLD_VERSION" == "4.1.0" ]; then
+            OLD_VERSION="4.1.0-1"
+         elif [ "$OLD_VERSION" == "4.1.1" ]; then
+            OLD_VERSION="4.1.1-1"
+         else
+            prompt_input openemr/upgrade_not_supported critical ret_result
+            unable_exit "Unable to upgrade from $OLD_VERSION version package with $UPGRADETYPE method, so can not upgrade the OpenEMR Package."
+         fi
+      fi
+      #
+      # ONLY acceptable package and converted raw is 3.0.1-1 or 3.1.0-1 or 3.2.0-1 or 4.0.0-1 or 4.1.0-1 or 4.1.1-1
+      #
+      if [ "$OLD_VERSION" != "3.0.1-1" ] && [ "$OLD_VERSION" != "3.1.0-1" ] && [ "$OLD_VERSION" != "3.2.0-1" ] && [ "$OLD_VERSION" != "4.0.0-1" ] && [ "$OLD_VERSION" != "4.1.0-1" ] && [ "$OLD_VERSION" != "4.1.1-1" ]; then
+         prompt_input openemr/upgrade_not_supported critical ret_result
+         unable_exit "Unable to upgrade from $OLD_VERSION version package with $UPGRADETYPE method, so can not upgrade the OpenEMR Package."
+      fi
+
+      #Initiate the config file string, which will pass info to postinst script
+      #to continue upgrade process.
+      SETTING="#Optional settings\n\
+#(currently empty, plan to use in subsequent versions of OpenEMR)\n\
+\n\
+#Installation settings\n\
+# (DO NOT EDIT below!!!)\n\
+process=pending\n\
+plan=upgrade\n\
+previous_version=$OLD_VERSION\n"
+
+      #collect openemr mysql data
+      #(will need to look in sites directory if 4.0 or later)
+      #Also supports multisite module, which can have multiple separate databases
+      if [ "$OLD_VERSION" == "3.0.1-1" ] || [ "$OLD_VERSION" == "3.1.0-1" ] || [ "$OLD_VERSION" == "3.2.0-1" ]; then
+
+         #check database (will exit upgrade if check fails)
+         upgrade_check_database $OPENEMR/library
+
+         #Prepare uprade of database and collect settings that will placed in the config file string
+         DATABASE_CONFIG=$(upgrade_prepare_database $OPENEMR/library default)
+         SETTING=$SETTING$DATABASE_CONFIG
+
+      else
+         for dir in $(find $SITEDIR/* -maxdepth 0 -type d ); do
+            #collect sitename
+            SITENAME=$(basename "$dir")
+
+            #check database (will exit upgrade if check fails)
+            upgrade_check_database $SITEDIR/$SITENAME
+
+            #Prepare uprade of database and collect settings that will placed in the config file string
+            DATABASE_CONFIG=$(upgrade_prepare_database $SITEDIR/$SITENAME $SITENAME)
+            SETTING=$SETTING$DATABASE_CONFIG
+         done
+      fi
+
+      #create the tmp web directory
+      mkdir -p $TMPDIR/openemr_web_$OLD_VERSION
+
+      #backup web directory to tmp
+      cp -fr $OPENEMR/* $TMPDIR/openemr_web_$OLD_VERSION/
+
+      #clear the temporary openemr cache directories (no need to keep these during upgrade)
+      rm -fr $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/compiled/*
+      rm -fr $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/cache/*
+      rm -fr $OPENEMR/gacl/admin/templates_c/*
+
+      log_only "Upgrading OpenEMR from $OLD_VERSION..."
+
+      #Create the config file, which will pass info to postinst script
+      #to continue upgrade process.
+      mkdir -p $CONFIGDIR
+      echo -e $SETTING > $CONFIG
+}
+
+
+case "$1" in
+   install)
+
+      #create the log file directory
+      mkdir -p $LOGDIR
+
+      #Check for /var/www/openemr, if exist then see if upgrade is possible
+      if [ -d "$OPENEMR" ]; then
+
+         #collect current version
+         #(for post-4.0 release will need to look in version.php file for version)
+         #(for post-4.0 release will need to use v_tag rather than tag)
+         #(if version.php exists then look there, otherwise get from globals)
+         if [ -e "$OPENEMR/version.php" ]; then
+            v1=$(collect_var \$v_major $OPENEMR/version.php)
+            v2=$(collect_var \$v_minor $OPENEMR/version.php)
+            v3=$(collect_var \$v_patch $OPENEMR/version.php)
+            v4=$(collect_var \$v_tag $OPENEMR//version.php)
+         else
+            v1=$(collect_var \$v_major $OPENEMR/interface/globals.php)
+            v2=$(collect_var \$v_minor $OPENEMR/interface/globals.php)
+            v3=$(collect_var \$v_patch $OPENEMR/interface/globals.php)
+            v4=$(collect_var \$tag $OPENEMR/interface/globals.php)
+         fi
+         RAWVERSION="$v1.$v2.$v3$v4"
+
+         #attempt upgrade, if user desires
+         prompt_input openemr/upgrade_confirm critical ret_result
+         if [ "$ret_result" == "no" ]; then
+            prompt_input openemr/upgrade_no critical ret_result
+            unable_exit "You have chosen to not install the OpenEMR package."
+         fi
+         upgrade_function $RAWVERSION "raw"
+
+         exit 0
+      fi
+
+      #Create the config file to pass to the postinst script 
+      # to signal that this is a new install
+      SETTING="#Optional settings\n\
+#(currently empty, plan to use in subsequent versions of OpenEMR)\n\
+\n\
+#Installation settings\n\
+# (DO NOT EDIT below!!!)\n\
+process=pending\n\
+plan=install"
+      mkdir -p $CONFIGDIR
+      echo -e $SETTING > $CONFIG
+
+      exit 0
+   ;;
+
+   upgrade)
+
+      upgrade_function $2 "package"
+
+      exit 0
+   ;;
+
+   abort-upgrade)
+      echo "preinst asked to do abort-upgrade"
+      exit 0
+   ;;
+
+   *)
+      echo "preinst called with unknown argument \`$1'" >&2
+      exit 1
+   ;;
+esac
diff --git a/debian/prerm b/debian/prerm
new file mode 100644
index 0000000..dba3ddd
--- /dev/null
+++ b/debian/prerm
@@ -0,0 +1,209 @@
+#!/bin/bash -e
+#
+#This program is free software; you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation; either version 2 of the License, or
+#(at your option) any later version.
+#
+# Copyright 2012
+# authors: Amalu Obinna <amaluobinna at aol.com>
+#          Brady Miller <brady at sparmy.com>
+#
+# Un-install script steps:
+#  1) Warn and confirm the user wants to remove the package (mandatory)
+#  2) Collect the MySQL root user password (mandatory)
+#  3) Remove openemr MySQL database(s)
+#  4) Remove openemr MySQL user(s)
+#  5) Remove OpenEMR etc directory
+#  6) Remove rest of OpenEMR web directory
+#  7) Remove tmp directory
+#  8) Remove OpenEMR apache configuration
+#
+#
+# summary of how this script can be called:
+#        * <prerm> `remove'
+#        * <old-prerm> `upgrade' <new-version>
+#        * <new-prerm> `failed-upgrade' <old-version>
+#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
+#        * <deconfigured's-prerm> `deconfigure' `in-favour'
+#          <package-being-installed> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+# Source debconf library.
+. /usr/share/debconf/confmodule
+
+case "$1" in
+   remove)
+
+      #constants and paths
+      LOGDIR=/var/log/openemr
+      LOG=$LOGDIR/install
+      CONFIGDIR=/etc/openemr
+      CONFIG=$CONFIGDIR/openemr.conf
+      TMPDIR=/tmp/openemr-tmp
+      WEB=/var/www
+      OPENEMR=$WEB/openemr
+      SITEDIR=$OPENEMR/sites
+
+      #Standardized echo function to send to only log file
+      #  requires one parameter (string)
+      log_only () {
+         echo "`date`: $1" >> $LOG
+      }
+
+      #Standardized exit function to be used when unable to uninstall the
+      #openemr package
+      #  requires one parameter (string with reason for exiting)
+      unable_exit () {
+         echo "`date`: $1" >> $LOG
+         echo "`date`: EXITING.........." >> $LOG
+         exit 1
+      }
+
+      #function to check mysql for selected databases
+      # 1st param is password, 2nd param database, 3rd param is host (optional), 4th param is user (optional)
+      check_mysql () {
+         if [ -n "$3" ]; then
+            HOST=$3
+         else
+            HOST=localhost
+         fi
+         if [ -n "$4" ]; then
+            USE=$4
+         else
+            USE=root
+         fi
+
+         if [ "`mysql -u "$USE" -h "$HOST" --password="$1" -e 'show databases' 2>/dev/null | awk '{ print $1}' | grep "^$2$"`" == "$2" ]; then
+            return 0
+         else
+            return 1
+         fi
+      }
+
+      #function to collect variables from config files
+      # 1st param is variable name, 2nd param is filename 
+      collect_var () {
+         echo `grep -i "^[[:space:]]*$1[[:space:]=]" $2 | cut -d \= -f 2 | cut -d \; -f 1 | sed "s/[ 	'\"]//gi"`
+      }
+
+      #function to prompt for input
+      # 1st param is name, 2nd param is priority, 3rd param is where result gets sent back in
+      # return the input
+      prompt_input () {
+         db_set "$1" ""
+         db_fset "$1" seen false
+         db_input "$2" "$1" || true
+         db_go || true
+         db_get "$1"
+         local input_value="$RET"
+         db_set "$1" ""
+         db_fset "$1" seen false
+         local __result=$3
+         eval $__result="'$input_value'"
+      }
+
+      #Confirm that user really wants to uninstall
+      prompt_input openemr/confirm_remove critical ret_result
+      if [ "$ret_result" == "no" ]; then
+         unable_exit "You have chosen to not uninstall the OpenEMR package."
+      fi
+
+      #collect the mysql root password
+      MPASS=""
+      if check_mysql "$MPASS" "mysql"; then
+         log_only "Passed the mysql check loop"
+      else
+         #the blank initial mysql password didn't work, so prompt for password
+         # (will give 3 chances to provide correct password)
+         COUNTDOWN=1
+         while true; do
+            prompt_input openemr/mysql_p_remove_${COUNTDOWN} critical ret_result
+            MPASS="$ret_result"
+            if check_mysql "$MPASS" "mysql"; then
+               #the mysql root password works, so can exit loop
+               log_only "Passed the mysql check loop"
+               break
+            else
+               #the mysql root password did not work
+               if [ "$COUNTDOWN" -ge "3" ]; then
+                  prompt_input openemr/unable_remove critical ret_result
+                  unable_exit "OpenEMR removal attempt failed (can try again when you know the mysql root password)"
+               fi
+            fi
+            let "COUNTDOWN += 1"
+         done
+      fi
+
+      #collect scripting information from config file
+      PROCESS=$(collect_var process $CONFIG)
+      PLAN=$(collect_var plan $CONFIG)
+
+      for dir in $(find $SITEDIR/* -maxdepth 0 -type d ); do
+         #collect sitename
+         SITENAME=$(basename "$dir")
+
+         # Collect database information from sqlconf.php file
+         SQLLOCATION=$(collect_var \$host $SITEDIR/$SITENAME/sqlconf.php)
+         SQLUSER=$(collect_var \$login $SITEDIR/$SITENAME/sqlconf.php)
+         SQLPASSWORD=$(collect_var \$pass $SITEDIR/$SITENAME/sqlconf.php)
+         SQLDATABASE=$(collect_var \$dbase $SITEDIR/$SITENAME/sqlconf.php)
+
+         #remove openemr mysql database (ensure the database exists)
+         if check_mysql "$MPASS" "$SQLDATABASE"; then
+            mysqladmin -f -u root -h "$SQLLOCATION" --password="$MPASS" drop "$SQLDATABASE" >> $LOG 2>&1
+            log_only "Removed OpenEMR MySQL database: $SQLDATABASE"
+         fi
+
+         #remove openemr mysql user
+         mysql -f -u root -h "$SQLLOCATION" --password="$MPASS" -e "DELETE FROM mysql.user WHERE User = '$SQLUSER';FLUSH PRIVILEGES;" >> $LOG 2>&1
+         log_only "Removed OpenEMR MySQL user: $SQLUSER"
+      done
+
+      #remove etc directory
+      rm -rf $CONFIGDIR
+      log_only "Removed OpenEMR etc directory"
+
+      #remove rest of web directory
+      rm -rf $OPENEMR
+      log_only "Finished removing OpenEMR web directory"
+
+      #remove tmp directory
+      sudo rm -fr $TMPDIR
+      log_only "Removed OpenEMR tmp directory"
+
+      #removes the configuration section for OpenEMR in Apache config file
+      sed -i '/#This is the start of the Apache configuration for OpenEMR./,/#This is the end of the Apache configuration for OpenEMR./d' /etc/apache2/httpd.conf
+      log_only "Removed OpenEMR Apache configuration"
+
+      #stop db
+      db_stop
+
+      exit 0
+   ;;
+
+   upgrade)
+
+      #echo "No need for upgrade instructions in prerm script to version $2"
+      exit 0
+   ;;
+
+   deconfigure)
+
+      echo "prerm asked to do deconfigure"
+      exit 0
+   ;;
+
+   failed-upgrade)
+
+      echo "prerm asked to do failed-upgrade from version $2"
+      exit 0
+   ;;
+
+   *)
+      echo "prerm called with unknown argument \`$1'" >&2
+      exit 1
+   ;;
+esac
diff --git a/debian/rules b/debian/rules
index ea1dea6..c112b43 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,51 +1,19 @@
 #!/usr/bin/make -f
-# OpenEMR rules - uncomment next two lines for debug information
-export DH_VERBOSE=1
-export DH_OPTIONS=-v
-
-build-arch:
-
-build: build-indep
-build-indep: build-stamp
-build-stamp:
-	dh_testdir
-	# place building of documentation here
-	touch build-stamp
-
-clean: 
-	dh_testdir
-	dh_testroot
-	rm -f build-stamp
-	dh_clean 
-	# debconf-updatepo <<-- We should really translate the package stuff into some other languages than English but haven't done it yet 
-
-install: build
-	dh_testdir
-	dh_testroot
-	dh_prep
-	dh_installdirs
-	dh_install
-
-# Build architecture-independent files here.
-binary-indep: build install
-	dh_testdir
-	dh_testroot
-	dh_installchangelogs
-	dh_installdocs
-	dh_installexamples
-	dh_installdebconf	
-	dh_installman
-	dh_lintian
-	dh_link
-	dh_compress
-	dh_fixperms
-	dh_installdeb
-	dh_gencontrol
-	dh_md5sums
-	dh_builddeb
-
-# Build architecture-dependent files here.
-binary-arch:
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install
+# OpenEMR rules - Adapted from http://anonscm.debian.org/viewvc/debian-med/trunk/package_template/rules?view=markup
+#
+DH_VERBOSE := 1
+DH_OPTIONS := -v
+#DEBVERS := $(shell dpkg-parsechangelog | awk '/^Version:/ {print $$2}')
+#VERSION := $(shell echo '$(DEBVERS)' | sed -e 's/^[0-9]*://' -e 's/-.*//')
+#DEBFLAVOR := $(shell dpkg-parsechangelog | awk '/^Distribution:/ {print $$2}')
+#DEBPKGNAME := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}')
+#DEBIAN_BRANCH := $(shell awk 'BEGIN{FS="[= ]+"} /debian-branch/ {print $$2}' debian/gbp.conf)
+#GIT_TAG := $(subst ~,_,$(VERSION))
+	
+# alternatively to manually set those variables you can
+# include /usr/share/cdbs/1/rules/buildvars.mk
+# and use what is set there. Any hint whether dh might set variables in
+# a similar manner are welcome.
+	
+%:
+	dh $@
diff --git a/debian/templates b/debian/templates
new file mode 100644
index 0000000..ca7ab6f
--- /dev/null
+++ b/debian/templates
@@ -0,0 +1,195 @@
+Template: openemr/mysql_p_install_1
+Type: string
+Description: MySQL Root Password:
+ If you enter the correct MySQL root password,
+ then OpenEMR will be installed and automatically
+ configured.
+ .
+ If you do not enter the correct MySQL root password,
+ then OpenEMR will be installed, but will not be
+ automatically configured.
+ .
+ You will be given 3 attempts to answer this question.
+ This is your first attempt.
+
+Template: openemr/mysql_p_install_2
+Type: string
+Description: MySQL Root Password:
+ If you enter the correct MySQL root password,
+ then OpenEMR will be installed and automatically
+ configured.
+ .
+ If you do not enter the correct MySQL root password,
+ then OpenEMR will be installed, but will not be
+ automatically configured.
+ .
+ You will be given 3 attempts to answer this question.
+ This is your second attempt.
+
+Template: openemr/mysql_p_install_3
+Type: string
+Description: MySQL Root Password:
+ If you enter the correct MySQL root password,
+ then OpenEMR will be installed and automatically
+ configured.
+ .
+ If you do not enter the correct MySQL root password,
+ then OpenEMR will be installed, but will not be
+ automatically configured.
+ .
+ You will be given 3 attempts to answer this question.
+ This is your last attempt.
+
+Template: openemr/mysql_p_remove_1
+Type: string
+Description: MySQL Root Password:
+ In order to remove this package, you need to enter
+ the correct MySQL root password.
+ .
+ You will be given 3 attempts to answer this question.
+ This is your first attempt.
+
+Template: openemr/mysql_p_remove_2
+Type: string
+Description: MySQL Root Password:
+ In order to remove this package, you need to enter
+ the correct MySQL root password.
+ .
+ You will be given 3 attempts to answer this question.
+ This is your second attempt.
+
+Template: openemr/mysql_p_remove_3
+Type: string
+Description: MySQL Root Password:
+ In order to remove this package, you need to enter
+ the correct MySQL root password.
+ .
+ You will be given 3 attempts to answer this question.
+ This is your last attempt.
+
+Template: openemr/upgrade_confirm
+Type: select
+Choices: yes, no
+Description: Attempt OpenEMR Upgrade?
+ Found a version of OpenEMR at /var/www/openemr.
+ Do you want to attempt an upgrade (ensure you have
+ a backup before proceeding)?
+
+Template: openemr/confirm_remove
+Type: select
+Choices: no, yes
+Description: Confirm OpenEMR Removal?
+ Are you sure you really want to remove the OpenEMR package?
+ All OpenEMR data will be removed if you remove this package!
+
+Template: openemr/upgrade_no
+Type: note
+Description: NOTICE
+ You have chosen to not install the OpenEMR package.
+
+Template: openemr/no_configure_mysql_root
+Type: note
+Description: NOTICE
+ OpenEMR is going to be installed, however it will
+ not be automatically configured (because you did not
+ provide the MySQL root password).
+
+Template: openemr/no_configure_mysql_database
+Type: note
+Description: NOTICE
+ OpenEMR is going to be installed, however it will
+ not be automatically configured (because a openemr
+ MySQL database already exists).
+
+Template: openemr/no_configure_mysql_user
+Type: note
+Description: NOTICE
+ OpenEMR is going to be installed, however it will
+ not be automatically configured (because a openemr
+ MySQL user already exists).
+
+Template: openemr/apache_configure
+Type: note
+Description: NOTICE
+ Entries have been added to your apache configuration
+ to secure directories with patient information. Placed
+ backup of your original apache configuration file to
+ /etc/apache2/httpd.conf.BAK .
+
+Template: openemr/php_configure
+Type: note
+Description: NOTICE
+ To ensure compatibility with php, settings have been
+ modified in your php configuration file, and a backup
+ of your original php configuration file has been placed
+ at /etc/php5/apache2/php.ini.BAK . For more information
+ on the php settings that have been modified, please see
+ the log file for more information after the installation
+ is complete, /var/log/openemr/install .
+
+Template: openemr/success_install
+Type: note
+Description: CONGRATULATIONS
+ OpenEMR has been successfully installed.
+ .
+ You can now set up OpenEMR by browsing
+ to: http://localhost/openemr
+
+Template: openemr/success_install_config
+Type: note
+Description: CONGRATULATIONS
+ OpenEMR has been successfully installed and configured.
+ .
+ You can now use OpenEMR by browsing
+ to: http://localhost/openemr
+ .
+ (user is 'admin' and password is 'pass')
+
+Template: openemr/success_upgrade
+Type: note
+Description: CONGRATULATIONS
+ OpenEMR has been successfully upgraded.
+ .
+ Recommend setting optional configuration settings in
+ /var/www/openemr/sites/<sitename>/config.php  (We have
+ renamed your old configuration file to config.OLD)
+ (We recommend you delete the config.OLD file when done)
+ .
+ We have placed backup of your old OpenEMR in
+ /tmp/openemr-tmp/ (We recommend you copy this
+ somewhere protected since it contains confidential
+ patient information)
+
+Template: openemr/unable_remove
+Type: error
+Description: ERROR
+ Unable to remove the openemr package, because
+ you did not provide the correct MySQL root password.
+ .
+ Ensure you know the MySQL root password before
+ attempting to remove this package in the future.
+
+Template: openemr/www_path_already_exists
+Type: error
+Description: ERROR
+ Unable to install the openemr package, because
+ an instance of OpenEMR already exist at /var/www/openemr.
+
+Template: openemr/upgrade_not_supported
+Type: error
+Description: ERROR
+ This package does not support upgrading your
+ current version of OpenEMR.
+
+Template: openemr/upgrade_not_installed
+Type: error
+Description: ERROR
+ This package can not upgrade OpenEMR, because
+ OpenEMR is not installed at /var/www/openemr
+
+Template: openemr/upgrade_not_database
+Type: error
+Description: ERROR
+ This package can not upgrade OpenEMR, because
+ unable to confirm presence of a mysql credentials
+ and/or database.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/openemr.git



More information about the debian-med-commit mailing list