Skip to content

Instantly share code, notes, and snippets.

@alukach
Created September 15, 2013 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alukach/6573103 to your computer and use it in GitHub Desktop.
Save alukach/6573103 to your computer and use it in GitHub Desktop.
#!/bin/sh
rm /tmp/hma.sh
cat <<INSTALL > /tmp/hma.sh
#!/bin/sh
cd /tmp
mkdir hma
cd hma
cat <<EOF > hma.conf
remote 173.208.32.98 53
client
dev tun
proto udp
script-security 2
resolv-retry infinite
nobind
persist-key
persist-tun
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
ca /tmp/hma/ca.crt
cert /tmp/hma/cl.crt
ns-cert-type server
key /tmp/hma/cl.key
auth-user-pass /tmp/hma/user.txt
log /tmp/hma/hma.log
verb 2
management 127.0.0.1 5001
EOF
cat <<"EOF" > user.txt
INSTALL
if [ -f /tmp/hma.txt ]; then
b64=`cat /tmp/hma.txt`
echo "begin-base64 644 -" > /tmp/hma.txt
echo "$b64" >> /tmp/hma.txt
uudecode < /tmp/hma.txt >> /tmp/hma.sh
echo "" >> /tmp/hma.sh
rm /tmp/hma.txt
else
echo "/tmp/hma.txt: Not found: HMA-WRT Installation Failed"
fi
cat <<INSTALL >> /tmp/hma.sh
EOF
chmod 600 user.txt
cat <<EOF > ca.crt
-----BEGIN CERTIFICATE-----
CERT HERE
-----END CERTIFICATE-----
EOF
cat <<EOF >cl.crt
-----BEGIN CERTIFICATE-----
CERT HERE
-----END CERTIFICATE-----
EOF
cat <<EOF >cl.key
-----BEGIN RSA PRIVATE KEY-----
KEY HERE
-----END RSA PRIVATE KEY-----
EOF
chmod 600 cl.key
cat <<EOF > up.sh
#!/bin/sh
iptables -A POSTROUTING -t nat -o tun0 -j MASQUERADE
EOF
chmod 755 up.sh
cat <<EOF > dn.sh
#!/bin/sh
iptables -D POSTROUTING -t nat -o tun0 -j MASQUERADE
/tmp/hma/vpn.sh &
EOF
chmod 755 dn.sh
cat <<EOF > vpn.sh
#!/bin/sh
openvpn --config /tmp/hma/hma.conf --route-up /tmp/hma/up.sh --down /tmp/hma/dn.sh --daemon 2>&1 >> /tmp/hma/hma.log
EOF
chmod 755 vpn.sh
while [ \`date +%Y\` -lt 2013 ]; do
sleep 5
done
sleep 2
while ! ps|grep openvpn >/dev/null ; do
/tmp/hma/vpn.sh &
sleep 30
done
INSTALL
nvram set hma="`cat /tmp/hma.sh`"
nvram set rc_startup="nvram get hma > /tmp/hma.sh; chmod 755 /tmp/hma.sh; /tmp/hma.sh; # Installed on 2013-09-15 10:58:25 #"
echo "Saving startup sequence"
nvram commit
echo "NVRAM saved"
cat <<BANNER
------------------------------------------
| Congratulations! |
| HMA WRT Installed |
| |
| Please now reboot your router. |
| |
------------------------------------------
BANNER
@alukach
Copy link
Author

alukach commented Sep 15, 2013

Backup of HMA's WRT OpenVPN setup script. Executed with:

wget -O /tmp/inst.sh 'http://vpn.hidemyass.com/vpnconfig/wrt.php?loc=USA%2C+Washington%2C+Seattle+%28LOC1+S1%29&proto=tcp' ; echo "YWx1a2FjaApoaWRlbXlhc3NDYXJyb3QwNyE=" > /tmp/hma.txt; chmod 755 /tmp/inst.sh ; /tmp/inst.sh; 

More info:
http://wiki.hidemyass.com/DD-WRT_OpenVPN_Setup
https://vpn.hidemyass.com/vpncontrol/myaccounts/wrt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment