This month I found myself spinning up Digital Ocean Droplets (VPS), running through the installation and configuration of SQUID, finding that it doesn’t work like I thought it did, and then destroying the Droplet when finished…only to do it all over again. I ended up spending a lot of time trying to understand what others before me had written only to be uncertain of where I went wrong. I even watched a video on Linux Academy to get “introduced” to Squid. At the end of the day, it was a lot of wasted time for something I would have understood better if someone had just dropped me this bash file and said, “run it, follow the directions to test it, then modify the conf file as needed”. Configuring Squid isn’t actually all that bad, my biggest problems were being sure that the service was actually running, configured in a way that I could at least test that it was doing something and lastly, making sure that I was configuring my machine to use the proxy properly.

I can’t access ThePirateBay here in the USA without paying for a VPN, which is often more expensive than setting up a VPS in a country that can access TPB. So I went about to make a TPB access service which also allows me to run other services on the machine for my convenience. With Digital Ocean, it costs me $5 / month and I have full control of what I want to do and how I want to do it. For me, that is worth far more than a VPN even could be, and at a fraction of the price.

So what’s next? I’ll probably seek out ways of securing the connection to the server, off the top of my head, setting up OpenVPN isn’t a bad idea – supports encryption, uses certificates, friends can join in on the fun!

#!/bin/bash
# For Debian systems. Install and configure Squid Web Proxy to access ThePirateBay.Org

# Update and install everything you're gonna need
apt-get update && apt-get upgrade -y && apt-get install squid sharutils -y

# Enable and Start Squid for the first time, then stop the service
systemctl enable squid
systemctl start squid
systemctl stop squid

# Configure /etc/squid/squid.conf
# Write this base64 encoded text to ./sqd-tmp
cat > ./sqd-tmp <<'_EOF'
begin-base64 644 /etc/squid/squid.conf
IyBTcXVpZCBXZWIgUHJveHkgQ29uZiBGaWxlCiMgSSd2ZSByZW1vdmVkIGFs
bCB0aGUgY29tbWVudHMgb3V0IG9mIHRoaXMgZmlsZSBiZWNhdXNlIHlvdSBj
YW4ndCBmaW5kIHNoaXQgaW4gaGVyZSBvdGhlcndpc2UgOykgfkpvaG4KCmFj
bCBTU0xfcG9ydHMgcG9ydCA0NDMKCmFjbCBTYWZlX3BvcnRzIHBvcnQgODAJ
CSMgaHR0cAphY2wgU2FmZV9wb3J0cyBwb3J0IDIxCQkjIGZ0cAphY2wgU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YXNlfFBhY2th
Z2VzKC5neikqKSQgICAgICAwICAgICAgIDIwJSAgICAgMjg4MApyZWZyZXNo
X3BhdHRlcm4gLgkJMAkyMCUJNDMyMAo=
====
_EOF
# Now decode that base64 encoded file and write it to /etc/squid/squid.conf
uudecode -o /etc/squid/squid.conf < ./sqd-tmp 
# Remove the tmp file
rm ./sqd-tmp

# Start the service
systemctl start squid

# Print out some instructions for using / testing the configuration.
cat <<'_EOF'
# Run the following to test the Proxy:
    export http_proxy="http://galaxysloth.com:3128/" # enable http_proxy on linux system
    curl -I thepiratebay.org # curl for headers from blocked url
    curl https://thepiratebay.org/ # curl headers from whitelisted url
    curl http://google.com # curl headers from google
_EOF