-
Notifications
You must be signed in to change notification settings - Fork 36
/
reset.sh
executable file
·69 lines (60 loc) · 1.57 KB
/
reset.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
source env.sh
shopt -s extglob
confirm() {
local msg
msg="$1"
echo "$msg"
read -rn 3 answer
case $answer in
Yes|yes|Y|y|YES)
echo
return 0
;;
*)
echo "Cancelling"
return 1
esac
}
reset_device() {
local serial
serial="$1"
for i in $(seq 1 2); do
if ! $YKMAN --device "${serial}" otp delete "$i" -f >/dev/null 2>&1; then
echo "Warning the slot $i didn't contain OTP configuration or an error happened"
fi
done
$YKMAN --device "${serial}" oath reset -f
$YKMAN --device "${serial}" openpgp reset -f
$YKMAN --device "${serial}" piv reset -f
$YKMAN --device "${serial}" fido reset
}
yubikeys=$($YKMAN list --serials)
select serial in all $yubikeys cancel; do
echo "You chose $serial"
case $serial in
all)
confirm "Are you sure you want to reset $yubikeys ? yes/no" || exit 0
for yubikey in $yubikeys; do
echo "Reset $yubikey"
reset_device "$yubikey"
done
break
;;
cancel)
echo "Cancelled"
break
;;
# https://www.linuxjournal.com/content/bash-extended-globbing
+([0-9]))
confirm "Are you sure you want to reset $serial ? yes/no" || exit 0
echo "Reset $serial"
reset_device "$serial"
break
;;
*)
echo "Unexpected error, exiting"
exit 1
;;
esac
done