Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
IP gathering and Password Secrecy
Browse files Browse the repository at this point in the history
Added more optionality to handle various Operating systems as well as hide passwords while being typed.
  • Loading branch information
Chris B committed Oct 15, 2018
1 parent b1cd5d1 commit 04c5f2a
Showing 1 changed file with 76 additions and 5 deletions.
81 changes: 76 additions & 5 deletions examples/single-host/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,69 @@

set -e

gather_ip() {

echo "[I] Determining OS Type and Attempting to Gather External IP Address"
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
*) machine="UNKNOWN:${unameOut}"
esac
echo "Host is detected as ${machine}"

if [[ $machine == Linux ]]; then
HOST_IP=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')
elif [[ $machine == Mac ]]; then
HOST_IP=$(route get default | grep gateway | awk '{print $2}')
else
echo "Cannot determine IP address."
read -p "Please input the hosts external IP Address: " HOST_IP
fi
}

valid_ip() {
local ip=$1
local stat=1

if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}

confirm_ip() {

read -p "Is this the correct external IP Address: ${HOST_IP} [Y/n]? " cont
case "$cont" in
y|Y)
return 0
;;
n|N)
read -p "Please input the hosts external IP Address: " HOST_IP
if valid_ip $HOST_IP; then
return 0
else
echo "Please enter a valid IP Address."
gather_ip
return 1
fi
return 0
;;
*)
return 0
;;
esac
}

CONFIG_DIR=$PWD/volumes/config-init/db
HOST_IP=$(ip route get 1 | awk '{print $NF;exit}')

GLUU_VERSION=3.1.4_dev
INIT_CONFIG_CMD=""

Expand All @@ -20,7 +81,7 @@ mkdir -p $CONFIG_DIR
# deploy service defined in docker-compose.yml
load_services() {
echo "[I] Deploying containers"
DOMAIN=$DOMAIN HOST_IP=$HOST_IP docker-compose up -d > /dev/null 2>&1
DOMAIN=$DOMAIN HOST_IP=$HOST_IP docker-compose up -d
}

prepare_config() {
Expand All @@ -37,8 +98,9 @@ prepare_config() {
echo "[W] Configuration not found in Consul"

if [[ -f $CONFIG_DIR/config.json ]]; then
read -p "[I] Load previously saved configuration in local disk? [y/n]" load_choice
if [[ $load_choice = "y" ]]; then
read -p "[I] Load previously saved configuration in local disk? [Y/n]" load_choice

if [[ $load_choice != "n" && $load_choice != "N" ]]; then
DOMAIN=$(cat $CONFIG_DIR/config.json | awk ' /'hostname'/ {print $2} ' | sed 's/[",]//g')
INIT_CONFIG_CMD="load"
fi
Expand All @@ -54,7 +116,13 @@ prepare_config() {
read -p "Enter City: " CITY
read -p "Enter Email: " EMAIL
read -p "Enter Organization: " ORG_NAME
read -p "Enter Admin/LDAP Password: " ADMIN_PW
while true; do
read -s -p "Enter Admin/LDAP Password: " ADMIN_PW
echo
read -s -p "Confirm Admin/LDAP Password: " password2
echo
[ "$ADMIN_PW" = "$password2" ] && break || echo "Please try again"
done

case "$ADMIN_PW" in
* ) ;;
Expand Down Expand Up @@ -105,6 +173,9 @@ generate_config() {
--ldap-type opendj
}

gather_ip
until confirm_ip; do : ; done

# ==========
# entrypoint
# ==========
Expand Down

0 comments on commit 04c5f2a

Please sign in to comment.