Wrap long line
[phpmyadmin/madhuracj.git] / scripts / upgrade.pl
blob7f142940ba3f8d4af4e2f023de51eb1f245458a0
1 #!/usr/bin/perl
4 # upgrade.pl - automatic phpmyadmin upgrader
7 # 2005-05-08, swix@users.sourceforge.net:
8 # - created script
10 # 2005-10-29 swix@users.sourceforge.net:
11 # - some fixes & improvements
14 use strict;
15 my $source_url = "http://phpmyadmin.net/home_page/version.php";
19 # usage
22 if (!$ARGV[0] || (($ARGV[0] eq "--force") && !$ARGV[1])) {
23 print "\n";
24 print "usage: $0 [--force] <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 $forced;
32 my $targetdirectory;
34 if ($ARGV[0] eq "--force") {
35 $forced = 1;
36 $targetdirectory = $ARGV[1];
37 } else {
38 $forced = 0;
39 $targetdirectory = $ARGV[0];
42 if ($targetdirectory =~ /^(.*)\/$/) {
43 # remove trailing slash, if any
44 $targetdirectory = $1;
47 if (!-d $targetdirectory) {
48 print "error: target directory ($targetdirectory) does not exists\n";
49 exit(0);
52 if (!-f "$targetdirectory/config.inc.php") {
53 print "error: target directory doesn't seem to contain phpMyAdmin\n";
54 exit(0);
59 # get current release information
62 my $version;
63 my $filename;
64 my $directory;
65 my $releasedate;
66 my @urls;
67 my @today;
68 my $installedversion;
70 if (open(LATEST, "wget -o /dev/null -O - $source_url|")) {
72 $version = <LATEST>; chomp($version);
73 $releasedate = <LATEST>; chomp($releasedate);
74 $filename = "phpMyAdmin-" . $version . "-all-languages.tar.gz";
75 $directory = "phpMyAdmin-" . $version . "-all-languages";
77 my $i = 0;
79 while (my $line = <LATEST>) {
80 chomp($line);
81 if ($line =~ /http/) {
82 $urls[$i++] = $line;
86 close(LATEST);
88 } else {
90 print "error: open of $source_url failed.\n";
91 exit(0);
96 if (-d $directory) {
97 print "error: target directory ($directory) already exists, exiting\n";
98 exit(0);
102 # check the installed version
105 if (open(DEFINES, $targetdirectory .'/libraries/Config.class.php')) {
106 my $versionStatus = 0;
107 $installedversion = "unknownversion";
109 while (my $line = <DEFINES>) {
111 next unless $line =~ /'PMA_VERSION',\ '(.*)?'\);$/;
112 $installedversion = $1;
114 # take care of "pl", "rc" and "dev": dev < rc < pl
116 my $converted_installedversion = $installedversion;
117 $converted_installedversion =~ s/dev/aaa/g;
118 $converted_installedversion =~ s/rc/bbb/g;
119 $converted_installedversion =~ s/pl/ccc/g;
121 my $converted_version = $version;
122 $converted_version =~ s/dev/aaa/g;
123 $converted_version =~ s/rc/bbb/g;
124 $converted_version =~ s/pl/ccc/g;
126 if ($converted_installedversion gt $converted_version && !$forced) {
127 print "Local version ($installedversion) newer than latest stable release ($version), not updating. (use \"--force\")\n";
128 exit(0);
130 } elsif ($installedversion eq $version && !$forced) {
131 print "Local version ($version) already up to date, not updating (you can use \"--force\")\n";
132 exit(0);
134 } else {
135 $versionStatus = 1;
138 if (!$versionStatus && !$forced) {
139 print "Old version could not be identified, not updating (use \"--force\" if you are sure) \n";
140 exit(0);
145 # ask for confirmation
148 print "\n";
149 print "phpMyAdmin upgrade summary:\n";
150 print "---------------------------\n";
151 print " phpMyAdmin Path: $targetdirectory\n";
152 print " Installed version: $installedversion\n";
153 print " Upgraded version: $version\n\n";
154 print "Proceed with upgrade? [Y/n] ";
155 my $kbdinput = <STDIN>; chomp($kbdinput);
156 if (lc(substr($kbdinput,0,1)) ne "y" && length($kbdinput) >= 1) {
157 print "Aborting.\n";
158 exit(0);
159 } else {
160 print "Proceeding...\n\n";
165 # get file
168 if (!-f $filename) {
170 print "getting phpMyAdmin $version\n";
171 foreach my $url (@urls) {
173 print "trying $url...\n";
174 system("wget -o /dev/null $url");
175 if (-f $filename) {
176 print "-> ok\n";
177 last;
180 } else {
181 print "already got $filename, not downloading\n";
185 if (!-f $filename) {
186 print "error: $filename download failed\n";
187 exit(0);
193 # setup
196 print "installing...\n";
198 system("tar xzf $filename");
199 if (!$directory) {
200 print "error: $directory still not exists after untar...\n";
201 exit(0);
204 @today = localtime(time); $today[4]++; $today[5]+=1900;
205 my $timestamp = sprintf("%04d%02d%02d%02d%02d", $today[5], $today[4], $today[3], $today[2], $today[1]);
207 my $backupdir = $targetdirectory . "-" . $timestamp . "-" . $installedversion;
208 print "- backup directory: $backupdir\n";
210 system("cp $directory/config.inc.php $directory/config.inc-dist.php");
211 print "- original distribution config.inc.php renamed to config.inc-dist.php\n";
213 system("cp $targetdirectory/config.inc.php $directory/config.inc.php");
214 print "- previous config.inc.php copied to the new setup\n";
216 system("mv $targetdirectory $backupdir");
217 system("mv $directory $targetdirectory");
218 system("rm $filename");
220 print "\ndone! phpMyAdmin $version installed in $targetdirectory\n";
221 print "backup of your old installation in $backupdir\n";
222 print "Enjoy! :-)\n\n";