#!/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 # . 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