Skip to content

Commit

Permalink
move init
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroTochigi committed Dec 7, 2023
1 parent 4087c49 commit 2755d4c
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions init.sh → src/aws/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,73 +134,73 @@ function usage {
exit 1
}

while getopts 'n:pN:a:' OPTION; do
case "$OPTION" in
n)
keyname=$OPTARG
;;
p)
portConfigArray=$(getArrayValueAsStringByKey $instanceName tcpPortArray)
udpPortConfigArray=$(getArrayValueAsStringByKey $instanceName udpPortArray)
if [ -z "$portConfigArray" ]
then
echo "There is no stored port numbers. The default port numbers are used"
fi
if [ -z "$udpPortConfigArray" ]
then
echo "There is no stored udp port numbers. The default port numbers are used"
fi
;;
a)
groupName=$OPTARG-sg
instanceName=$OPTARG
keyname=$OPTARG
;;
?)
usage
;;
esac
done
shift "$(($OPTIND -1))"


if [ -z $keyname ]
then
keyname=luftballon
fi
function init {
while getopts 'n:pN:a:' OPTION; do
case "$OPTION" in
n)
keyname=$OPTARG
;;
p)
portConfigArray=$(getArrayValueAsStringByKey $instanceName tcpPortArray)
udpPortConfigArray=$(getArrayValueAsStringByKey $instanceName udpPortArray)
if [ -z "$portConfigArray" ]
then
echo "There is no stored port numbers. The default port numbers are used"
fi
if [ -z "$udpPortConfigArray" ]
then
echo "There is no stored udp port numbers. The default port numbers are used"
fi
;;
a)
groupName=$OPTARG-sg
instanceName=$OPTARG
keyname=$OPTARG
;;
?)
usage
;;
esac
done
shift "$(($OPTIND -1))"


keyName=$(importSshKey | getValueByKeyword KeyName )
if [ -z $keyname ]
then
keyname=luftballon
fi

if [ -z $keyName ]
then
exit 1
fi

echo "Success to add ssh key: $keyName"
keyName=$(importSshKey | getValueByKeyword KeyName )

createSecurityGroups
echo "Add security group"
if [ -z $keyName ]
then
exit 1
fi

instanceId=$(createEc2 | getValueByKeyword InstanceId )
echo "Create EC2 Instance"
echo "Instance id is $instanceId"
echo "Success to add ssh key: $keyName"

createSecurityGroups
echo "Add security group"

aws ec2 create-tags --resources $instanceId --tags Key=Name,Value=$instanceName
aws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses
instanceId=$(createEc2 | getValueByKeyword InstanceId )
echo "Create EC2 Instance"
echo "Instance id is $instanceId"


publicIp=$(waitForOutput "getLatestIpAddress $instanceId")
echo "Public IP Address is $publicIp"
aws ec2 create-tags --resources $instanceId --tags Key=Name,Value=$instanceName
aws ec2 create-tags --resources $instanceId --tags Key=Class,Value=treehouses

echo "Will open ssh tunnel soon"
isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256")
echo "Opened ssh tunnel"

openSSHTunnel $publicIp $portConfigArray
storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName
publicIp=$(waitForOutput "getLatestIpAddress $instanceId")
echo "Public IP Address is $publicIp"

echo "Will open ssh tunnel soon"
isOpen=$(waitForOutput "ssh-keyscan -H $publicIp | grep ecdsa-sha2-nistp256")
echo "Opened ssh tunnel"

openSSHTunnel $publicIp $portConfigArray
storeConfigIntoTreehousesConfigAsStringfiedJson $instanceName $keyName $instanceId $publicIp $groupName
}


0 comments on commit 2755d4c

Please sign in to comment.