File: upgrade.pl

package info (click to toggle)
apt-cacher 0.9.4sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 268 kB
  • ctags: 224
  • sloc: perl: 1,862; makefile: 495; sh: 37
file content (124 lines) | stat: -rwxr-xr-x 4,161 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w
#	@(#) remove.pl -- Upgrade script for apt-cacher
#	$ Revision: $
#	$ Source: $
#	$ Date: $
# This script is actually almost identical to the remove script, except that
# on upgrade we don't want to nuke the cache contents so that part is commented
# out. We also don't want to restart Apache twice (it already gets done by the
# install script that gets run at the end of the upgrade, and even that's not
# necessary).

my $path = $ENV{PATH_INFO};
#############################################################################
### configuration ###########################################################
# Include the library for the config file parser
require '/usr/share/apt-cacher/apt-cacher-lib.pl';

# Read in the config file and set the necessary variables
my $configfile = '/etc/apt-cacher/apt-cacher.conf';

my $configref;
eval {
        $configref = read_config($configfile);
};
my %config = %$configref;

# not sure what to do if we can't read the config file...
die "Could not read config file: $@" if $@;

# Now set some things from the config file
# $logfile used to be set in the config file: now we derive it from $logdir
$config{logfile} = "$config{logdir}/access.log";

# $errorfile used to be set in the config file: now we derive it from $logdir
$config{errorfile} = "$config{logdir}/error.log";

my $private_dir = "$config{cache_dir}/private";

################################################

# Now set some things from the config file
$config{reportfile} = "$config{logdir}/report.html";




# Remove the include lines from Apache's httpd.conf
# This should really be turned into a function so I don't have to
# copy the whole lot for Apache-SSL!
my $httpdconf = "/etc/apache/httpd.conf";
if (-f $httpdconf) {
	$old = $httpdconf;
	$new = "$httpdconf.tmp.$$";
	$bak = "$httpdconf.bak";
	
	open(OLD, "< $old")         or die "can't open $old: $!";
	open(NEW, "> $new")         or die "can't open $new: $!";
	
	while (<OLD>) {
		s/# This line has been appended by the Apt\-cacher install script/ /;
		s/Include \/etc\/apt\-cacher\/apache.conf/ /;
		(print NEW $_)          or die "can't write to $new: $!";
	}
	
	close(OLD)                  or die "can't close $old: $!";
	close(NEW)                  or die "can't close $new: $!";
	
	rename($old, $bak)          or die "can't rename $old to $bak: $!";
	rename($new, $old)          or die "can't rename $new to $old: $!";
	
	## Restart Apache
	#if ( -f "/etc/init.d/apache" ) {
	#	print "Restarting Apache (if you have an SSL cert password, enter it now):";
	#	`/etc/init.d/apache restart`;
	#	print "... done.\n";
	#} else {
	#	print "Apache startup script was not found. Please restart Apache manually.\n";
	#}
}

# Remove the include lines from Apache-SSL's httpd.conf
# This should really be turned into a function so I don't have to
# copy the whole lot for Apache-SSL!
$httpdconf = "/etc/apache-ssl/httpd.conf";
if (-f $httpdconf) {
	$old = $httpdconf;
	$new = "$httpdconf.tmp.$$";
	$bak = "$httpdconf.bak";
	
	open(OLD, "< $old")         or die "can't open $old: $!";
	open(NEW, "> $new")         or die "can't open $new: $!";
	
	while (<OLD>) {
		s/# This line has been appended by the Apt\-cacher install script/ /;
		s/Include \/etc\/apt\-cacher\/apache.conf/ /;
		(print NEW $_)          or die "can't write to $new: $!";
	}
	
	close(OLD)                  or die "can't close $old: $!";
	close(NEW)                  or die "can't close $new: $!";
	
	rename($old, $bak)          or die "can't rename $old to $bak: $!";
	rename($new, $old)          or die "can't rename $new to $old: $!";
	
	## Restart Apache-SSL
	#if ( -f "/etc/init.d/apache-ssl" ) {
	#	print "Restarting Apache-SSL (if you have an SSL cert password, enter it now):";
	#	`/etc/init.d/apache-ssl restart`;
	#	print "... done.\n";
	#} else {
	#	print "Apache-SSL startup script was not found. Please restart Apache-SSL manually.\n";
	#}
}


## Delete the cache directory and everything in it
#system("rm -rf $config{cache_dir}");
#
## Delete the two log files (leaving the directory behind for now)
#unlink($config{logfile});
#unlink($config{errorfile});
#unlink($config{reportfile});

exit(0);