#!/bin/bash

# 2019-08-14T21:58:08Z; baltakatei>

# The purpose of this script is to open a session of firefox dedicated
# to editing wikipedia from a remote machine with a public IP address
# not on Wikipedia's blocklist.

# This script:
#   1. Creates ssh proxy to remote server
#   2. Starts Firefox by calling a local installation of firefox via
#     its own startup script.

# Note: This script does not automatically initialize the default
# Firefox profile with the correct SOCKS5 settings as can be seen in
# "Connection Settings" ("Manual proxy configuration", SOCKS
# Host="127.0.0.1", Port="8080"). These changes must be made manually
# until an automated method for applying SOCKS settings via edits to
# `prefs.js` in the default Firefox profile.

# Reference:

# SSH CONNECTION SETTINGS
REMOTE_USER=baltakatei
REMOTE_IP=76.102.50.36
REMOTE_PORT=63865
LOCAL_PROXY_PORT=8080

# STEP 1: Start an SSH master connection (-M)
#         in the background (-f)
#         without running a remote command (-N)
ssh -p $REMOTE_PORT -M -o ControlPath=/tmp/socks.%r@%h:%p -f -N -D $LOCAL_PROXY_PORT -C $REMOTE_USER@$REMOTE_IP

# STEP 2: Launch Firefox in the foreground
#/home/baltakatei/Desktop/firefox/firefox -P -no-remote
/home/baltakatei/Desktop/firefox/firefox -no-remote

# STEP 3: When user is done with Firefox, send an "exit" command to the master connection
ssh -p $REMOTE_PORT -o ControlPath=/tmp/socks.%r@%h:%p -O exit $REMOTE_USER@$REMOTE_IP