-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtomcat_upgrade.cgi
More file actions
135 lines (104 loc) · 3.69 KB
/
tomcat_upgrade.cgi
File metadata and controls
135 lines (104 loc) · 3.69 KB
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
#!/usr/bin/perl
require './tomcat-lib.pl';
sub select_tomcat_archive{
print "$text{'base_desc2'}<p>\n";
print &ui_form_start("tomcat_upgrade.cgi", "form-data");
print ui_hidden('mode', 'tomcat_upgrade');
print &ui_table_start($text{'base_options'}, undef, 2);
my $install_ver = installed_tomcat_version();
my $install_major = (split /\./, $install_ver)[0];
if($in{'tmver'}){
$install_major = $in{'tmver'};
}
my @tmver = &get_tomcat_major_versions();
my $sel_tmver = $install_major;
my @tm_opts = ( );
foreach my $v (@tmver) {
push(@tm_opts, [ $v, $v ]);
}
print <<EOF;
<script type="text/javascript">
function update_select(){
var majorSel = document.getElementById('base_major');
var major = majorSel.options[majorSel.selectedIndex].value;
get_pjax_content('/tomcat/tomcat_upgrade.cgi?mode=select_version&tmver='+major);
}
</script>
EOF
print &ui_table_row($text{'base_major'},
&ui_select("base_major", $sel_tmver, \@tm_opts, 1, 0, undef, undef, 'id="base_major" onchange="update_select()"'));
my @tver = &major_tomcat_versions($sel_tmver);
my @tver_opts = ( );
foreach my $v (reverse @tver) {
push(@tver_opts, [ $v, $v ]);
}
print &ui_table_row($text{'base_installsource'},
&ui_radio_table("source", 100,
[ [ 100, $text{'source_archive'}, &ui_select("source_archive", undef, \@tver_opts,1, 0)],
]));
print &ui_table_end();
print &ui_form_end([ [ "", $text{'base_upgradeok'} ] ]);
}
sub migrate_settings_and_apps{
my $old_ver = $_[0];
my $new_ver = $_[1];
my $apps_ref = $_[2];
#Copy Settings
my @files = ('bin/setenv.sh', 'conf/tomcat-users.xml');
foreach my $file (@files){
if( -f "/home/tomcat/apache-tomcat-$old_ver/$file"){
copy_source_dest("/home/tomcat/apache-tomcat-$old_ver/$file",
"/home/tomcat/apache-tomcat-$new_ver/$file");
print "Copying $file to /home/tomcat/apache-tomcat-$new_ver/$file<br>";
}
}
#make a list of installed apps
my @exclude_apps = ('docs', 'examples', 'host-manager', 'manager', 'ROOT');
#move apps
print "Copying apps ...<br>";
foreach my $app (@$apps_ref){
next if grep( /^$app$/, @exclude_apps);
if(!copy_source_dest( "/home/tomcat/apache-tomcat-$old_ver/webapps/$app",
"/home/tomcat/apache-tomcat-$new_ver/webapps/$app")){
&error("Error: Can't copy $app: $!");
}else{
print "$app<br>";
}
if(-f "/home/tomcat/apache-tomcat-$old_ver/webapps/$app.war"){
if(!copy_source_dest( "/home/tomcat/apache-tomcat-$old_ver/webapps/$app.war",
"/home/tomcat/apache-tomcat-$new_ver/webapps/$app.war")){
&error("Error: Can't copy $app.war: $!");
}else{
print "$app.war<br>";
}
}
}
}
sub upgrade_tomcat_from_archive{
my $install_ver = installed_tomcat_version();
my $latest_ver = $_[0];
my @installed_apps = get_all_war_infos();
#add_tomcat_user();
download_and_install($latest_ver);
tomcat_service_ctl('stop');
setup_catalina_env($latest_ver);
#setup_tomcat_users($latest_ver);
setup_tomcat_service($latest_ver);
migrate_settings_and_apps($install_ver, $latest_ver, \@installed_apps);
print("Update done, starting new Tomcat ".$latest_ver);
tomcat_service_ctl('start');
}
&ui_print_header(undef, $text{'index_title_upgrade'}, "", "intro", 1, 1);
if($ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/) {
&ReadParseMime();
}else {
&ReadParse(); $no_upload = 1;
}
&error_setup($text{'start_err'});
my $mode = $in{'mode'} || "select_version";
if($mode eq "select_version"){
select_tomcat_archive();
}elsif($mode eq "tomcat_upgrade"){
$err = upgrade_tomcat_from_archive($in{'source_archive'});
}
&ui_print_footer("", $text{'index_return'});