#!/bin/bash

# send-bankid-token
#
# Takes a bankid URI as input, extracts the token and writes the token to disk
# on a target Windows SSH host. The target host is expected to watch for this
# file, just like the following PowerShell script does:
# https://gitlab.com/dabruh/weird-corner/-/blob/main/powershell/BankIDTokenFileWatcher.ps1

TOKEN=${1:?} || exit 1
TOKEN="${TOKEN#*=}"
TOKEN="${TOKEN%&*}"

xclip -selection clipboard <<<"$1"
ssh bankid -- powershell.exe -NoLogo -ExecutionPolicy Bypass -Command "Set-Content -Path C:\.bidtoken -Value '$TOKEN'" &
notify-send BankID "Token has been sent." &
