Last active
February 23, 2024 12:17
-
-
Save SimonXIX/192052681bc73473d433c4486cfee611 to your computer and use it in GitHub Desktop.
Copies the Copim Hugo site, finds the correct onion address, replaces the Onion-Location header in the original, and replaces the base_url with the onion service address in the onion mirror.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# @name: create_onion_service.sh | |
# @creation_date: 2022-09-02 | |
# @license: The MIT License <https://opensource.org/licenses/MIT> | |
# @author: Simon Bowie <ad7588@coventry.ac.uk> | |
# @purpose: Copies the Copim Hugo site, finds the correct onion address, replaces the Onion-Location header in the original, and replaces the base_url with the onion service address in the onion mirror. | |
# define variables | |
SOURCE_DIRECTORY='/home/[REDACTED]/website_inate/copim_website/public' | |
TARGET_DIRECTORY='/home/[REDACTED]/website_onion' | |
BASE_URL='https://www.copim.ac.uk' | |
ONION_ADDRESS=`docker exec tor cat /var/lib/tor/onion_services/onion-nginx/hostname` | |
# find the Onion-Location header and replace ONION_ADDRESS with the actual onion address | |
find ${SOURCE_DIRECTORY} \( -name "*.html" \) -exec sed -i "s/ONION_ADDRESS/${ONION_ADDRESS}/gI" {} \; | |
# copy the generated static site to a new directory | |
cp -rp $SOURCE_DIRECTORY/* $TARGET_DIRECTORY/ | |
# escape URL for sed | |
BASE_URL_ESCAPED=${BASE_URL//./\\.} | |
BASE_URL_ESCAPED=${BASE_URL_ESCAPED//\//\\/} | |
# find every instance of the base URL and replace with the onion address | |
# development version for macOS which implements 'sed' differently | |
#find ${TARGET_DIRECTORY} \( -name "*.html" -o -name "*.xml" -o -name "*.css" \) -exec gsed -i "s/${BASE_URL_ESCAPED}/${ONION_ADDRESS}/gI" {} \; | |
# production version for Linux | |
find ${TARGET_DIRECTORY} \( -name "*.html" -o -name "*.xml" -o -name "*.css" \) -exec sed -i "s/${BASE_URL_ESCAPED}/http:\/\/${ONION_ADDRESS}/gI" {} \; | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment