patch #1250935, interface improvements
[phpmyadmin/crack.git] / scripts / upgrade.pl
blob06af2a8e6816203751052a08f9634633f7a39f43
1 #!/usr/bin/perl
3 # $Id$
5 # upgrade.pl - automatic phpmyadmin upgrader
6 #
8 # 2005-05-08, swix@users.sourceforge.net:
9 # - created script
14 use strict;
15 my $source_url = "http://www.phpmyadmin.net/latest.txt";
19 # usage
22 if (!$ARGV[0]) {
23 print "\n";
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";
28 exit(0);
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";
39 exit(0);
42 if (!-f "$targetdirectory/config.inc.php") {
43 print "error: target directory doesn't seem to contain phpMyAdmin\n";
44 exit(0);
49 # get current release information
52 my $version;
53 my $filename;
54 my $directory;
55 my $releasedate;
56 my @urls;
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;
65 my $i = 0;
67 while(my $line = <LATEST>) {
68 chomp($line);
69 if ($line =~ /http/) {
70 $urls[$i++] = $line;
74 close(LATEST);
76 } else {
78 print "error: open failed.\n";
79 exit(0);
84 if (-d $directory) {
85 print "error: target directory ($directory) already exists, exiting\n";
86 exit(0);
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',\ '(.*)?'\);$/;
99 if ($1 gt $version) {
100 print "Local version newer than latest stable release, not updating.\n";
101 exit(0);
103 } elsif ($1 eq $version) {
104 print "Local version already up to date, not updating\n";
105 exit(0);
107 } else {
108 $versionStatus = 1;
111 if (!$versionStatus) {
112 print "Old version could not be identified, not updating\n";
113 exit(0);
118 # get file
121 if (!-f $filename) {
123 print "getting phpMyAdmin $version\n";
124 foreach my $url (@urls) {
126 print "trying $url...\n";
127 system("wget -o /dev/null $url");
128 if (-f $filename) {
129 print "-> ok\n";
130 last;
133 } else {
134 print "already got $filename, not downloading\n";
138 if (!-f $filename) {
139 print "error: $filename download failed\n";
140 exit(0);
146 # setup
149 print "installing...\n";
151 system("tar xzf $filename");
152 if (!$directory) {
153 print "error: $directory still not exists after untar...\n";
154 exit(0);
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";