Last active
December 15, 2020 00:38
-
-
Save louneskmt/11bf57c187b0e9c7b0048fb83a26d1f9 to your computer and use it in GitHub Desktop.
Script to install a launchd service for a socat socks proxy
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 -e | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
-h|--help) | |
echo "Usage: ./install-socat-service.sh -n <SERVICE_NAME> -p <PORT_TO_BIND> <ONION_URL:PORT>" | |
echo "Example: ./install-socat-service.sh -n umbrel-bitcoin-rpc -p 1000 blablabla.onion:8332" | |
exit 0 | |
;; | |
-p|--port) port="$2"; shift ;; | |
-n|--name) name="$2"; shift ;; | |
${@: -1}) url="$1" ;; | |
*) echo "Unknown parameter passed: $1"; exit 1 ;; | |
esac | |
shift | |
done | |
if [ -z ${port+x} ] || [ -z ${name+x} ] || [ -z ${url+x} ]; | |
then | |
echo "Please specify an URL: ./install-socat-service.sh -n <SERVICE_NAME> -p <PORT_TO_BIND> <ONION_URL:PORT>" | |
echo "Example: ./install-socat-service.sh -n umbrel-bitcoin-rpc -p 1000 blablabla.onion:8332" | |
exit 1 | |
fi; | |
echo " | |
<?xml version=\"1.0\" encoding=\UTF-8\"?> | |
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> | |
<plist version=\"1.0\"> | |
<dict> | |
<key>Label</key> | |
<string>socat.$name</string> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>KeepAlive</key> | |
<true/> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/socat</string> | |
<string>TCP4-LISTEN:$port,reuseaddr,fork</string> | |
<string>SOCKS4A:127.0.0.1:$url,socksport=9050</string> | |
</array> | |
<key>StandardOutPath</key> | |
<string>/var/log/$name.log</string> | |
</dict> | |
</plist> | |
" > ~/Library/LaunchAgents/socat.$name.plist | |
launchctl load ~/Library/LaunchAgents/socat.$name.plist | |
launchctl start socat.$name | |
echo "Service ready:" | |
echo $(sudo launchctl list | grep $name) | |
echo "-------------------------------------" | |
echo "You can now start and stop this service with:" | |
echo " sudo launchctl start socat.$name" | |
echo " sudo launchctl stop socat.$name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment