Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / scripts / upgrade.pl
blobc9e625e16c50126ccbccec2014911e9cc683eeb8
1 #!/usr/bin/perl
3 # $Id$
5 # upgrade.pl - automatic phpmyadmin upgrader
8 # 2005-05-08, swix@users.sourceforge.net:
9 # - created script
11 # 2005-10-29 swix@users.sourceforge.net:
12 # - some fixes & improvements
15 use strict;
16 my $source_url = "http://phpmyadmin.net/home_page/version.php";
20 # usage
23 if (!$ARGV[0] || (($ARGV[0] eq "--force") && !$ARGV[1])) {
24 print "\n";
25 print "usage: $0 [--force] <target_directory>\n\n";
26 print " The location specified by <target_directory> will be backed up and replaced\n";
27 print " by the latest stable version of phpMyAdmin.\n";
28 print " Your config.inc.php file will be preserved.\n\n";
29 exit(0);
32 my $forced;
33 my $targetdirectory;
35 if ($ARGV[0] eq "--force") {
36 $forced = 1;
37 $targetdirectory = $ARGV[1];
38 } else {
39 $forced = 0;
40 $targetdirectory = $ARGV[0];
43 if ($targetdirectory =~ /^(.*)\/$/) {
44 # remove trailing slash, if any
45 $targetdirectory = $1;
48 if (!-d $targetdirectory) {
49 print "error: target directory ($targetdirectory) does not exists\n";
50 exit(0);
53 if (!-f "$targetdirectory/config.inc.php") {
54 print "error: target directory doesn't seem to contain phpMyAdmin\n";
55 exit(0);
60 # get current release information
63 my $version;
64 my $filename;
65 my $directory;
66 my $releasedate;
67 my @urls;
68 my @today;
69 my $installedversion;
71 if (open(LATEST, "wget -o /dev/null -O - $source_url|")) {
73 $version = <LATEST>; chomp($version);
74 $releasedate = <LATEST>; chomp($releasedate);
75 $filename = "phpMyAdmin-" . $version . "-all-languages.tar.gz";
76 $directory = "phpMyAdmin-" . $version . "-all-languages";
78 my $i = 0;
80 while (my $line = <LATEST>) {
81 chomp($line);
82 if ($line =~ /http/) {
83 $urls[$i++] = $line;
87 close(LATEST);
89 } else {
91 print "error: open of $source_url failed.\n";
92 exit(0);
97 if (-d $directory) {
98 print "error: target directory ($directory) already exists, exiting\n";
99 exit(0);
103 # check the installed version
106 if (open(DEFINES, $targetdirectory .'/libraries/Config.class.php')) {
107 my $versionStatus = 0;
108 $installedversion = "unknownversion";
110 while (my $line = <DEFINES>) {
112 next unless $line =~ /'PMA_VERSION',\ '(.*)?'\);$/;
113 $installedversion = $1;
115 # take care of "pl", "rc" and "dev": dev < rc < pl
117 my $converted_installedversion = $installedversion;
118 $converted_installedversion =~ s/dev/aaa/g;
119 $converted_installedversion =~ s/rc/bbb/g;
120 $converted_installedversion =~ s/pl/ccc/g;
122 my $converted_version = $version;
123 $converted_version =~ s/dev/aaa/g;
124 $converted_version =~ s/rc/bbb/g;
125 $converted_version =~ s/pl/ccc/g;
127 if ($converted_installedversion gt $converted_version && !$forced) {
128 print "Local version ($installedversion) newer than latest stable release ($version), not updating. (use \"--force\")\n";
129 exit(0);
131 } elsif ($installedversion eq $version && !$forced) {
132 print "Local version ($version) already up to date, not updating (you can use \"--force\")\n";
133 exit(0);
135 } else {
136 $versionStatus = 1;
139 if (!$versionStatus && !$forced) {
140 print "Old version could not be identified, not updating (use \"--force\" if you are sure) \n";
141 exit(0);
146 # ask for confirmation
149 print "\n";
150 print "phpMyAdmin upgrade summary:\n";
151 print "---------------------------\n";
152 print " phpMyAdmin Path: $targetdirectory\n";
153 print " Installed version: $installedversion\n";
154 print " Upgraded version: $version\n\n";
155 print "Proceed with upgrade? [Y/n] ";
156 my $kbdinput = <STDIN>; chomp($kbdinput);
157 if (lc(substr($kbdinput,0,1)) ne "y" && length($kbdinput) >= 1) {
158 print "Aborting.\n";
159 exit(0);
160 } else {
161 print "Proceeding...\n\n";
166 # get file
169 if (!-f $filename) {
171 print "getting phpMyAdmin $version\n";
172 foreach my $url (@urls) {
174 print "trying $url...\n";
175 system("wget -o /dev/null $url");
176 if (-f $filename) {
177 print "-> ok\n";
178 last;
181 } else {
182 print "already got $filename, not downloading\n";
186 if (!-f $filename) {
187 print "error: $filename download failed\n";
188 exit(0);
194 # setup
197 print "installing...\n";
199 system("tar xzf $filename");
200 if (!$directory) {
201 print "error: $directory still not exists after untar...\n";
202 exit(0);
205 @today = localtime(time); $today[4]++; $today[5]+=1900;
206 my $timestamp = sprintf("%04d%02d%02d%02d%02d", $today[5], $today[4], $today[3], $today[2], $today[1]);
208 my $backupdir = $targetdirectory . "-" . $timestamp . "-" . $installedversion;
209 print "- backup directory: $backupdir\n";
211 system("cp $directory/config.inc.php $directory/config.inc-dist.php");
212 print "- original distribution config.inc.php renamed to config.inc-dist.php\n";
214 system("cp $targetdirectory/config.inc.php $directory/config.inc.php");
215 print "- previous config.inc.php copied to the new setup\n";
217 system("mv $targetdirectory $backupdir");
218 system("mv $directory $targetdirectory");
219 system("rm $filename");
221 print "\ndone! phpMyAdmin $version installed in $targetdirectory\n";
222 print "backup of your old installation in $backupdir\n";
223 print "Enjoy! :-)\n\n";