aboutsummaryrefslogtreecommitdiffstats
path: root/hsrvpn
blob: 82220e0c1d47cfb31a5acdea65e60f08fc00540a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

set -e

if (($# < 1)); then
    echo "Usage: $0 <username>" >&2
    exit 1
fi

username=$1
host=vpn.hsr.ch

password=$(keyring get openhsr-connect $username)
if [[ -z "$password" ]]; then
  echo "No openhsr-connect (HSR) password found!" >&2
  exit 1
fi

tokens=( $(keyring get hsrvpn-secrets $username) )
if [[ -z "$tokens" ]]; then
  echo "No tokens found!" >&2
  exit 1
fi

token=${tokens[0]}
unset -v 'tokens[0]'

echo "${tokens[@]}" | keyring set hsrvpn-secrets $username

echo "$token"

printf '%s\n' "$password" "$token" | sudo openconnect "$host" -u "$username"