2 Commits

Author SHA1 Message Date
8fed63792b Ask permission for starting vagrant SSH tunnels 2023-09-16 00:04:58 -04:00
2c4fcbacc3 Introduce forward-ssh.sh method & reorganize
- Abandoned update-hosts.sh in favor of loopback SSH forwarding
- Adopted *.local.krislamo.org as a wildcard loopback domain
- Bound Traefik to ports 443/80 on Dockerbox dev
- Removed outdated Gitea config from Dockerbox
- Relocated production playbooks to a new directory
2023-09-15 23:46:45 -04:00

View File

@@ -3,6 +3,12 @@
# Finds the SSH private key under ./.vagrant and connects to # Finds the SSH private key under ./.vagrant and connects to
# the Vagrant box, port forwarding localhost ports: 8443, 80, 443 # the Vagrant box, port forwarding localhost ports: 8443, 80, 443
# Root check
if [ "$EUID" -ne 0 ]; then
echo "[ERROR]: Please run script as root"
exit 1
fi
# Clean environment # Clean environment
unset PRIVATE_KEY unset PRIVATE_KEY
unset HOST_IP unset HOST_IP
@@ -11,8 +17,12 @@ unset PKILL_ANSWER
# Function to create the SSH tunnel # Function to create the SSH tunnel
function ssh_connect { function ssh_connect {
read -rp "Start a new vagrant SSH tunnel? [y/N]"
echo
case "$PSTART_ANSWER" in
[yY])
printf "[INFO]: Starting new vagrant SSH tunnel on PID " printf "[INFO]: Starting new vagrant SSH tunnel on PID "
sudo ssh -fNT -i "$PRIVATE_KEY" \ sudo -u "$USER" ssh -fNT -i "$PRIVATE_KEY" \
-L 8443:localhost:8443 \ -L 8443:localhost:8443 \
-L 80:localhost:80 \ -L 80:localhost:80 \
-L 443:localhost:443 \ -L 443:localhost:443 \
@@ -21,6 +31,12 @@ function ssh_connect {
vagrant@"$HOST_IP" 2>/dev/null vagrant@"$HOST_IP" 2>/dev/null
sleep 2 sleep 2
pgrep -f "$MATCH_PATTERN" pgrep -f "$MATCH_PATTERN"
;;
*)
echo "[INFO]: Delined to start a new vagrant SSH tunnel"
exit 0
;;
esac
} }
# Check for valid PRIVATE_KEY location # Check for valid PRIVATE_KEY location
@@ -56,7 +72,7 @@ else
case "$PKILL_ANSWER" in case "$PKILL_ANSWER" in
[yY]) [yY])
echo "[WARNING]: Killing old vagrant SSH tunnel(s): " echo "[WARNING]: Killing old vagrant SSH tunnel(s): "
pgrep -f "$MATCH_PATTERN" | tee >(xargs sudo kill -15) pgrep -f "$MATCH_PATTERN" | tee >(xargs kill -15)
echo echo
if [ "$(pgrep -afc "$MATCH_PATTERN")" -eq 0 ]; then if [ "$(pgrep -afc "$MATCH_PATTERN")" -eq 0 ]; then
ssh_connect ssh_connect