forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.pl
executable file
·145 lines (107 loc) · 2.63 KB
/
upgrade.pl
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
#!/usr/bin/perl
#
# $Id$
#
# upgrade.pl - automatic phpmyadmin upgrader
#
#
# 2005-05-08, swix@users.sourceforge.net:
# - created script
#
# TODO: check if current version is not already uptodate
# (let's assume the sysadmin still has a brain... :-)
#
use strict;
my $source_url = "http://www.phpmyadmin.net/latest.txt";
#
# usage
#
if (!$ARGV[0]) {
print "\n";
print "usage: upgrade.pl target_directory\n\n";
print " target_directory will be backuped and replaced\n";
print " by the current version of phpMyAdmin, by keeping your\n";
print " config.inc.php file.\n\n";
exit(0);
}
my $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;
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 failed.\n";
exit(0);
}
if (-d $directory) {
print "error: target directory ($directory) already exists, exiting\n";
exit(0);
}
#
# 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 (!-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);
}
my $backupdir = $targetdirectory . "-" . time;
print "- backup directory: $backupdir\n";
system("cp $directory/config.inc.php $directory/config.inc-dist.php");
print "- original config.inc.php renamed to config.inc-dist.php\n";
system("cp $targetdirectory/config.inc.php $directory/config.inc.php");
system("mv $targetdirectory $backupdir");
system("mv $directory $targetdirectory");
print "\ndone! phpMyAdmin $version installed in $directory\n";
print "backup of your old installation in $backupdir\n\n";
print "Enjoy! :-)\n\n";