#!/bin/bash

loc_check=$(dig smart01.blipsandchitz.local +short)
filename=/Users/tylebean/.ssh/config
hostlist=/Users/tylebean/.ssh/hostlist
vpchostlist=/Users/tylebean/.ssh/vpchostlist

cat /dev/null > $filename
cat /Users/tylebean/.ssh/security-bastion >> $filename
printf "\n\n# Personal Hosts Configuration\n\n" >> $filename
echo "host jump" >> $filename
echo "  HostName jump.shortchangehero.com" >> $filename
echo "  User root" >> $filename
echo "" >> $filename
echo "host vpc" >> $filename
echo "  HostName vpn.shortchangehero.com" >> $filename
echo "  User ec2-user" >> $filename
echo ""

while read i;
do
  hostname=$(echo $i | awk '{print $1}')
  ip=$(echo $i | awk '{print $2}')
  user=$(echo $i | awk '{print $3}')
  echo "host $hostname" >> $filename
  echo "  StrictHostKeyChecking no" >> $filename
  echo "  ServerAliveInterval 60" >> $filename
  echo "  HostName $ip" >> $filename
  echo "  User $user" >> $filename
  if [ "$loc_check" != 1 ]
  then
    echo "  ProxyCommand ssh -q jump nc %h %p" >> $filename
  fi
  echo "" >> $filename
done <$hostlist

echo "" >> $filename
echo "host git-push" >> $filename
echo "  StrictHostKeyChecking no" >> $filename
echo "  ServerAliveInterval 60" >> $filename
echo "  HostName frijole-git.blipsandchitz.local" >> $filename
echo "  IdentityFile /Users/tylebean/CloudStation/work/keys/tylebean.pem" >> $filename
echo "  User git" >> $filename
if [ "$loc_check" != 1 ]
then
  echo "  ProxyCommand ssh -q jump nc %h %p" >> $filename
fi

echo "" >> $filename
while read i;
do
  hostname=$(echo $i | awk '{print $1}')
  ip=$(echo $i | awk '{print $2}')
  user=$(echo $i | awk '{print $3}')
  echo "host $hostname" >> $filename
  echo "  StrictHostKeyChecking no" >> $filename
  echo "  ServerAliveInterval 60" >> $filename
  echo "  HostName $ip" >> $filename
  echo "  User $user" >> $filename
  echo "  ProxyCommand ssh -q vpc nc %h %p" >> $filename
done <$vpchostlist
