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