-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.sh
46 lines (39 loc) · 1.28 KB
/
functions.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
#!/bin/bash
# Function to enter 2FA code
enter_2fa() {
echo "Attempting to generate and enter 2FA code..."
# Ensure the 1Password window is active
WINDOW_ID=$(xdotool search --name "1Password")
if [ -n "$WINDOW_ID" ]; then
echo "Focusing 1Password window ID: $WINDOW_ID"
xdotool windowactivate "$WINDOW_ID"
sleep 0.5 # Allow time for focus
else
echo "Error: 1Password window not found."
echo "Listing all active window names:" # Added error debug output
xdotool search --onlyvisible --name ".*" getwindowname
return 1
fi
# Generate a 2FA code using the secret key (if TOTP is used)
TWOFA_CODE=$(oathtool --totp -b "$ONEPASSWORD_TOTP_SECRET")
if [ -n "$TWOFA_CODE" ]; then
echo "2FA code generated: $TWOFA_CODE"
else
echo "Error: Failed to generate 2FA code."
return 1
fi
# Enter the 2FA code
echo "Entering the 2FA code..."
xdotool type "$TWOFA_CODE"
sleep 0.5
# Submit the 2FA code
echo "Submitting the 2FA code..."
xdotool key Tab
sleep 0.5
xdotool key Return
# Wait briefly to ensure the code is processed
echo "Waiting for confirmation of 2FA submission..."
sleep 2
xdotool key Return
echo "2FA process completed."
}