Add usage, opts, fix port usage
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
4ae3ec5ec4
commit
b5a94e2ad5
1 changed files with 33 additions and 3 deletions
|
@ -3,12 +3,42 @@ set -euo pipefail
|
||||||
|
|
||||||
source "${HOME}/bin/script_framework.sh"
|
source "${HOME}/bin/script_framework.sh"
|
||||||
|
|
||||||
port="${1:-}"
|
function usage() {
|
||||||
[[ -n $port ]] || fatal "Missing local port as first argument"
|
echo "Usage: $0 [-hv] [-p prefix] <port>" >&2
|
||||||
|
}
|
||||||
|
|
||||||
# Get real shareport command
|
# Get real shareport command
|
||||||
shareport=$(which -a shareport | grep -v $0 | head -n1)
|
shareport=$(which -a shareport | grep -v $0 | head -n1)
|
||||||
|
|
||||||
|
# Start argument array
|
||||||
|
args=($shareport)
|
||||||
|
|
||||||
|
# Parse options
|
||||||
|
while getopts ":hp:v" o; do
|
||||||
|
case "${o}" in
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
p)
|
||||||
|
args+=(--var "FQDN_PREFIX=${OPTARG}")
|
||||||
|
;;
|
||||||
|
v)
|
||||||
|
args+=(--log-level debug)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
fatal "Invalid option -- ${OPTARG}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
# Add port
|
||||||
|
port="${1:-}"
|
||||||
|
[[ -n $port ]] || fatal "Missing local port as first argument"
|
||||||
|
args+=(--local-addr "localhost:${port}")
|
||||||
|
|
||||||
step "Fetching secrets..."
|
step "Fetching secrets..."
|
||||||
export IDENTITY_FILE=$(mktemp)
|
export IDENTITY_FILE=$(mktemp)
|
||||||
export IDENTITY_FILE_PASSWORD=$(vault read -field=passphrase secret/ssh-key/shareport)
|
export IDENTITY_FILE_PASSWORD=$(vault read -field=passphrase secret/ssh-key/shareport)
|
||||||
|
@ -28,4 +58,4 @@ function cleanup() {
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
step "Starting shareport..."
|
step "Starting shareport..."
|
||||||
$shareport --local-addr "localhost:$1"
|
"${args[@]}"
|
||||||
|
|
Loading…
Reference in a new issue