Added rudimentary route discovery

This commit is contained in:
Ivan Ilves 2017-02-07 19:50:22 +01:00
parent 897905f092
commit e1b4c0e8cd
3 changed files with 32 additions and 12 deletions

3
.gitignore vendored
View File

@ -87,3 +87,6 @@ ENV/
# Rope project settings # Rope project settings
.ropeproject .ropeproject
# local routes generator
/discover-routes

12
discover-routes.aws.example Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
#
# Route discovery primer for AWS
#
if [[ ${#} != 1 ]]; then
echo "Usage: ${0} SSH_SERVER"
exit 1
fi
export AWS_PROFILE=$(echo ${1} | awk -F"." '{print $2}')
aws ec2 describe-subnets | grep CidrBlock\":\ \"10 | awk -F"\"" '{print $4}'

View File

@ -10,7 +10,12 @@ if [[ ${#} -lt 1 ]]; then
fi fi
declare -r SSH_SERVER=${1}; shift declare -r SSH_SERVER=${1}; shift
declare -r NETWORKS=${@}
if [[ ${#} -gt 0 ]]; then
declare -r NETWORKS=${@}
elif [[ -x ./discover-routes ]]; then
declare -r NETWORKS=$(./discover-routes ${SSH_SERVER})
fi
declare -r IP_BASE=192.168.245 declare -r IP_BASE=192.168.245
declare -r TUNNEL_ID_PATH=~/.xiringuito/tunnel_id declare -r TUNNEL_ID_PATH=~/.xiringuito/tunnel_id
@ -42,6 +47,7 @@ function teardown() {
fi fi
./scripts/client-teardown.sh ${TUNNEL_ID} ./scripts/client-teardown.sh ${TUNNEL_ID}
ssh ${SSH_OPTS} ${SSH_SERVER} pkill -f ${REMOTE_PATH}/server-execute.sh ssh ${SSH_OPTS} ${SSH_SERVER} pkill -f ${REMOTE_PATH}/server-execute.sh
echo "DONE"
} }
echo "TUNNEL ID: ${TUNNEL_ID}" echo "TUNNEL ID: ${TUNNEL_ID}"
@ -60,23 +66,22 @@ ssh ${SSH_OPTS} ${SSH_SERVER} ${REMOTE_PATH}/server-setup.sh ${TUNNEL_ID} ${IP_B
sleep 1; echo -n "SERVER: ${SSH_SERVER} ... " sleep 1; echo -n "SERVER: ${SSH_SERVER} ... "
ssh ${SSH_OPTS} -w ${TUNNEL_ID}:${TUNNEL_ID} ${SSH_SERVER} ${REMOTE_PATH}/server-execute.sh ${TUNNEL_ID} ${IP_BASE} & ssh ${SSH_OPTS} -w ${TUNNEL_ID}:${TUNNEL_ID} ${SSH_SERVER} ${REMOTE_PATH}/server-execute.sh ${TUNNEL_ID} ${IP_BASE} &
SSH_PID=${!} SSH_PID=${!}
sleep 2 sleep 3
if [[ ! ${NO_DNS} && ! -z "${NETWORKS}" ]]; then if [[ ! ${NO_DNS} && ! -z "${NETWORKS}" && ! "$(grep xiringuito /etc/resolv.conf)" ]]; then
echo echo
echo "* Will now replace your DNS config with one fetched from the SSH server." echo "* Will now replace your DNS config with one fetched from the SSH server."
echo "* Set enviromental variable 'NO_DNS', if you do not want this to happen." echo "* Set enviromental variable 'NO_DNS', if you do not want this to happen."
REMOTE_RESOLV_CONF=$(ssh ${SSH_OPTS} ${SSH_SERVER} cat /etc/resolv.conf | grep -v "[#;]" ) REMOTE_RESOLV_CONF=$(ssh ${SSH_OPTS} ${SSH_SERVER} cat /etc/resolv.conf | grep -v "[#;]" )
if [[ ! "$(grep xiringuito /etc/resolv.conf)" ]]; then
sudo cp /etc/resolv.conf /etc/resolv.conf.orig
if [[ "${REMOTE_RESOLV_CONF}" =~ nameserver ]]; then sudo cp /etc/resolv.conf /etc/resolv.conf.orig
echo "--- resolv.conf ---"
echo "# Added by xiringuito" | sudo tee /etc/resolv.conf if [[ "${REMOTE_RESOLV_CONF}" =~ nameserver ]]; then
echo "${REMOTE_RESOLV_CONF}" | sudo tee -a /etc/resolv.conf echo "--- resolv.conf ---"
echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf echo "# Added by xiringuito" | sudo tee /etc/resolv.conf
echo "--- resolv.conf ---" echo "${REMOTE_RESOLV_CONF}" | sudo tee -a /etc/resolv.conf
fi echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf
echo "--- resolv.conf ---"
fi fi
fi fi