removed redundant docs (it is on the wiki)
[openemr.git] / contrib / util / restore
blob096f704a36daabdc4903286fb3c6b21aeaadc026
1 #!/bin/bash
3 # Copyright (C) 2008-2010 Rod Roark <rod@sunsetsystems.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This is for restoring a backup created by the "Backup" option
11 # in OpenEMR's administration menu, which invokes
12 # interface/main/backup.php.
14 # Xdialog is supported if available... dialog support is also in
15 # here but is disabled, as it was found to be ugly and clumsy.
17 DLGCMD=""
18 NOBUTTONS=""
19 DEFAULTNO=""
20 LEFT=""
21 if [ ! -z "$DISPLAY" -a ! -z "`which Xdialog`" ]; then
22 DLGCMD="Xdialog"
23 NOBUTTONS="--no-buttons"
24 DEFAULTNO="--default-no"
25 LEFT="--left"
26 # elif [ ! -z `which dialog` ]; then
27 # DLGCMD="dialog"
30 dlg_msg() {
31 if [ ! -z "$DLGCMD" ]; then
32 local MSG="$1"
33 shift
34 while [ ! -z "$1" ]; do
35 MSG="$MSG\n$1"
36 shift
37 done
38 $DLGCMD --title 'OpenEMR Restore' $LEFT --msgbox "$MSG" 0 0
39 return 0
41 while [ ! -z "$1" ]; do
42 echo "$1"
43 shift
44 done
47 dlg_info() {
48 if [ ! -z "$DLGCMD" ]; then
49 if [ "$DLGCMD" = "Xdialog" ]; then
50 echo "$1"
52 $DLGCMD --title 'OpenEMR Restore' $LEFT --infobox "$1" 0 0
53 return 0
55 echo "$1"
58 dlg_fselect() {
59 if [ ! -z "$DLGCMD" ]; then
60 exec 3>&1
61 RESULT=`$DLGCMD --title 'OpenEMR Restore' --backtitle "$1" $NOBUTTONS --fselect $HOME/ 0 70 2>&1 1>&3`
62 CODE=$?
63 exec 3>&-
64 if [ $CODE -eq 0 ]; then
65 return 0
67 echo $RESULT
68 exit 1
70 echo " "
71 read -e -p "$1: " RESULT
74 dlg_yesno() {
75 if [ ! -z "$DLGCMD" ]; then
76 local MSG="$1"
77 shift
78 while [ ! -z "$1" ]; do
79 MSG="$MSG\n$1"
80 shift
81 done
82 $DLGCMD --title 'OpenEMR Restore' $DEFAULTNO $LEFT --yesno "$MSG" 0 0
83 CODE=$?
84 exec 3>&-
85 if [ $CODE -eq 0 ]; then
86 RESULT="1"
87 elif [ $CODE -eq 1 ]; then
88 RESULT="0"
89 else
90 exit 1
92 return 0
94 echo " "
95 while [ ! -z "$2" ]; do
96 echo "$1"
97 shift
98 done
99 read -e -p "$1 [N/y] " RESULT
100 RESULT=`expr "$RESULT" : "[yY]"`
101 return 0
104 dlg_input() {
105 if [ ! -z "$DLGCMD" ]; then
106 exec 3>&1
107 RESULT=`$DLGCMD --title 'OpenEMR Restore' $LEFT --inputbox "$1" 0 0 2>&1 1>&3`
108 CODE=$?
109 exec 3>&-
110 if [ $CODE -eq 0 ]; then
111 return 0
113 echo $RESULT
114 exit 1
116 echo " "
117 read -e -p "$1 " RESULT
120 dlg_blank_line() {
121 if [ -z "$DLGCMD" ]; then
122 echo " "
126 dlg_msg "WARNING: This script is experimental." "It may have serious bugs or omissions." "Use it at your own risk!"
128 BAKDIR=/tmp/emr_backup
130 if [ $UID -ne 0 ]; then
131 dlg_msg "Error: This script must be executed with root privileges."
132 exit 1
135 # Create and change to a clean scratch directory.
136 rm -rf $BAKDIR
137 mkdir $BAKDIR
138 if [ $? -ne 0 ]; then
139 dlg_msg "Error: Cannot create directory '$BAKDIR'."
140 exit 1
143 dlg_msg "Now you will be asked for the backup file." "By default this is named emr_backup.tar, although you may have saved it as something else."
145 LOOKING=1
146 while [ $LOOKING -eq 1 ]; do
147 dlg_fselect "Enter path/name of backup file"
148 TARFILE=$RESULT
149 dlg_blank_line
150 if [ ! -f $TARFILE ]; then
151 dlg_msg "Error: '$TARFILE' is not found or is not a file."
152 else
153 # Extract the backup tarball into the scratch directory.
154 dlg_info "Extracting $TARFILE ..."
155 cd $BAKDIR
156 tar -xf $TARFILE
157 if [ $? -ne 0 ]; then
158 dlg_msg "Error: tar could not extract '$TARFILE'."
159 else
160 LOOKING=0
163 done
165 # Extract the OpenEMR web directory tree.
166 dlg_info "Extracting $BAKDIR/openemr.tar.gz ..."
167 mkdir openemr
168 cd openemr
169 tar zxf ../openemr.tar.gz
170 if [ $? -ne 0 ]; then
171 dlg_msg "Error: tar could not extract '$BAKDIR/openemr.tar.gz'."
172 exit 1
175 OEDIR=/var/www/openemr
177 # Get the Site ID, it should be the only site backed up.
178 SITEID=`ls -1 sites | head -n 1`
180 # Get various parameters from the extracted files.
181 OEDBNAME=`grep '^\$dbase' sites/$SITEID/sqlconf.php | cut -d \' -f 2 | cut -d \" -f 2`
182 OEDBUSER=`grep '^\$login' sites/$SITEID/sqlconf.php | cut -d \' -f 2 | cut -d \" -f 2`
183 OEDBPASS=`grep '^\$pass' sites/$SITEID/sqlconf.php | cut -d \' -f 2 | cut -d \" -f 2`
184 SLDBNAME=''
185 # SL support is becoming obsolete, but we're leaving it in for now.
186 if [ -f ../sql-ledger.sql ]; then
187 SLDBNAME=`grep '^\$sl_dbname' interface/globals.php | cut -d \' -f 2`
188 SLDBUSER=`grep '^\$sl_dbuser' interface/globals.php | cut -d \' -f 2`
189 SLDBPASS=`grep '^\$sl_dbpass' interface/globals.php | cut -d \' -f 2`
191 # Likewise, external phpGACL is discouraged because it will not work
192 # with multiple sites.
193 GADIR=''
194 GACONFIGDIR=''
195 GADBNAME=''
196 if [ -f ../phpgacl.tar.gz ]; then
197 GADIR=`grep '^\s*\$phpgacl_location' library/acl.inc | cut -d \" -f 2`
198 GACONFIGDIR="$GADIR"
199 mkdir ../phpgacl
200 cd ../phpgacl
201 dlg_info "Extracting $BAKDIR/phpgacl.tar.gz ..."
202 tar zxf ../phpgacl.tar.gz
203 if [ $? -ne 0 ]; then
204 dlg_msg "Error: tar could not extract '$BAKDIR/phpgacl.tar.gz'."
205 exit 1
207 if [ -f ../phpgacl.sql.gz ]; then
208 GADBNAME=`grep '^\s*var \$_db_name' gacl.class.php | cut -d \' -f 2`
209 GADBUSER=`grep '^\s*var \$_db_user' gacl.class.php | cut -d \' -f 2`
210 GADBPASS=`grep '^\s*var \$_db_password' gacl.class.php | cut -d \' -f 2`
212 elif [ -e gacl ]; then
213 grep '^\s*\$phpgacl_location' library/acl.inc > /dev/null
214 if [ $? -eq 0 ]; then
215 GACONFIGDIR="$OEDIR/gacl"
216 if [ -f ../phpgacl.sql.gz ]; then
217 cd gacl
218 GADBNAME=`grep '^\s*var \$_db_name' gacl.class.php | cut -d \' -f 2`
219 GADBUSER=`grep '^\s*var \$_db_user' gacl.class.php | cut -d \' -f 2`
220 GADBPASS=`grep '^\s*var \$_db_password' gacl.class.php | cut -d \' -f 2`
221 cd ..
226 SLDIR=''
227 if [ -f ../sql-ledger.tar.gz ]; then
228 SLDIR=`dirname $OEDIR`/sql-ledger
231 dlg_yesno "Do you want to specify site ID, locations or database names for the restore?"
233 CHANGES=$RESULT
234 OLDSITEID=$SITEID
236 dlg_blank_line
238 if [ $CHANGES -gt 0 ]; then
239 dlg_msg "Current values are shown in [brackets]. Just hit Enter to leave them as-is."
240 dlg_input "Site ID [$SITEID]? "
241 if [ ! -z "$RESULT" ]; then SITEID="$RESULT"; fi
242 dlg_input "OpenEMR database name [$OEDBNAME]? "
243 if [ ! -z "$RESULT" ]; then OEDBNAME="$RESULT"; fi
244 dlg_input "OpenEMR database user [$OEDBUSER]? "
245 if [ ! -z "$RESULT" ]; then OEDBUSER="$RESULT"; fi
246 dlg_input "OpenEMR database password [$OEDBPASS]? "
247 if [ ! -z "$RESULT" ]; then OEDBPASS="$RESULT"; fi
248 if [ ! -z "$GADBNAME" ]; then
249 dlg_input "phpGACL database name [$GADBNAME]? "
250 if [ ! -z "$RESULT" ]; then GADBNAME="$RESULT"; fi
251 OLDGADBUSER="$GADBUSER"
252 LOOKING=1
253 while [ $LOOKING -eq 1 ]; do
254 dlg_input "phpGACL database user [$GADBUSER]? "
255 if [ ! -z "$RESULT" ]; then GADBUSER="$RESULT"; fi
256 if [ "$GADBUSER" = "$SLDBUSER" ]; then
257 dlg_msg "Error: OpenEMR and phpGACL have separate databases but the same user name." "They must be different user names."
258 GADBUSER="$OLDGADBUSER"
259 else
260 LOOKING=0
262 done
263 dlg_input "phpGACL database password [$GADBPASS]? "
264 if [ ! -z "$RESULT" ]; then GADBPASS="$RESULT"; fi
266 if [ ! -z "$SLDBNAME" ]; then
267 OLDSLDBNAME="$SLDBNAME"
268 dlg_input "SQL-Ledger database name [$SLDBNAME]? "
269 if [ ! -z "$RESULT" ]; then SLDBNAME="$RESULT"; fi
270 dlg_input "SQL-Ledger database user [$SLDBUSER]? "
271 if [ ! -z "$RESULT" ]; then SLDBUSER="$RESULT"; fi
272 dlg_input "SQL-Ledger database password [$SLDBPASS]? "
273 if [ ! -z "$RESULT" ]; then SLDBPASS="$RESULT"; fi
275 OLDOEDIR="$OEDIR"
276 dlg_input "New OpenEMR web directory [$OEDIR]? "
277 if [ ! -z "$RESULT" ]; then OEDIR="$RESULT"; fi
278 if [ ! -z "$GADIR" ]; then
279 OLDGADIR="$GADIR"
280 dlg_input "New phpGACL web directory [$GADIR]? "
281 if [ ! -z "$RESULT" ]; then GADIR="$RESULT"; fi
283 if [ ! -z "$SLDIR" ]; then
284 OLDSLDIR="$SLDIR"
285 dlg_input "New SQL-Ledger web directory [$SLDIR]? "
286 if [ ! -z "$RESULT" ]; then SLDIR="$RESULT"; fi
287 dlg_input "Previous SQL-Ledger web directory [$OLDSLDIR]? "
288 if [ ! -z "$RESULT" ]; then OLDSLDIR="$RESULT"; fi
293 # Patch up $GACONFIGDIR in case it was changed.
294 if [ -z "$GADIR" ]; then
295 if [ ! -z "$GACONFIGDIR" ]; then
296 GACONFIGDIR="$OEDIR/gacl"
298 else
299 GACONFIGDIR="$GADIR"
302 # If phpgacl has its own database, make sure the database user is not the
303 # same as for openemr. This is to prevent screwups caused by persistent
304 # database connections in PHP.
305 if [ ! -z "$GADBNAME" ]; then
306 if [ "$GADBUSER" = "$OEDBUSER" ]; then
307 dlg_msg "Error: OpenEMR and phpGACL have separate databases but the same user name." "They must be different user names."
308 exit 1
312 # The following sanity checks are an attempt to avoid disastrous results
313 # from mistakes in entry of directory path names.
315 TRASH=`expr "$OEDIR" : "[/]"`
316 if [ $TRASH -ne 1 ]; then
317 dlg_msg "Error: The OpenEMR directory path '$OEDIR' does not start with '/'."
318 exit 1
320 if [ -e "$OEDIR" -a ! -e "$OEDIR/interface/globals.php" ]; then
321 dlg_msg "Error: $OEDIR already exists but does not look like an OpenEMR directory." "If you are really sure you want to replace it, please remove it first."
322 exit 1
325 if [ ! -z "$GADIR" ]; then
326 TRASH=`expr "$GADIR" : "[/]"`
327 if [ $TRASH -ne 1 ]; then
328 dlg_msg "Error: The phpGACL directory path '$GADIR' does not start with '/'."
329 exit 1
331 if [ -e "$GADIR" -a ! -e "$GADIR/gacl.class.php" ]; then
332 dlg_msg "Error: $GADIR already exists but does not look like a phpGACL directory." "If you are really sure you want to replace it, please remove it first."
333 exit 1
337 if [ ! -z "$SLDIR" ]; then
338 TRASH=`expr "$SLDIR" : "[/]"`
339 if [ $TRASH -ne 1 ]; then
340 dlg_msg "Error: The SQL-Ledger directory path '$SLDIR' does not start with '/'."
341 exit 1
343 if [ -e "$SLDIR" -a ! -e "$SLDIR/setup.pl" ]; then
344 dlg_msg "Error: $SLDIR already exists but does not look like a SQL-Ledger directory." "If you are really sure you want to replace it, please remove it first."
345 exit 1
349 if [ -e "$OEDIR" -a ! -e "$OEDIR/sites" ]; then
350 dlg_msg "Error: Directory '$OEDIR/sites' is missing - old release needs removal?"
351 exit 1
354 if [ -e "$OEDIR/sites/$SITEID" ]; then
355 dlg_msg "Error: Site '$SITEID' already exists in '$OEDIR/sites'."
356 exit 1
359 COLLATE="utf8_general_ci"
360 dlg_msg "If you have a particular requirement for the UTF-8 collation to use, " \
361 "then please specify it here. Hit Enter to accept the default '$COLLATE'." \
362 "Enter 'none' if you do not want UTF-8."
363 dlg_input "UTF-8 collation [$COLLATE]? "
364 if [ ! -z "$RESULT" ]; then COLLATE="$RESULT"; fi
365 TRASH=`expr "$COLLATE" : "[uU]"`
366 if [ $TRASH -ne 1 ]; then
367 COLLATE=""
370 # Ask the user to do final sanity checking.
372 MARGS="\"Your Site ID will be '$SITEID'.\""
373 if [ -e "$OEDIR" ]; then
374 MARGS="$MARGS \"Only site-specific files will be restored to '$OEDIR/sites/$SITEID' in the existing OpenEMR web directory.\""
375 else
376 MARGS="$MARGS \"I will install a new OpenEMR web directory '$OEDIR' from the backup.\""
378 MARGS="$MARGS \"I will restore the OpenEMR database backup to the MySQL database '$OEDBNAME'.\""
379 MARGS="$MARGS \"The OpenEMR database user will be '$OEDBUSER' with password '$OEDBPASS'.\""
380 if [ ! -z "$GADBNAME" ]; then
381 MARGS="$MARGS \"I will restore the phpGACL database backup to the MySQL database '$GADBNAME'.\""
382 MARGS="$MARGS \"The phpGACL database user will be '$GADBUSER' with password '$GADBPASS'.\""
384 if [ -z "$COLLATE" ]; then
385 MARGS="$MARGS \"MySQL will use its default character set and collation.\""
386 else
387 MARGS="$MARGS \"MySQL will use character set 'utf8' with collation '$COLLATE'.\""
389 if [ ! -z "$SLDBNAME" ]; then
390 MARGS="$MARGS \"I will restore the SQL-Ledger database backup to the PostgreSQL database '$SLDBNAME'.\""
391 MARGS="$MARGS \"The SQL-Ledger database user will be '$SLDBUSER' with password '$SLDBPASS'.\""
393 if [ ! -z "$GADIR" ]; then
394 MARGS="$MARGS \"I will copy the phpGACL web directory backup to '$GADIR'.\""
396 if [ ! -z "$SLDIR" ]; then
397 MARGS="$MARGS \"I will copy the SQL-Ledger web directory backup to '$SLDIR'.\""
399 MARGS="$MARGS \" \""
400 MARGS="$MARGS \"Please check the above very carefully!\""
401 MARGS="$MARGS \"Any existing databases and directories matching these names will be DESTROYED.\""
402 MARGS="$MARGS \"Do you wish to continue?\""
404 eval "dlg_yesno $MARGS"
405 if [ $RESULT -ne 1 ]; then
406 exit 1
409 dlg_blank_line
411 dlg_msg "In order to create MySQL databases and users on this computer, I will need to" \
412 "log into MySQL as its 'root' user. The next question asks for the MySQL root" \
413 "user's password for this server, the one that you are restoring to. This is" \
414 "a MySQL password, not a system login password. It might be blank."
415 dlg_input 'Enter the password, if any, for the MySQL root user:'
416 MYROOTPASS="$RESULT"
418 dlg_blank_line
420 dlg_info "Dropping old OpenEMR database if it exists ..."
421 mysqladmin --password="$MYROOTPASS" --force drop $OEDBNAME 2> /dev/null
423 dlg_info "Restoring OpenEMR database ..."
424 cd $BAKDIR
425 gunzip openemr.sql.gz
426 if [ $? -ne 0 ]; then
427 dlg_msg "Error: Could not decompress '$BAKDIR/openemr.sql.gz'."
428 exit 1
431 if [ -z $COLLATE ]; then
432 TRASH="CREATE DATABASE $OEDBNAME"
433 else
434 TRASH="CREATE DATABASE $OEDBNAME CHARACTER SET utf8 COLLATE $COLLATE"
436 mysql --password="$MYROOTPASS" --execute "$TRASH"
437 if [ $? -ne 0 ]; then
438 dlg_msg "Error creating MySQL database with '$TRASH'."
439 exit 1
442 mysql --password="$MYROOTPASS" --execute "GRANT ALL PRIVILEGES ON $OEDBNAME.* TO '$OEDBUSER'@'localhost' IDENTIFIED BY '$OEDBPASS'" $OEDBNAME
443 mysql --user=$OEDBUSER --password="$OEDBPASS" $OEDBNAME < openemr.sql
444 if [ $? -ne 0 ]; then
445 dlg_msg "Error: Restore to database '$OEDBNAME' failed."
446 exit 1
449 if [ ! -z "$GADBNAME" ]; then
450 dlg_info "Dropping old phpGACL database if it exists ..."
451 mysqladmin --password="$MYROOTPASS" --force drop $GADBNAME 2> /dev/null
452 dlg_info "Restoring phpGACL database ..."
453 cd $BAKDIR
454 gunzip phpgacl.sql.gz
455 if [ $? -ne 0 ]; then
456 dlg_msg "Error: Could not decompress '$BAKDIR/phpgacl.sql.gz'."
457 exit 1
460 if [ -z $COLLATE ]; then
461 TRASH="CREATE DATABASE $GADBNAME"
462 else
463 TRASH="CREATE DATABASE $GADBNAME CHARACTER SET utf8 COLLATE $COLLATE"
465 mysql --password="$MYROOTPASS" --execute "$TRASH"
466 if [ $? -ne 0 ]; then
467 dlg_msg "Error creating MySQL database with '$TRASH'."
468 exit 1
471 mysql --password="$MYROOTPASS" --execute "GRANT ALL PRIVILEGES ON $GADBNAME.* TO '$GADBUSER'@'localhost' IDENTIFIED BY '$GADBPASS'" $GADBNAME
472 mysql --user=$GADBUSER --password="$GADBPASS" $GADBNAME < phpgacl.sql
473 if [ $? -ne 0 ]; then
474 dlg_msg "Error: Restore to database '$GADBNAME' failed."
475 exit 1
479 if [ ! -z "$SLDBNAME" ]; then
480 # Avoid local domain connections for the sql-ledger user, because a
481 # default postgresql configuration is likely set to require "ident"
482 # authentication for them.
483 MYPGHOST=localhost
484 if [ ! -z "$PGHOST" ]; then
485 MYPGHOST="$PGHOST";
488 unset PGUSER
489 unset PGPASSWORD
490 dlg_info "Restarting Apache to close persistent database connections ..."
491 apache2ctl graceful
492 dlg_info "Dropping old SQL-Ledger database if it exists ..."
493 sudo -u postgres psql --command "DROP DATABASE \"$SLDBNAME\"" template1 2> /dev/null
494 dlg_info "Creating procedural language and database user ..."
495 sudo -u postgres createlang plpgsql template1 2> /dev/null
496 sudo -u postgres psql --command "DROP ROLE \"$SLDBUSER\"" template1 2> /dev/null
498 # This next part merits some comment. The database is best loaded by the
499 # sql-ledger user, otherwise we will have the nasty task of granting that
500 # user access to all of its tables individually, which PostgreSQL does not
501 # provide a convenient way of doing. However superuser privilege is needed
502 # to properly restore the dump. Therefore we give the new role superuser
503 # privilege now and revoke it after the restore is done.
505 sudo -u postgres psql --command "CREATE ROLE \"$SLDBUSER\" PASSWORD '$SLDBPASS' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN" template1
506 dlg_info "Creating and restoring SQL-Ledger database ..."
507 export PGUSER="$SLDBUSER"
508 export PGPASSWORD="$SLDBPASS"
509 psql -h $MYPGHOST --command "CREATE DATABASE \"$SLDBNAME\" WITH TEMPLATE template0" template1
510 if [ $? -ne 0 ]; then
511 dlg_msg "Error: Could not create PostgreSQL database '$SLDBNAME'."
512 exit 1
514 pg_restore -h $MYPGHOST --no-owner --dbname=$SLDBNAME sql-ledger.sql
515 if [ $? -ne 0 ]; then
516 dlg_msg "Error: Restore to database '$SLDBNAME' failed."
517 exit 1
519 unset PGUSER
520 unset PGPASSWORD
521 sudo -u postgres psql --command "ALTER ROLE \"$SLDBUSER\" NOSUPERUSER" template1
522 if [ $? -ne 0 ]; then
523 dlg_info "Warning: ALTER ROLE failed."
525 sudo -u postgres psql --command "ANALYZE" $SLDBNAME
528 if [ -e "$OEDIR" ]; then
529 dlg_info "Restoring site subdirectory ..."
530 mv $BAKDIR/openemr/sites/$OLDSITEID $OEDIR/sites/$SITEID
531 if [ $? -ne 0 ]; then
532 dlg_msg "Error: Cannot create directory '$OEDIR/sites/$SITEID'."
533 exit 1
535 else
536 dlg_info "Restoring OpenEMR web directory tree ..."
537 mv $BAKDIR/openemr $OEDIR
538 if [ $? -ne 0 ]; then
539 dlg_msg "Error: Cannot create directory '$OEDIR'."
540 exit 1
544 if [ $CHANGES -gt 0 ]; then
545 if [ ! -z "$SLDIR" ]; then
546 dlg_info "Modifying $OEDIR/interface/globals.php ..."
547 cd $OEDIR/interface
548 mv -f globals.php globals.php.old
549 sed "s^sl_dbname *= '.*'^sl_dbname = '$SLDBNAME'^" globals.php.old | \
550 sed "s^sl_dbuser *= '.*'^sl_dbuser = '$SLDBUSER'^" | \
551 sed "s^sl_dbpass *= '.*'^sl_dbpass = '$SLDBPASS'^" \
552 > globals.php
555 dlg_info "Modifying $OEDIR/sites/$SITEID/sqlconf.php ..."
556 cd $OEDIR/sites/$SITEID
557 mv sqlconf.php sqlconf.php.old
558 sed "s^dbase\s*=\s*['\"].*['\"]^dbase\t= '$OEDBNAME'^" sqlconf.php.old | \
559 sed "s^login\s*=\s*['\"].*['\"]^login\t= '$OEDBUSER'^" | \
560 sed "s^pass\s*=\s*['\"].*['\"]^pass\t= '$OEDBPASS'^" > sqlconf.php
562 # Logic to fix the path to ws_server.pl in includes/config.php was removed.
563 # Not gonna worry about this because SL is deprecated, the old logic was not
564 # very robust, and this can be fixed up manually easily enough.
567 if [ ! -z "$GADIR" ]; then
568 dlg_info "Restoring phpGACL web directory tree ..."
569 mkdir -p $GADIR
570 rm -rf $GADIR
571 mv $BAKDIR/phpgacl $GADIR
572 if [ $? -ne 0 ]; then
573 dlg_msg "Error: Cannot create directory '$GADIR'."
574 exit 1
577 if [ $CHANGES -gt 0 ]; then
578 dlg_info "Modifying $OEDIR/library/acl.inc ..."
579 cd $OEDIR/library
580 mv -f acl.inc acl.inc.old
581 sed "s^phpgacl_location *= *\"/.*\"^phpgacl_location = \"$GADIR\"^" acl.inc.old > acl.inc
585 if [ ! -z "$GACONFIGDIR" -a $CHANGES -gt 0 -a ! -z "$GADBNAME" ]; then
586 dlg_info "Modifying $GACONFIGDIR/gacl.class.php ..."
587 cd $GACONFIGDIR
588 mv -f gacl.class.php gacl.class.php.old
589 sed "s^db_name *= *'.*'^db_name = '$GADBNAME'^" gacl.class.php.old | \
590 sed "s^db_user *= *'.*'^db_user = '$GADBUSER'^" | \
591 sed "s^db_password *= *'.*'^db_password = '$GADBPASS'^" > gacl.class.php
593 dlg_info "Modifying $GACONFIGDIR/gacl.ini.php ..."
594 cd $GACONFIGDIR
595 mv -f gacl.ini.php gacl.ini.php.old
596 sed "s^db_name[ \t]*= *\".*\"^db_name\t\t\t= \"$GADBNAME\"^" gacl.ini.php.old | \
597 sed "s^db_user[ \t]*= *\".*\"^db_user\t\t\t= \"$GADBUSER\"^" | \
598 sed "s^db_password[ \t]*= *\".*\"^db_password\t\t= \"$GADBPASS\"^" > gacl.ini.php
601 if [ ! -z "$SLDIR" ]; then
602 dlg_info "Restoring SQL-Ledger web directory tree ..."
603 mkdir -p $SLDIR
604 rm -rf $SLDIR
605 mkdir $SLDIR
606 cd $SLDIR
607 if [ $? -ne 0 ]; then
608 dlg_msg "Error: Creating $SLDIR failed."
609 exit 1
611 tar zxf $BAKDIR/sql-ledger.tar.gz
612 if [ $? -ne 0 ]; then
613 dlg_msg "Error: Extracting '$BAKDIR/sql-ledger.tar.gz' failed."
614 exit 1
617 if [ $CHANGES -gt 0 ]; then
618 # SQL-Ledger stores passwords in an obfuscated form.
619 SLDBHASH=`perl -e "print pack u, '$SLDBPASS'"`
621 dlg_info "Modifying $SLDIR/ws_server.pl ..."
622 cd $SLDIR
623 mv -f ws_server.pl ws_server.pl.old
624 sed "s^$OLDSLDIR^$SLDIR^" ws_server.pl.old > ws_server.pl
625 chmod a+x ws_server.pl
627 dlg_info "Modifying $SLDIR/users/admin.conf ..."
628 cd $SLDIR/users
629 cp -f admin.conf admin.conf.old
630 sed "s^dbname => '.*'^dbname => '$SLDBNAME'^" admin.conf.old | \
631 sed "s^dbuser => '.*'^dbuser => '$SLDBUSER'^" | \
632 sed "/dbpasswd =>/ c \ dbpasswd => '$SLDBHASH'," | \
633 sed "s^dbname=$OLDSLDBNAME^dbname=$SLDBNAME^" > admin.conf
635 dlg_info "Modifying $SLDIR/users/members ..."
636 cd $SLDIR/users
637 cp -f members members.old
638 sed "s^dbname=.*^dbname=$SLDBNAME^g" members.old | \
639 sed "s^dbuser=.*^dbuser=$SLDBUSER^g" | \
640 sed "/dbpasswd=/ c dbpasswd=$SLDBHASH" > members
644 dlg_msg "All done."