1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#!/usr/bin/perl
#
# $Id: upgrade.pl 8301 2006-01-17 17:03:02Z cybot_tm $
#
# upgrade.pl - automatic phpmyadmin upgrader
#
#
# 2005-05-08, swix@users.sourceforge.net:
# - created script
#
# 2005-10-29 swix@users.sourceforge.net:
# - some fixes & improvements
#
use strict;
my $source_url = "http://phpmyadmin.net/home_page/version.php";
#
# usage
#
if (!$ARGV[0] || (($ARGV[0] eq "--force") && !$ARGV[1])) {
print "\n";
print "usage: $0 [--force] <target_directory>\n\n";
print " The location specified by <target_directory> will be backed up and replaced\n";
print " by the latest stable version of phpMyAdmin.\n";
print " Your config.inc.php file will be preserved.\n\n";
exit(0);
}
my $forced;
my $targetdirectory;
if ($ARGV[0] eq "--force") {
$forced = 1;
$targetdirectory = $ARGV[1];
} else {
$forced = 0;
$targetdirectory = $ARGV[0];
}
if ($targetdirectory =~ /^(.*)\/$/) {
# remove trailing slash, if any
$targetdirectory = $1;
}
if (!-d $targetdirectory) {
print "error: target directory ($targetdirectory) does not exists\n";
exit(0);
}
if (!-f "$targetdirectory/config.inc.php") {
print "error: target directory doesn't seem to contain phpMyAdmin\n";
exit(0);
}
#
# get current release information
#
my $version;
my $filename;
my $directory;
my $releasedate;
my @urls;
my @today;
my $installedversion;
if (open(LATEST, "wget -o /dev/null -O - $source_url|")) {
$version = <LATEST>; chomp($version);
$releasedate = <LATEST>; chomp($releasedate);
$filename = "phpMyAdmin-" . $version . ".tar.gz";
$directory = "phpMyAdmin-" . $version;
my $i = 0;
while (my $line = <LATEST>) {
chomp($line);
if ($line =~ /http/) {
$urls[$i++] = $line;
}
}
close(LATEST);
} else {
print "error: open of $source_url failed.\n";
exit(0);
}
if (-d $directory) {
print "error: target directory ($directory) already exists, exiting\n";
exit(0);
}
#
# check the installed version
#
if (open(DEFINES, $targetdirectory .'/libraries/Config.class.php')) {
my $versionStatus = 0;
$installedversion = "unknownversion";
while (my $line = <DEFINES>) {
next unless $line =~ /'PMA_VERSION',\ '(.*)?'\);$/;
$installedversion = $1;
# take care of "pl", "rc" and "dev": dev < rc < pl
my $converted_installedversion = $installedversion;
$converted_installedversion =~ s/dev/aaa/g;
$converted_installedversion =~ s/rc/bbb/g;
$converted_installedversion =~ s/pl/ccc/g;
my $converted_version = $version;
$converted_version =~ s/dev/aaa/g;
$converted_version =~ s/rc/bbb/g;
$converted_version =~ s/pl/ccc/g;
if ($converted_installedversion gt $converted_version && !$forced) {
print "Local version ($installedversion) newer than latest stable release ($version), not updating. (use \"--force\")\n";
exit(0);
} elsif ($installedversion eq $version && !$forced) {
print "Local version ($version) already up to date, not updating (you can use \"--force\")\n";
exit(0);
} else {
$versionStatus = 1;
}
}
if (!$versionStatus && !$forced) {
print "Old version could not be identified, not updating (use \"--force\" if you are sure) \n";
exit(0);
}
}
#
# ask for confirmation
#
print "\n";
print "phpMyAdmin upgrade summary:\n";
print "---------------------------\n";
print " phpMyAdmin Path: $targetdirectory\n";
print " Installed version: $installedversion\n";
print " Upgraded version: $version\n\n";
print "Proceed with upgrade? [Y/n] ";
my $kbdinput = <STDIN>; chomp($kbdinput);
if (lc(substr($kbdinput,0,1)) ne "y" && length($kbdinput) >= 1) {
print "Aborting.\n";
exit(0);
} else {
print "Proceeding...\n\n";
}
#
# get file
#
if (!-f $filename) {
print "getting phpMyAdmin $version\n";
foreach my $url (@urls) {
print "trying $url...\n";
system("wget -o /dev/null $url");
if (-f $filename) {
print "-> ok\n";
last;
}
}
} else {
print "already got $filename, not downloading\n";
}
if (!-f $filename) {
print "error: $filename download failed\n";
exit(0);
}
#
# setup
#
print "installing...\n";
system("tar xzf $filename");
if (!$directory) {
print "error: $directory still not exists after untar...\n";
exit(0);
}
@today = localtime(time); $today[4]++; $today[5]+=1900;
my $timestamp = sprintf("%04d%02d%02d%02d%02d", $today[5], $today[4], $today[3], $today[2], $today[1]);
my $backupdir = $targetdirectory . "-" . $timestamp . "-" . $installedversion;
print "- backup directory: $backupdir\n";
system("cp $directory/config.inc.php $directory/config.inc-dist.php");
print "- original distribution config.inc.php renamed to config.inc-dist.php\n";
system("cp $targetdirectory/config.inc.php $directory/config.inc.php");
print "- previous config.inc.php copied to the new setup\n";
system("mv $targetdirectory $backupdir");
system("mv $directory $targetdirectory");
system("rm $filename");
print "\ndone! phpMyAdmin $version installed in $targetdirectory\n";
print "backup of your old installation in $backupdir\n";
print "Enjoy! :-)\n\n";
|