3 #This program is free software; you can redistribute it and/or modify
4 #it under the terms of the GNU General Public License as published by
5 #the Free Software Foundation; either version 2 of the License, or
6 #(at your option) any later version.
9 # authors: Brady Miller <brady@sparmy.com>
10 # Amalu Obinna <amaluobinna@aol.com>
12 # Debian package post installation script steps:
13 # 1) Collect mysql root password (optional)
14 # 2) Download OpenEMR from official github repository
16 # 4) Configure OpenEMR (if applicable)
18 # summary of how this script can be called:
19 # * <postinst> `configure' <most-recently-configured-version>
20 # * <old-postinst> `abort-upgrade' <new version>
21 # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
23 # * <postinst> `abort-remove'
24 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
25 # <failed-install-package> <version> `removing'
26 # <conflicting-package> <version>
27 # for details, see http://www.debian.org/doc/debian-policy/ or
28 # the debian-policy package
30 # Source debconf library.
31 .
/usr
/share
/debconf
/confmodule
37 LOGDIR
=/var
/log
/git-openemr
39 CONFIGDIR
=/etc
/git-openemr
40 CONFIG
=$CONFIGDIR/git-openemr.conf
42 OPENEMR
=$WEB/git-openemr
43 SITEDIR
=$OPENEMR/sites
/default
44 INSTALL_USER
=gitopenemr
45 INSTALL_DATABASE
=gitopenemr
49 #auto installer location
50 INST
=$OPENEMR/contrib
/util
/installScripts
/InstallerAuto.php
51 INSTTEMP
=$OPENEMR/contrib
/util
/installScripts
/InstallerAutoTemp.php
53 #Standardized echo function to send to only log file
54 # requires one parameter (string)
56 echo "`date`: $1" >> $LOG
59 #Standardized exit functions to be used
60 # requires one parameter (string with reason for exiting)
62 echo "`date`: $1" >> $LOG
63 echo "`date`: EXITING.........." >> $LOG
67 #function to check mysql for selected databases
68 # 1st param is password, 2nd param database, 3rd param is host (optional), 4th param is user (optional)
81 if [ "`mysql -u "$USE" -h "$HOST" --password="$1" -e 'show databases' 2>/dev/null | awk '{ print $1}' | grep "^
$2$
"`" == "$2" ]; then
88 #function to collect variables from config files
89 # 1st param is variable name, 2nd param is filename
91 echo `grep -i "^[[:space:]]*$1[[:space:]=]" $2 | cut -d \= -f 2 | cut -d \; -f 1 | sed "s/[ '\"]//gi"`
94 #function to insert variables into config files
95 # 1st param is variable name, 2nd param is variable, 3rd param is filename
97 sed -i 's@^[ ]*'"$1"'[ =].*$@'"$1"' = '"$2"'@' "$3"
100 #function to prompt for input
101 # 1st param is name, 2nd param is priority, 3rd param is where result gets sent back in
105 db_fset
"$1" seen false
106 db_input
"$2" "$1" || true
109 local input_value
="$RET"
111 db_fset
"$1" seen false
113 eval $__result="'$input_value'"
116 #collect scripting information from config file
117 PROCESS
=$
(collect_var process
$CONFIG)
118 PLAN
=$
(collect_var plan
$CONFIG)
120 #Don't allow re-configuration
121 if [ "$PROCESS" == "complete" ] ; then
122 unable_exit
"OpenEMR has already been configured."
123 elif [ "$PROCESS" == "pending" ] ; then
124 #continue with configuration
125 log_only
"Configuring git-openemr package..."
127 unable_exit
"Error reading process variable in configuration file."
130 if [ "$PLAN" == "upgrade" ] ; then
131 #upgrade is not available with the git-openemr package
132 log_only
"Upgrading is not available with the git-openemr package"
133 log_only
"This package is for testing most recent development (unstable) OpenEMR version"
134 prompt_input git-openemr
/upgrade_not_supported critical ret_result
135 unable_exit
"To upgrade to most recent git version, recommend removing/reinstalling package"
137 elif [ "$PLAN" == "install" ] ; then
138 #continue with installation
139 log_only
"Installing git-openemr package..."
141 unable_exit
"Error reading plan variable in configuration file."
144 #collect the mysql root password (if applicable)
146 if check_mysql
"$MPASS" "mysql"; then
147 log_only
"Passed the mysql check loop"
149 #the blank initial mysql password didn't work, so prompt for password
150 # (will give 3 chances to provide correct password)
153 prompt_input git-openemr
/mysql_p_install_
${COUNTDOWN} critical ret_result
155 if check_mysql
"$MPASS" "mysql"; then
156 #the mysql root password works, so can exit loop
157 log_only
"Passed the mysql check loop"
160 #the mysql root password did not work
161 if [ "$COUNTDOWN" -ge "3" ]; then
162 prompt_input git-openemr
/no_configure_mysql_root high ret_result
163 log_only
"Will install OpenEMR, however will not configure OpenEMR. (unable to provide root password)"
171 #decide whether to configure OpenEMR after it is installed
173 if check_mysql
"$MPASS" "mysql"; then
174 #before auto configuration, ensure the openemr user and database do not exist
175 # Check for openemr database in mysql, if exist then will not configure
176 if check_mysql
"$MPASS" "$INSTALL_DATABASE"; then
177 prompt_input git-openemr
/no_configure_mysql_database high ret_result
178 log_only
"Will install OpenEMR, however will not automatically configure OpenEMR. (MySQL database already exists)"
179 configure_flag
=false
;
181 # Check for OpenEMR user in mysql.user, if exist then will not configure
182 USER
=$
(mysql
-s -u root
-h localhost
--password="$MPASS" -e "SELECT User from mysql.user where User='$INSTALL_USER'")
183 if [ "$USER" == "$INSTALL_USER" ]; then
184 prompt_input git-openemr
/no_configure_mysql_user high ret_result
185 log_only
"Will install OpenEMR, however will not automatically configure OpenEMR. (MySQL user already exists)"
186 configure_flag
=false
;
189 #the mysql root password didn't work, so do not configure OpenEMR
190 log_only
"Will install OpenEMR, however will not automatically configure OpenEMR. (root password did not work)"
191 configure_flag
=false
;
198 # Download development version of openemr
199 log_only
"Downloading official OpenEMR development version (please be patient)"
200 if !(git clone git
://github.com
/openemr
/openemr.git
>> $LOG 2>&1); then
201 # unable to download OpenEMR
202 prompt_input git-openemr
/unable_download critical ret_result
203 unable_exit
"Unable to download OpenEMR development version"
207 # Remove .git directory
208 rm -rf `find $TMPDIR -name .git`
211 if $configure_flag; then
212 log_only
"Installing/Configuring OpenEMR development version..."
214 log_only
"Installing OpenEMR development version..."
216 mv $TMPDIR/openemr
$OPENEMR
221 chown
-Rf root
:root
$OPENEMR
223 # Set file and directory permissions
224 chmod 666 $SITEDIR/sqlconf.php
225 chown
$WEB_GROUP.
$WEB_USER $OPENEMR/interface
/modules
/zend_modules
/config
/application.config.php
226 chown
-R $WEB_GROUP.
$WEB_USER $SITEDIR/documents
227 chown
-R $WEB_GROUP.
$WEB_USER $SITEDIR/edi
228 chown
-R $WEB_GROUP.
$WEB_USER $SITEDIR/era
229 chown
-R $WEB_GROUP.
$WEB_USER $SITEDIR/letter_templates
230 chown
-R $WEB_GROUP.
$WEB_USER $OPENEMR/interface
/main
/calendar
/modules
/PostCalendar
/pntemplates
/cache
231 chown
-R $WEB_GROUP.
$WEB_USER $OPENEMR/interface
/main
/calendar
/modules
/PostCalendar
/pntemplates
/compiled
232 chown
-R $WEB_GROUP.
$WEB_USER $OPENEMR/gacl
/admin
/templates_c
234 # NEED TO CONFIGURE APACHE BEFORE CONFIGURATION SINCE ZEND SUPPORT NEEDS PROPER CONFIGURATION
235 # Activate the OpenEMR conf file for apache
236 log_only
"Activate OpenEMR config file for Apache"
237 a2ensite git-openemr.conf
238 # Ensure the apache rewrite module is turned on
240 # Restart the apache server
241 log_only
"Restarting Apache service..."
242 invoke-rc.d apache2 restart
>> $LOG 2>&1
245 if $configure_flag; then
246 # Create a random password for the openemr mysql user
247 password
=$
(makepasswd
--char=12)
249 # openemr installation VARIABLES
250 if [ "$MPASS" == "" ] ; then
251 rootpass
="rootpass=BLANK" #MySQL server root password
253 rootpass
="rootpass=$MPASS" #MySQL server root password
255 login
="login=$INSTALL_USER" #username to MySQL openemr database
256 pass
="pass=$password" #password to MySQL openemr database
257 dbname
="dbname=$INSTALL_DATABASE" #MySQL openemr database name
262 sed -e 's@^exit;@ @' <$INST >$INSTTEMP
263 php
-f $INSTTEMP $rootpass $login $pass $dbname >> $LOG 2>&1
266 # NO NEED to secure files since this is a development/testing version
268 log_only
"Done configuring OpenEMR"
271 #update config file, change process to complete and remove plan and pass
272 sed -i "s/^[ ]*process[ =].*$/process=complete/" $CONFIG
273 sed -i "/^[ ]*plan[ =].*$/d" $CONFIG
274 sed -i "/^[ ]*pass[ =].*$/d" $CONFIG
276 log_only
"You can now use OpenEMR development version by browsing to:"
277 log_only
"http://localhost/git-openemr"
278 if $configure_flag; then
279 prompt_input git-openemr
/success_install_config high ret_result
280 log_only
"user is 'admin' and password is 'pass'"
282 prompt_input git-openemr
/success_install high ret_result
284 log_only
"See the openemr man page for further instructions:"
285 log_only
"type 'man git-openemr' at command line"
292 abort-upgrade|abort-remove|abort-deconfigure
)
294 echo "postinst asked to do $1"
298 echo "postinst called with unknown argument \`$1'" >&2