aboutsummaryrefslogtreecommitdiff
path: root/bin/provision-host
blob: 13b8a78d108d1f9cf40019dd88c11077abe18454 (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
#!/bin/bash
#
# Provisioner for a simple hosting environment
#

# Parameters
PROJECT="${PROJECT:-bookup}"

# Check for sudo
if [ "`whoami`" != "root" ]; then
  SUDO="sudo"
fi

# Apache
$SUDO apt install -y apache2

# Configure an Onion Service
if which trashman &> /dev/null; then
  trashman install tor-onion-service
else
  HIDDEN="/var/lib/tor/hidden/${PROJECT}"

  # Install Tor
  $SUDO apt install -y tor

  # Tor config
  cat <<-EOF | $SUDO tee -a /etc/tor/torrc > /dev/null
RunAsDaemon 1
HiddenServiceDir $HIDDEN
HiddenServicePort 80 127.0.0.1:80
EOF

  # Create folder structure
  $SUDO mkdir -p $HIDDEN
  $SUDO chmod -R 700 $HIDDEN
  $SUDO chown -R debian-tor: $HIDDEN

  # Start Tor
  $SUDO service tor restart
fi

# Configure Onion Service virtual host
cat <<-EOF | $SUDO tee /etc/apache2/sites-available/onion.conf > /dev/null
<VirtualHost 127.0.0.1:80>
    ServerName localhost
    ServerAlias *.onion
    DocumentRoot "/srv/shared/public"

    <Directory /srv/shared/public>
      #AuthType Basic
      #AuthName "Protected"
      #AuthUserFile /srv/shared/.htpasswd
      #Require valid-user
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
    </Directory>
</VirtualHost>
EOF

# Configure local virtual host
cat <<-EOF | $SUDO tee /etc/apache2/sites-available/local.conf > /dev/null
<VirtualHost *:80>
    ServerName ${PROJECT}.local
    DocumentRoot "/srv/shared/public"

    <Directory /srv/shared/public>
      #AuthType Basic
      #AuthName "Protected"
      #AuthUserFile /srv/shared/.htpasswd
      #Require valid-user
      Options Indexes FollowSymLinks
      AllowOverride All
      Require all granted
    </Directory>
</VirtualHost>
EOF

# Ensure that the DocumentRoot exists
$SUDO mkdir -p /srv/shared

# Enable virtual host
$SUDO a2ensite onion local
$SUDO service apache2 restart