From b3926751ad43fee62afaa469ab269c555ef270fa Mon Sep 17 00:00:00 2001 From: geek Date: Fri, 23 Jun 2017 17:37:02 -0500 Subject: [PATCH] chore: explicitly ask for key path --- docker/api/package.json | 2 +- setup.sh | 79 +++++++++++++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/docker/api/package.json b/docker/api/package.json index 5bfac7f3..fd46194d 100644 --- a/docker/api/package.json +++ b/docker/api/package.json @@ -15,7 +15,7 @@ "good": "^7.2.0", "good-console": "^6.4.0", "good-squeeze": "^5.0.2", - "graphi": "^2.2.1", + "graphi": "^2.3.0", "hapi": "^16.1.0", "hoek": "^4.1.1", "joi": "^10.6.0", diff --git a/setup.sh b/setup.sh index b7ab92aa..b1792134 100755 --- a/setup.sh +++ b/setup.sh @@ -1,9 +1,44 @@ #!/bin/bash set -e -o pipefail +help() { + echo + echo 'Usage ./setup.sh ~/path/to/TRITON_PRIVATE_KEY' + echo + echo 'Checks that your Triton and Docker environment is sane and configures' + echo 'an environment file to use.' + echo + echo 'TRITON_PRIVATE_KEY is the filesystem path to an SSH private key' + echo 'used to connect to Triton.' + echo +} + # Check for correct configuration check() { + if [ -z "$1" ]; then + tput rev # reverse + tput bold # bold + echo 'Please provide a path to a SSH private key to access Triton.' + tput sgr0 # clear + + help + exit 1 + fi + + if [ ! -f "$1" ]; then + tput rev # reverse + tput bold # bold + echo 'SSH private key for Triton is unreadable.' + tput sgr0 # clear + + help + exit 1 + fi + + # Assign args to named vars + TRITON_PRIVATE_KEY_PATH=$1 + command -v docker >/dev/null 2>&1 || { echo tput rev # reverse @@ -46,20 +81,36 @@ check() { echo TRITON_KEY_PATH=${TRITON_CREDS_PATH}/key.pem >> _env echo TRITON_CERT=$(cat "${DOCKER_CERT_PATH}"/cert.pem | tr '\n' '#') >> _env echo TRITON_CERT_PATH=${TRITON_CREDS_PATH}/cert.pem >> _env + echo SDC_KEY=$(cat "${TRITON_PRIVATE_KEY_PATH}" | tr '\n' '#') >> _env + echo SDC_KEY_PUB=$(cat "${TRITON_PRIVATE_KEY_PATH}.pub" | tr '\n' '#') >> _env echo >> _env - - for file in ~/.ssh/*.pub - do - SDC_KEY=$(ssh-keygen -E md5 -lf ${file} | awk '{print $2}' | awk -F"MD5:" '{print $2}') - if [ "$SDC_KEY" == "$SDC_KEY_ID" ] - then - echo SDC_KEY_PUB=$(cat "${file}" | tr '\n' '#') >> _env - priv_file=$(echo "${file}" | awk -F".pub" '{print $1}') - echo SDC_KEY=$(cat "${priv_file}" | tr '\n' '#') >> _env - break - fi - done } -# default behavior -check +# --------------------------------------------------- +# parse arguments + +# Get function list +funcs=($(declare -F -p | cut -d " " -f 3)) + +until + if [ ! -z "$1" ]; then + # check if the first arg is a function in this file, or use a default + if [[ " ${funcs[@]} " =~ " $1 " ]]; then + cmd=$1 + shift 1 + else + cmd="check" + fi + + $cmd "$@" + if [ $? == 127 ]; then + help + fi + + exit + else + help + fi +do + echo +done