mirror of
https://github.com/GRFreire/scripts.git
synced 2026-01-10 04:59:38 +00:00
add get-otp script
This commit is contained in:
parent
e5d50eb7e5
commit
a9a5ae6d0c
1
bin/get-otp
Symbolic link
1
bin/get-otp
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../get-otp/get-otp.sh
|
||||||
8
get-otp/README.md
Normal file
8
get-otp/README.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# get-otp
|
||||||
|
|
||||||
|
## About
|
||||||
|
A simple shell wrapper for go-andotp and oathtool for generating TOTP with andotp backups files.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- [go-andotp](https://github.com/RijulGulati/go-andotp)
|
||||||
|
- [oathtool](https://www.nongnu.org/oath-toolkit/)
|
||||||
53
get-otp/get-otp.sh
Executable file
53
get-otp/get-otp.sh
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
accounts_file=$1
|
||||||
|
|
||||||
|
# Check if file path was provided
|
||||||
|
if [ -z "$accounts_file" ]; then
|
||||||
|
echo "File not provided."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "Password: "
|
||||||
|
stty -echo
|
||||||
|
read -r password
|
||||||
|
stty echo
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
|
# Decrypt the andotp generated file
|
||||||
|
accounts_json=$(go-andotp -d -i "$accounts_file" -p "$password")
|
||||||
|
if [ "$(echo $accounts_json | awk '{print $1;}')" = "error:" ]; then
|
||||||
|
echo "Could not decrypt the file"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get Issuers
|
||||||
|
issuers=$(echo "$accounts_json" | jq -r '.[] | .issuer')
|
||||||
|
issuers_count=$(echo "$accounts_json" | jq -r '. | length')
|
||||||
|
|
||||||
|
# Get issuer
|
||||||
|
printf "\nWhat issuer do you want?\n" "$issuers"
|
||||||
|
|
||||||
|
# Print issuers with index as prefix
|
||||||
|
for i in $(seq 1 "$issuers_count"); do
|
||||||
|
issuer=$(echo "$issuers" | awk "NR==$i")
|
||||||
|
echo "$i: $issuer"
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "\nIssuer index: "
|
||||||
|
read -r issuer_i
|
||||||
|
|
||||||
|
# Check valid input (needs to be a number and less or equal to issuers_count)
|
||||||
|
if ! ([ "$issuer_i" -eq "$issuer_i" ] && [ "$issuer_i" -le "$issuers_count" ] && [ "$issuer_i" -ge "1" ]); then
|
||||||
|
echo "Invalid index!"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
issuer_selected=$(echo "$issuers" | awk "NR==$issuer_i")
|
||||||
|
|
||||||
|
# Get secret
|
||||||
|
secret=$(echo "$accounts_json" | jq -r ".[] | select(.issuer == \"$issuer_selected\") | .secret")
|
||||||
|
|
||||||
|
# Get otp-code
|
||||||
|
code=$(echo "$secret" | xargs oathtool --totp -b)
|
||||||
|
echo "\nOTP CODE: $code"
|
||||||
Loading…
Reference in New Issue
Block a user