]> pere.pagekite.me Git - exim4-smtorp.git/blobdiff - setup-exim-hidden-service
Change deb section from python to mail.
[exim4-smtorp.git] / setup-exim-hidden-service
index e0ab869af6f181cee4e15299586045604d44257f..d14a3ae5ddb0d00586d7a5de9b8e5183ee38a790 100644 (file)
@@ -3,30 +3,50 @@
 # Configure a machine without exim installed as a mail server receiving
 # email using SMTP via Tor.
 
-if dpkg -l exim4-config > /dev/null ; then
-    echo "******************************************************************"
-    echo "* Unable to set up SMTP over Tor, exim4-config already installed *"
-    echo "* Purge the package and try again, or                            *"
-    echo "* run "dpkg-reconfigure exim4-config" to configure manually.     *"
-    echo "******************************************************************"
-    exit 1
-fi
+append_if_missing() {
+    file="$1"
+    string="$2"
+    if [ -f "$file" ] && grep -xq "$string" "$file" ; then
+        :
+    else
+        (
+            if [ -f "$file" ] ; then cat "$file" ; fi
+            echo "$string"
+        ) > "$file.new" && mv "$file.new" "$file"
+    fi
+}
 
-DEBIAN_FRONTEND=noninteractive apt-get install -y tor
+DEBIAN_FRONTEND=noninteractive apt-get install -y tor xinetd
 torhsdir=$(awk '/^HiddenServiceDir (.*) *$/ { print $2 }' /etc/tor/torrc)
 if [ -e "$torhsdir/hostname" ] ; then
    torhsname=$(cat "$torhsdir/hostname")
 else
     echo "*******************************************************************"
-    echo "* Unable to set up SMTP over TOR.  There is no Tor hidden service *"
-    echo "* name in $torhsdir           *"
+    echo "* Added Tor hidden service for SMTP (port 25)                     *"
     echo "*******************************************************************"
-    echo "Please add lines like this to /etc/tor/torrc:"
-    echo
-    echo "HiddenServiceDir /var/lib/tor/hidden_service/"
-    echo "HiddenServicePort 25 127.0.0.1:25"
-    mkdir /var/lib/tor/hidden_service
+    append_if_missing /etc/tor/torrc \
+       "HiddenServiceDir /var/lib/tor/hidden_service/"
+    append_if_missing /etc/tor/torrc \
+       "HiddenServicePort 25 127.0.0.1:25"
+    mkdir -p /var/lib/tor/hidden_service
     chown debian-tor:debian-tor /var/lib/tor/hidden_service
+    chmod og-rwx /var/lib/tor/hidden_service
+    service tor restart
+    if [ -e "$torhsdir/hostname" ] ; then
+       torhsname=$(cat "$torhsdir/hostname")
+    else
+       echo "error: unable to set up Tor hidden service"
+       exit 1
+    fi
+fi
+
+if dpkg -l exim4-config > /dev/null ; then
+    echo "******************************************************************"
+    echo "* Unable to set up SMTP over Tor, exim4-config already installed *"
+    echo "* Purge the package and try again, or                            *"
+    echo "* run "dpkg-reconfigure exim4-config" to configure manually.     *"
+    echo "******************************************************************"
+    echo "* Enable '$torhsname' as mail domain.
     exit 1
 fi