5 # upgrade.pl - automatic phpmyadmin upgrader
8 # 2005-05-08, swix@users.sourceforge.net:
11 # 2005-10-29 swix@users.sourceforge.net:
12 # - some fixes & improvements
16 my $source_url = "http://phpmyadmin.net/home_page/version.php";
23 if (!$ARGV[0] || (($ARGV[0] eq "--force") && !$ARGV[1])) {
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";
35 if ($ARGV[0] eq "--force") {
37 $targetdirectory = $ARGV[1];
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";
53 if (!-f
"$targetdirectory/config.inc.php") {
54 print "error: target directory doesn't seem to contain phpMyAdmin\n";
60 # get current release information
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";
80 while (my $line = <LATEST
>) {
82 if ($line =~ /http/) {
91 print "error: open of $source_url failed.\n";
98 print "error: target directory ($directory) already exists, exiting\n";
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";
131 } elsif ($installedversion eq $version && !$forced) {
132 print "Local version ($version) already up to date, not updating (you can use \"--force\")\n";
139 if (!$versionStatus && !$forced) {
140 print "Old version could not be identified, not updating (use \"--force\" if you are sure) \n";
146 # ask for confirmation
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) {
161 print "Proceeding...\n\n";
171 print "getting phpMyAdmin $version\n";
172 foreach my $url (@urls) {
174 print "trying $url...\n";
175 system("wget -o /dev/null $url");
182 print "already got $filename, not downloading\n";
187 print "error: $filename download failed\n";
197 print "installing...\n";
199 system("tar xzf $filename");
201 print "error: $directory still not exists after untar...\n";
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";