added default character set and collation when creating mysql databases
[openemr.git] / contrib / util / restore
blob1682f0b82b371110aab150d1ecf54c6417ef6bbb
1 #!/bin/bash
3 # Copyright (C) 2008-2009 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 # Get various parameters from the extracted files.
176 OEDIR=`grep '^\$webserver_root' interface/globals.php | cut -d \" -f 2`
177 OEDBNAME=`grep '^\$dbase' library/sqlconf.php | cut -d \' -f 2`
178 OEDBUSER=`grep '^\$login' library/sqlconf.php | cut -d \' -f 2`
179 OEDBPASS=`grep '^\$pass' library/sqlconf.php | cut -d \' -f 2`
180 SLDBNAME=''
181 if [ -f ../sql-ledger.sql ]; then
182 SLDBNAME=`grep '^\$sl_dbname' interface/globals.php | cut -d \' -f 2`
183 SLDBUSER=`grep '^\$sl_dbuser' interface/globals.php | cut -d \' -f 2`
184 SLDBPASS=`grep '^\$sl_dbpass' interface/globals.php | cut -d \' -f 2`
187 GADIR=''
188 GACONFIGDIR=''
189 GADBNAME=''
190 if [ -f ../phpgacl.tar.gz ]; then
191 GADIR=`grep '^\s*\$phpgacl_location' library/acl.inc | cut -d \" -f 2`
192 GACONFIGDIR="$GADIR"
193 mkdir ../phpgacl
194 cd ../phpgacl
195 dlg_info "Extracting $BAKDIR/phpgacl.tar.gz ..."
196 tar zxf ../phpgacl.tar.gz
197 if [ $? -ne 0 ]; then
198 dlg_msg "Error: tar could not extract '$BAKDIR/phpgacl.tar.gz'."
199 exit 1
201 if [ -f ../phpgacl.sql.gz ]; then
202 GADBNAME=`grep '^\s*var \$_db_name' gacl.class.php | cut -d \' -f 2`
203 GADBUSER=`grep '^\s*var \$_db_user' gacl.class.php | cut -d \' -f 2`
204 GADBPASS=`grep '^\s*var \$_db_password' gacl.class.php | cut -d \' -f 2`
206 elif [ -e gacl ]; then
207 grep '^\s*\$phpgacl_location' library/acl.inc > /dev/null
208 if [ $? -eq 0 ]; then
209 GACONFIGDIR="$OEDIR/gacl"
210 if [ -f ../phpgacl.sql.gz ]; then
211 cd gacl
212 GADBNAME=`grep '^\s*var \$_db_name' gacl.class.php | cut -d \' -f 2`
213 GADBUSER=`grep '^\s*var \$_db_user' gacl.class.php | cut -d \' -f 2`
214 GADBPASS=`grep '^\s*var \$_db_password' gacl.class.php | cut -d \' -f 2`
215 cd ..
220 SLDIR=''
221 if [ -f ../sql-ledger.tar.gz ]; then
222 SLDIR=`dirname $OEDIR`/sql-ledger
225 dlg_yesno 'Do you want to specify new locations and database names for the restore?'
226 CHANGES=$RESULT
228 dlg_blank_line
230 if [ $CHANGES -gt 0 ]; then
231 dlg_msg "Current values are shown in [brackets]. Just hit Enter to leave them as-is."
232 dlg_input "OpenEMR database name [$OEDBNAME]? "
233 if [ ! -z "$RESULT" ]; then OEDBNAME="$RESULT"; fi
234 dlg_input "OpenEMR database user [$OEDBUSER]? "
235 if [ ! -z "$RESULT" ]; then OEDBUSER="$RESULT"; fi
236 dlg_input "OpenEMR database password [$OEDBPASS]? "
237 if [ ! -z "$RESULT" ]; then OEDBPASS="$RESULT"; fi
238 if [ ! -z "$GADBNAME" ]; then
239 dlg_input "phpGACL database name [$GADBNAME]? "
240 if [ ! -z "$RESULT" ]; then GADBNAME="$RESULT"; fi
241 OLDGADBUSER="$GADBUSER"
242 LOOKING=1
243 while [ $LOOKING -eq 1 ]; do
244 dlg_input "phpGACL database user [$GADBUSER]? "
245 if [ ! -z "$RESULT" ]; then GADBUSER="$RESULT"; fi
246 if [ "$GADBUSER" = "$SLDBUSER" ]; then
247 dlg_msg "Error: OpenEMR and phpGACL have separate databases but the same user name." "They must be different user names."
248 GADBUSER="$OLDGADBUSER"
249 else
250 LOOKING=0
252 done
253 dlg_input "phpGACL database password [$GADBPASS]? "
254 if [ ! -z "$RESULT" ]; then GADBPASS="$RESULT"; fi
256 if [ ! -z "$SLDBNAME" ]; then
257 OLDSLDBNAME="$SLDBNAME"
258 dlg_input "SQL-Ledger database name [$SLDBNAME]? "
259 if [ ! -z "$RESULT" ]; then SLDBNAME="$RESULT"; fi
260 dlg_input "SQL-Ledger database user [$SLDBUSER]? "
261 if [ ! -z "$RESULT" ]; then SLDBUSER="$RESULT"; fi
262 dlg_input "SQL-Ledger database password [$SLDBPASS]? "
263 if [ ! -z "$RESULT" ]; then SLDBPASS="$RESULT"; fi
265 OLDOEDIR="$OEDIR"
266 dlg_input "OpenEMR web directory [$OEDIR]? "
267 if [ ! -z "$RESULT" ]; then OEDIR="$RESULT"; fi
268 if [ ! -z "$GADIR" ]; then
269 OLDGADIR="$GADIR"
270 dlg_input "phpGACL web directory [$GADIR]? "
271 if [ ! -z "$RESULT" ]; then GADIR="$RESULT"; fi
273 if [ ! -z "$SLDIR" ]; then
274 OLDSLDIR="$SLDIR"
275 dlg_input "SQL-Ledger web directory [$SLDIR]? "
276 if [ ! -z "$RESULT" ]; then SLDIR="$RESULT"; fi
279 # The following is to figure out the proper value for $web_root.
281 LOOKING=1
282 DOCROOT=`dirname $OEDIR`
283 OEFILE=`basename $OEDIR`
284 while [ $LOOKING -eq 1 ]; do
285 dlg_yesno "Is the Apache document root '$DOCROOT'?"
286 if [ $RESULT -eq 1 ]; then
287 LOOKING=0
288 else
289 OEFILE=`basename $DOCROOT`/$OEFILE
290 DOCROOT=`dirname $DOCROOT`
291 if [ "$DOCROOT" = "/" ]; then
292 LOOKING=0
293 OEFILE=`basename $OEDIR`
294 DOCROOT=`dirname $OEDIR`
295 dlg_msg "Never mind, I will assume '$DOCROOT'. You may need to manually correct" "the value of \$web_root in '$OEDIR/interface/globals.php'."
298 done
299 unset DOCROOT
303 # Patch up $GACONFIGDIR in case it was changed.
304 if [ -z "$GADIR" ]; then
305 if [ ! -z "$GACONFIGDIR" ]; then
306 GACONFIGDIR="$OEDIR/gacl"
308 else
309 GACONFIGDIR="$GADIR"
312 # If phpgacl has its own database, make sure the database user is not the
313 # same as for openemr. This is to prevent screwups caused by persistent
314 # database connections in PHP.
315 if [ ! -z "$GADBNAME" ]; then
316 if [ "$GADBUSER" = "$SLDBUSER" ]; then
317 dlg_msg "Error: OpenEMR and phpGACL have separate databases but the same user name." "They must be different user names."
318 exit 1
322 # The following sanity checks are an attempt to avoid disastrous results
323 # from mistakes in entry of directory path names.
325 TRASH=`expr "$OEDIR" : "[/]"`
326 if [ $TRASH -ne 1 ]; then
327 dlg_msg "Error: The OpenEMR directory path '$OEDIR' does not start with '/'."
328 exit 1
330 if [ -e "$OEDIR" -a ! -e "$OEDIR/interface/globals.php" ]; then
331 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."
332 exit 1
335 if [ ! -z "$GADIR" ]; then
336 TRASH=`expr "$GADIR" : "[/]"`
337 if [ $TRASH -ne 1 ]; then
338 dlg_msg "Error: The phpGACL directory path '$GADIR' does not start with '/'."
339 exit 1
341 if [ -e "$GADIR" -a ! -e "$GADIR/gacl.class.php" ]; then
342 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."
343 exit 1
347 if [ ! -z "$SLDIR" ]; then
348 TRASH=`expr "$SLDIR" : "[/]"`
349 if [ $TRASH -ne 1 ]; then
350 dlg_msg "Error: The SQL-Ledger directory path '$SLDIR' does not start with '/'."
351 exit 1
353 if [ -e "$SLDIR" -a ! -e "$SLDIR/setup.pl" ]; then
354 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."
355 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="\"I will restore the OpenEMR database backup to the MySQL database '$OEDBNAME'.\""
373 MARGS="$MARGS \"The OpenEMR database user will be '$OEDBUSER' with password '$OEDBPASS'.\""
374 if [ ! -z "$GADBNAME" ]; then
375 MARGS="$MARGS \"I will restore the phpGACL database backup to the MySQL database '$GADBNAME'.\""
376 MARGS="$MARGS \"The phpGACL database user will be '$GADBUSER' with password '$GADBPASS'.\""
379 if [ -z "$COLLATE" ]; then
380 MARGS="$MARGS \"MySQL will use its default character set and collation.\""
381 else
382 MARGS="$MARGS \"MySQL will use character set 'utf8' with collation '$COLLATE'.\""
385 if [ ! -z "$SLDBNAME" ]; then
386 MARGS="$MARGS \"I will restore the SQL-Ledger database backup to the PostgreSQL database '$SLDBNAME'.\""
387 MARGS="$MARGS \"The SQL-Ledger database user will be '$SLDBUSER' with password '$SLDBPASS'.\""
389 MARGS="$MARGS \"I will copy the OpenEMR web directory backup to '$OEDIR'.\""
390 if [ ! -z "$GADIR" ]; then
391 MARGS="$MARGS \"I will copy the phpGACL web directory backup to '$GADIR'.\""
393 if [ ! -z "$SLDIR" ]; then
394 MARGS="$MARGS \"I will copy the SQL-Ledger web directory backup to '$SLDIR'.\""
396 MARGS="$MARGS \" \""
397 MARGS="$MARGS \"Please check the above very carefully!\""
398 MARGS="$MARGS \"Any existing databases and directories matching these names will be DESTROYED.\""
399 MARGS="$MARGS \"Do you wish to continue?\""
401 eval "dlg_yesno $MARGS"
402 if [ $RESULT -ne 1 ]; then
403 exit 1
406 dlg_blank_line
408 dlg_msg "In order to create MySQL databases and users on this computer, I will need to" \
409 "log into MySQL as its 'root' user. The next question asks for the MySQL root" \
410 "user's password for this server, the one that you are restoring to. This is" \
411 "a MySQL password, not a system login password. Often it is blank."
412 dlg_input 'Enter the password, if any, for the MySQL root user:'
413 MYROOTPASS="$RESULT"
415 dlg_blank_line
417 dlg_info "Dropping old OpenEMR database if it exists ..."
418 mysqladmin --password="$MYROOTPASS" --force drop $OEDBNAME 2> /dev/null
420 dlg_info "Restoring OpenEMR database ..."
421 cd $BAKDIR
422 gunzip openemr.sql.gz
423 if [ $? -ne 0 ]; then
424 dlg_msg "Error: Could not decompress '$BAKDIR/openemr.sql.gz'."
425 exit 1
428 if [ -z $COLLATE ]; then
429 TRASH="CREATE DATABASE $OEDBNAME"
430 else
431 TRASH="CREATE DATABASE $OEDBNAME CHARACTER SET utf8 COLLATE $COLLATE"
433 mysql --password="$MYROOTPASS" --execute "$TRASH"
434 if [ $? -ne 0 ]; then
435 dlg_msg "Error creating MySQL database with '$TRASH'."
436 exit 1
439 mysql --password="$MYROOTPASS" --execute "GRANT ALL PRIVILEGES ON $OEDBNAME.* TO '$OEDBUSER'@'localhost' IDENTIFIED BY '$OEDBPASS'" $OEDBNAME
440 mysql --user=$OEDBUSER --password="$OEDBPASS" $OEDBNAME < openemr.sql
441 if [ $? -ne 0 ]; then
442 dlg_msg "Error: Restore to database '$OEDBNAME' failed."
443 exit 1
446 if [ ! -z "$GADBNAME" ]; then
447 dlg_info "Dropping old phpGACL database if it exists ..."
448 mysqladmin --password="$MYROOTPASS" --force drop $GADBNAME 2> /dev/null
449 dlg_info "Restoring phpGACL database ..."
450 cd $BAKDIR
451 gunzip phpgacl.sql.gz
452 if [ $? -ne 0 ]; then
453 dlg_msg "Error: Could not decompress '$BAKDIR/phpgacl.sql.gz'."
454 exit 1
457 if [ -z $COLLATE ]; then
458 TRASH="CREATE DATABASE $GADBNAME"
459 else
460 TRASH="CREATE DATABASE $GADBNAME CHARACTER SET utf8 COLLATE $COLLATE"
462 mysql --password="$MYROOTPASS" --execute "$TRASH"
463 if [ $? -ne 0 ]; then
464 dlg_msg "Error creating MySQL database with '$TRASH'."
465 exit 1
468 mysql --password="$MYROOTPASS" --execute "GRANT ALL PRIVILEGES ON $GADBNAME.* TO '$GADBUSER'@'localhost' IDENTIFIED BY '$GADBPASS'" $GADBNAME
469 mysql --user=$GADBUSER --password="$GADBPASS" $GADBNAME < phpgacl.sql
470 if [ $? -ne 0 ]; then
471 dlg_msg "Error: Restore to database '$GADBNAME' failed."
472 exit 1
476 if [ ! -z "$SLDBNAME" ]; then
477 # Avoid local domain connections for the sql-ledger user, because a
478 # default postgresql configuration is likely set to require "ident"
479 # authentication for them.
480 MYPGHOST=localhost
481 if [ ! -z "$PGHOST" ]; then
482 MYPGHOST="$PGHOST";
485 unset PGUSER
486 unset PGPASSWORD
487 dlg_info "Restarting Apache to close persistent database connections ..."
488 apache2ctl graceful
489 dlg_info "Dropping old SQL-Ledger database if it exists ..."
490 sudo -u postgres psql --command "DROP DATABASE \"$SLDBNAME\"" template1 2> /dev/null
491 dlg_info "Creating procedural language and database user ..."
492 sudo -u postgres createlang plpgsql template1 2> /dev/null
493 sudo -u postgres psql --command "DROP ROLE \"$SLDBUSER\"" template1 2> /dev/null
495 # This next part merits some comment. The database is best loaded by the
496 # sql-ledger user, otherwise we will have the nasty task of granting that
497 # user access to all of its tables individually, which PostgreSQL does not
498 # provide a convenient way of doing. However superuser privilege is needed
499 # to properly restore the dump. Therefore we give the new role superuser
500 # privilege now and revoke it after the restore is done.
502 sudo -u postgres psql --command "CREATE ROLE \"$SLDBUSER\" PASSWORD '$SLDBPASS' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN" template1
503 dlg_info "Creating and restoring SQL-Ledger database ..."
504 export PGUSER="$SLDBUSER"
505 export PGPASSWORD="$SLDBPASS"
506 psql -h $MYPGHOST --command "CREATE DATABASE \"$SLDBNAME\" WITH TEMPLATE template0" template1
507 if [ $? -ne 0 ]; then
508 dlg_msg "Error: Could not create PostgreSQL database '$SLDBNAME'."
509 exit 1
511 pg_restore -h $MYPGHOST --no-owner --dbname=$SLDBNAME sql-ledger.sql
512 if [ $? -ne 0 ]; then
513 dlg_msg "Error: Restore to database '$SLDBNAME' failed."
514 exit 1
516 unset PGUSER
517 unset PGPASSWORD
518 sudo -u postgres psql --command "ALTER ROLE \"$SLDBUSER\" NOSUPERUSER" template1
519 if [ $? -ne 0 ]; then
520 dlg_info "Warning: ALTER ROLE failed."
522 sudo -u postgres psql --command "ANALYZE" $SLDBNAME
525 dlg_info "Restoring OpenEMR web directory tree ..."
526 mkdir -p $OEDIR
527 rm -rf $OEDIR
528 mv $BAKDIR/openemr $OEDIR
529 if [ $? -ne 0 ]; then
530 dlg_msg "Error: Cannot create directory '$OEDIR'."
531 exit 1
534 if [ $CHANGES -gt 0 ]; then
535 dlg_info "Modifying $OEDIR/interface/globals.php ..."
536 cd $OEDIR/interface
537 mv -f globals.php globals.php.old
538 sed "s^$OLDOEDIR^$OEDIR^" globals.php.old | \
539 sed "/\\\$web_root *=/ c \$web_root = \"/$OEFILE\";" | \
540 sed "s^sl_dbname *= '.*'^sl_dbname = '$SLDBNAME'^" | \
541 sed "s^sl_dbuser *= '.*'^sl_dbuser = '$SLDBUSER'^" | \
542 sed "s^sl_dbpass *= '.*'^sl_dbpass = '$SLDBPASS'^" \
543 > globals.php
545 dlg_info "Modifying $OEDIR/library/sqlconf.php ..."
546 cd $OEDIR/library
547 mv sqlconf.php sqlconf.php.old
548 sed "s^dbase\t= '.*'^dbase\t= '$OEDBNAME'^" sqlconf.php.old | \
549 sed "s^login\t= '.*'^login\t= '$OEDBUSER'^" | \
550 sed "s^pass\t= '.*'^pass\t= '$OEDBPASS'^" > sqlconf.php
552 dlg_info "Modifying $OEDIR/includes/config.php ..."
553 SLFILE=`dirname /$OEFILE`
554 if [ "$SLFILE" = "/" ]; then
555 SLFILE="/sql-ledger"
556 else
557 SLFILE="$SLFILE/sql-ledger"
559 cd $OEDIR/includes
560 cp -f config.php config.php.old
561 sed "s^\"/.*/ws_server.pl\"^\"$SLFILE/ws_server.pl\"^" config.php.old > config.php
564 if [ ! -z "$GADIR" ]; then
565 dlg_info "Restoring phpGACL web directory tree ..."
566 mkdir -p $GADIR
567 rm -rf $GADIR
568 mv $BAKDIR/phpgacl $GADIR
569 if [ $? -ne 0 ]; then
570 dlg_msg "Error: Cannot create directory '$GADIR'."
571 exit 1
574 if [ $CHANGES -gt 0 ]; then
575 dlg_info "Modifying $OEDIR/library/acl.inc ..."
576 cd $OEDIR/library
577 mv -f acl.inc acl.inc.old
578 sed "s^$OLDGADIR^$GADIR^" acl.inc.old > acl.inc
582 if [ ! -z "$GACONFIGDIR" -a $CHANGES -gt 0 ]; then
583 if [ -z "$GADBNAME" ]; then
584 GADBNAME="$OEDBNAME"
585 GADBUSER="$OEDBUSER"
586 GADBPASS="$OEDBPASS"
589 dlg_info "Modifying $GACONFIGDIR/gacl.class.php ..."
590 cd $GACONFIGDIR
591 mv -f gacl.class.php gacl.class.php.old
592 sed "s^db_name *= *'.*'^db_name = '$GADBNAME'^" gacl.class.php.old | \
593 sed "s^db_user *= *'.*'^db_user = '$GADBUSER'^" | \
594 sed "s^db_password *= *'.*'^db_password = '$GADBPASS'^" > gacl.class.php
596 dlg_info "Modifying $GACONFIGDIR/gacl.ini.php ..."
597 cd $GACONFIGDIR
598 mv -f gacl.ini.php gacl.ini.php.old
599 sed "s^db_name[ \t]*= *\".*\"^db_name\t\t\t= \"$GADBNAME\"^" gacl.ini.php.old | \
600 sed "s^db_user[ \t]*= *\".*\"^db_user\t\t\t= \"$GADBUSER\"^" | \
601 sed "s^db_password[ \t]*= *\".*\"^db_password\t\t= \"$GADBPASS\"^" > gacl.ini.php
604 if [ ! -z "$SLDIR" ]; then
605 dlg_info "Restoring SQL-Ledger web directory tree ..."
606 mkdir -p $SLDIR
607 rm -rf $SLDIR
608 mkdir $SLDIR
609 cd $SLDIR
610 if [ $? -ne 0 ]; then
611 dlg_msg "Error: Creating $SLDIR failed."
612 exit 1
614 tar zxf $BAKDIR/sql-ledger.tar.gz
615 if [ $? -ne 0 ]; then
616 dlg_msg "Error: Extracting '$BAKDIR/sql-ledger.tar.gz' failed."
617 exit 1
620 if [ $CHANGES -gt 0 ]; then
621 # SQL-Ledger stores passwords in an obfuscated form.
622 SLDBHASH=`perl -e "print pack u, '$SLDBPASS'"`
624 dlg_info "Modifying $SLDIR/ws_server.pl ..."
625 cd $SLDIR
626 mv -f ws_server.pl ws_server.pl.old
627 sed "s^$OLDSLDIR^$SLDIR^" ws_server.pl.old > ws_server.pl
628 chmod a+x ws_server.pl
630 dlg_info "Modifying $SLDIR/users/admin.conf ..."
631 cd $SLDIR/users
632 cp -f admin.conf admin.conf.old
633 sed "s^dbname => '.*'^dbname => '$SLDBNAME'^" admin.conf.old | \
634 sed "s^dbuser => '.*'^dbuser => '$SLDBUSER'^" | \
635 sed "/dbpasswd =>/ c \ dbpasswd => '$SLDBHASH'," | \
636 sed "s^dbname=$OLDSLDBNAME^dbname=$SLDBNAME^" > admin.conf
638 dlg_info "Modifying $SLDIR/users/members ..."
639 cd $SLDIR/users
640 cp -f members members.old
641 sed "s^dbname=.*^dbname=$SLDBNAME^g" members.old | \
642 sed "s^dbuser=.*^dbuser=$SLDBUSER^g" | \
643 sed "/dbpasswd=/ c dbpasswd=$SLDBHASH" > members
647 dlg_msg "All done."