5 # upgrade.pl - automatic phpmyadmin upgrader
8 # 2005-05-08, swix@users.sourceforge.net:
15 my $source_url = "http://www.phpmyadmin.net/latest.txt";
24 print "usage: $0 <target_directory>\n\n";
25 print " The location specified by <target_directory> will be backed up and replaced\n";
26 print " by the latest stable version of phpMyAdmin.\n";
27 print " Your config.inc.php file will be preserved.\n\n";
31 my $targetdirectory = $ARGV[0];
32 if ($targetdirectory =~ /^(.*)\/$/) {
33 # remove trailing slash, if any
34 $targetdirectory = $1;
37 if (!-d
$targetdirectory) {
38 print "error: target directory ($targetdirectory) does not exists\n";
42 if (!-f
"$targetdirectory/config.inc.php") {
43 print "error: target directory doesn't seem to contain phpMyAdmin\n";
49 # get current release information
58 if (open(LATEST
, "wget -o /dev/null -O - $source_url|")) {
60 $version = <LATEST
>; chomp($version);
61 $releasedate = <LATEST
>; chomp($releasedate);
62 $filename = "phpMyAdmin-" . $version . ".tar.gz";
63 $directory = "phpMyAdmin-" . $version;
67 while(my $line = <LATEST
>) {
69 if ($line =~ /http/) {
78 print "error: open failed.\n";
85 print "error: target directory ($directory) already exists, exiting\n";
90 # check the installed version
93 if (open(DEFINES
, $targetdirectory .'/libraries/defines.lib.php')) {
94 my $versionStatus = 0;
95 while(my $line = <DEFINES
>) {
97 next unless $line =~ /'PMA_VERSION',\ '(.*)?'\);$/;
100 print "Local version newer than latest stable release, not updating.\n";
103 } elsif ($1 eq $version) {
104 print "Local version already up to date, not updating\n";
111 if (!$versionStatus) {
112 print "Old version could not be identified, not updating\n";
123 print "getting phpMyAdmin $version\n";
124 foreach my $url (@urls) {
126 print "trying $url...\n";
127 system("wget -o /dev/null $url");
134 print "already got $filename, not downloading\n";
139 print "error: $filename download failed\n";
149 print "installing...\n";
151 system("tar xzf $filename");
153 print "error: $directory still not exists after untar...\n";
157 my $backupdir = $targetdirectory . "-" . time;
158 print "- backup directory: $backupdir\n";
160 system("cp $directory/config.inc.php $directory/config.inc-dist.php");
161 print "- original config.inc.php renamed to config.inc-dist.php\n";
163 system("cp $targetdirectory/config.inc.php $directory/config.inc.php");
164 system("mv $targetdirectory $backupdir");
165 system("mv $directory $targetdirectory");
168 print "\ndone! phpMyAdmin $version installed in $targetdirectory\n";
169 print "backup of your old installation in $backupdir\n";
170 print "downloaded archive saved as $filename\n\n";
171 print "Enjoy! :-)\n\n";