2020-01-11 12:49:05 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
source "${HOME}/bin/script_framework.sh"
|
|
|
|
|
2020-01-11 13:31:31 +00:00
|
|
|
function usage() {
|
|
|
|
echo "Usage: $0 [-hv] [-p prefix] <port>" >&2
|
|
|
|
}
|
2020-01-11 12:49:05 +00:00
|
|
|
|
|
|
|
# Get real shareport command
|
|
|
|
shareport=$(which -a shareport | grep -v $0 | head -n1)
|
|
|
|
|
2020-01-11 13:31:31 +00:00
|
|
|
# Start argument array
|
|
|
|
args=($shareport)
|
2020-04-06 22:01:29 +00:00
|
|
|
host=localhost
|
2020-01-11 13:31:31 +00:00
|
|
|
|
|
|
|
# Parse options
|
2020-04-06 22:01:29 +00:00
|
|
|
while getopts ":hi:p:v" o; do
|
2020-01-11 13:31:31 +00:00
|
|
|
case "${o}" in
|
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2020-04-06 22:01:29 +00:00
|
|
|
i)
|
|
|
|
host="${OPTARG}"
|
|
|
|
;;
|
2020-01-11 13:31:31 +00:00
|
|
|
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"
|
2020-04-06 22:01:29 +00:00
|
|
|
args+=(--local-addr "${host}:${port}")
|
2020-01-11 13:31:31 +00:00
|
|
|
|
2020-01-11 12:49:05 +00:00
|
|
|
step "Fetching secrets..."
|
|
|
|
export IDENTITY_FILE=$(mktemp)
|
|
|
|
export IDENTITY_FILE_PASSWORD=$(vault read -field=passphrase secret/ssh-key/shareport)
|
|
|
|
|
|
|
|
vault read -field=private secret/ssh-key/shareport >${IDENTITY_FILE}
|
|
|
|
|
|
|
|
# Configure remote
|
|
|
|
export REMOTE_HOST=knut.dev:22
|
|
|
|
export REMOTE_SCRIPT="${HOME}/.config/shareport.remote.sh"
|
|
|
|
export REMOTE_USER=shareport
|
|
|
|
|
|
|
|
# Setup removal of SSH key after exit
|
|
|
|
function cleanup() {
|
|
|
|
step "Cleaning up..."
|
|
|
|
rm -f ${IDENTITY_FILE}
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
step "Starting shareport..."
|
2020-01-11 13:31:31 +00:00
|
|
|
"${args[@]}"
|