Switch to SISH service for shareport

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-09-27 14:47:39 +02:00
parent bfeb8b689f
commit 6715bdf685
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E

View file

@ -4,15 +4,13 @@ set -euo pipefail
source "${HOME}/bin/script_framework.sh" source "${HOME}/bin/script_framework.sh"
function usage() { function usage() {
echo "Usage: $0 [-hv] [-p prefix] <port>" >&2 echo "Usage: $0 [-h] [-k key] [-p prefix] <port>" >&2
} }
# Get real shareport command args=(-p 31088 master.k8s.kserver.biz)
shareport=$(which -a shareport | grep -v $0 | head -n1)
# Start argument array
args=($shareport)
host=localhost host=localhost
key=loki
remote="80"
# Parse options # Parse options
while getopts ":hi:p:v" o; do while getopts ":hi:p:v" o; do
@ -21,14 +19,11 @@ while getopts ":hi:p:v" o; do
usage usage
exit 0 exit 0
;; ;;
i) k)
host="${OPTARG}" key="${OPTARG}"
;; ;;
p) p)
args+=(--var "FQDN_PREFIX=${OPTARG}") remote="${OPTARG}:80"
;;
v)
args+=(--log-level debug)
;; ;;
*) *)
usage usage
@ -41,25 +36,7 @@ shift $((OPTIND - 1))
# Add port # Add port
port="${1:-}" port="${1:-}"
[[ -n $port ]] || fatal "Missing local port as first argument" [[ -n $port ]] || fatal "Missing local port as first argument"
args+=(--local-addr "${host}:${port}")
step "Fetching secrets..." step "Starting port-forward..."
export IDENTITY_FILE=$(mktemp) vault-sshadd ${key}
export IDENTITY_FILE_PASSWORD=$(vault read -field=passphrase secret/ssh-key/shareport) exec /usr/bin/ssh -R "${remote}:${host}:${port}" "${args[@]}"
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..."
"${args[@]}"