]> pere.pagekite.me Git - exim4-smtorp.git/blob - setup-exim-hidden-service
Make sure to install xinetd, used by tor to connect to smtp.
[exim4-smtorp.git] / setup-exim-hidden-service
1 #!/bin/sh
2 #
3 # Configure a machine without exim installed as a mail server receiving
4 # email using SMTP via Tor.
5
6 if dpkg -l exim4-config > /dev/null ; then
7 echo "******************************************************************"
8 echo "* Unable to set up SMTP over Tor, exim4-config already installed *"
9 echo "* Purge the package and try again, or *"
10 echo "* run "dpkg-reconfigure exim4-config" to configure manually. *"
11 echo "******************************************************************"
12 exit 1
13 fi
14
15 append_if_missing() {
16 file="$1"
17 string="$2"
18 if [ -f "$file" ] && grep -xq "$string" "$file" ; then
19 :
20 else
21 (
22 if [ -f "$file" ] ; then cat "$file" ; fi
23 echo "$string"
24 ) > "$file.new" && mv "$file.new" "$file"
25 fi
26 }
27
28 DEBIAN_FRONTEND=noninteractive apt-get install -y tor xinetd
29 torhsdir=$(awk '/^HiddenServiceDir (.*) *$/ { print $2 }' /etc/tor/torrc)
30 if [ -e "$torhsdir/hostname" ] ; then
31 torhsname=$(cat "$torhsdir/hostname")
32 else
33 echo "*******************************************************************"
34 echo "* Added Tor hidden service for SMTP (port 25) *"
35 echo "*******************************************************************"
36 append_if_missing /etc/tor/torrc \
37 "HiddenServiceDir /var/lib/tor/hidden_service/"
38 append_if_missing /etc/tor/torrc \
39 "HiddenServicePort 25 127.0.0.1:25"
40 mkdir -p /var/lib/tor/hidden_service
41 chown debian-tor:debian-tor /var/lib/tor/hidden_service
42 chmod og-rwx /var/lib/tor/hidden_service
43 service tor restart
44 if [ -e "$torhsdir/hostname" ] ; then
45 torhsname=$(cat "$torhsdir/hostname")
46 else
47 echo "error: unable to set up Tor hidden service"
48 exit 1
49 fi
50 fi
51
52 cat <<EOF | debconf-set-selections
53 exim4-config exim4/dc_eximconfig_configtype select internet site; mail is sent and received directly using SMTP
54 exim4-config exim4/dc_local_interfaces string 127.0.0.1 ; ::1
55 exim4-config exim4/dc_other_hostnames string $torhsname
56 exim4-config exim4/use_split_config boolean true
57 EOF
58
59 DEBIAN_FRONTEND=noninteractive apt-get install -y exim4