summaryrefslogtreecommitdiff
path: root/debian/echolot.postinst.in
blob: 1f68dc84c3cd7d0247be8e51ebcebc67bae2ebd5 (plain)
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
#!/bin/sh -e

# postinst for Echolot

. /usr/share/debconf/confmodule

# Make sure the echolot user exists
adduser --quiet \
	--quiet \
	--system \
	--disabled-password \
	--shell /bin/bash \
	--home /var/lib/echolot \
	--no-create-home \
	--group \
	--gecos "Echolot Pinger" \
	echolot

# Give the echolot user write permissions to /var/log/echolot/echolot.log
touch /var/log/echolot/echolot.log
chown echolot.adm /var/log/echolot/echolot.log
chmod 640 /var/log/echolot/echolot.log
# and /var/lib/echolot
if ( ! dpkg-statoverride --list /var/lib/echolot > /dev/null ); then
	dpkg-statoverride --update --add root echolot 02775 /var/lib/echolot
fi
# and /var/run/echolot
if ( ! dpkg-statoverride --list /var/run/echolot > /dev/null ); then
	dpkg-statoverride --update --add root echolot 02770 /var/run/echolot
fi


########################################################################
# User configuration
########################################################################
if [ "$1" = "configure" ]; then

	########################
	# Echolot configuration

	filename=`tempfile`;
cat > $filename << 'EOF'
#!/usr/bin/perl -w

		use strict;
		use Debconf::Client::ConfModule;
		use IO::File;

		my $postblock = "";
		my $preblock = "";

		if ( -e "/etc/echolot/pingd.conf" ) {
			my $fh = new IO::File;
			$fh->open("/etc/echolot/pingd.conf") or
				die ("Cannot open /etc/echolot/pingd.conf: $!");
			while (<$fh>) {
				last if (/^### BEGIN DEBCONF SECTION/);
				$preblock .= $_;
			};
			while (<$fh>) {
				last if (/^### END DEBCONF SECTION/);
			};
			while (<$fh>) {
				$postblock .= $_;
			};
			$fh->close() or
				die ("Cannot close /etc/echolot/pingd.conf: $!");
		};

		my $address = Debconf::Client::ConfModule::get("echolot/address");
		my $operator = Debconf::Client::ConfModule::get("echolot/operator");
		my $sitename = Debconf::Client::ConfModule::get("echolot/sitename");
		my $recipient_delimiter = Debconf::Client::ConfModule::get("echolot/recipient_delimiter");

		my ($local, $domain) = split (/@/, $address, 2);

		my $debconf  = sprintf("\$CONFIG->{q{my_localpart}        } = q{%s};\n", $local);
		   $debconf .= sprintf("\$CONFIG->{q{my_domain}           } = q{%s};\n", $domain);
		   $debconf .= sprintf("\$CONFIG->{q{operator_address}    } = q{%s};\n", $operator);
		   $debconf .= sprintf("\$CONFIG->{q{sitename}            } = q{%s};\n", $sitename);
		   $debconf .= sprintf("\$CONFIG->{q{recipient_delimiter} } = q{%s};\n", $recipient_delimiter);

		my $fh = new IO::File;
		$fh->open(">/etc/echolot/pingd.conf") or
			die ("Cannot open /etc/echolot/pingd.conf: $!");
		print $fh $preblock .
		          "### BEGIN DEBCONF SECTION\n" .
		          $debconf .
		          "1;\n" .
		          "### END DEBCONF SECTION\n" .
		          $postblock or
			die ("Cannot write to /etc/echolot/pingd.conf: $!");
		$fh->close or
			die ("Cannot close /etc/echolot/pingd.conf: $!");
EOF
	chmod +x $filename;
	$filename
	rm $filename
fi

#DEBHELPER#

########################################################################
# Configuration reprise
########################################################################
if [ "$1" = "configure" ]; then
	db_get echolot/addnow || true
	if [ "$RET" = "true" ]; then
		/etc/init.d/echolot add REMAILER_LIST
		# But don't do it again unless the user asks for it
		db_set echolot/addnow false
	fi
fi


db_stop

# vim:set ts=4:
# vim:set shiftwidth=4: