~ekez/negativefour

ref: a3ba218efef2773e5826b94d9ca3c096795b3ddc negativefour/serve/undeploy.sh -rwxr-xr-x 1.8 KiB
a3ba218eZeke Medley Fix race condition between apache restart and status check 3 months ago
                                                                                
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
#!/bin/bash

# Removes a webpage deployed with the `deploy.sh` file given then name
# of the webpage.

# Copyright (C) 2021  Zeke Medley
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see
# <https://www.gnu.org/licenses/>.

set -e
set -u
set -o pipefail

NAME=$1
URL="$NAME.negativefour.app"
PORT=$(head -1 /etc/apache2/sites-available/${URL}.conf | awk 'NF>1{print $NF}')

rm -rf "/home/admin/www/html/$URL"

# This dance is needed as for whatever reason piping the output of
# grep into a variable replaces the newlines with spaces so we need to
# pipe into a file and move it around.
grep -v "HiddenServiceDir /var/lib/tor/${URL}" /etc/tor/torrc > tmpfile
grep -v "HiddenServicePort 80 127.0.0.1:${PORT}" tmpfile > tmpfile2
rm tmpfile

mv tmpfile2 /etc/tor/torrc

rm -rf "/var/lib/tor/${URL}"

systemctl restart tor

# If we don't have this sleep an interesting race condition occurs
# where apache will be restarting as the user tries to check the
# status of the build causing the first check to fail. This quick
# check happens because after a delete operation the user is instantly
# redirected to the status page.
sleep 3

rm "/etc/apache2/sites-available/${URL}.conf"

a2dissite "${URL}"

systemctl restart apache2