Skip to content

Commit f7e6d42

Browse files
committed
drop entry_name
1 parent 1df80b7 commit f7e6d42

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

pritunl_login/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ A shell script for connecting to Pritunl VPN using credentials stored in 1Passwo
55
## Usage
66

77
```bash
8-
./pritunl_login.sh <account> <entry_name> <password_ref>
8+
./pritunl_login.sh <account> <password_ref>
99
```
1010

1111
### Arguments
1212

1313
- `account`: 1Password account name/ID (e.g., 'stark-industries')
14-
- `entry_name`: Name of the 1Password entry (e.g., 'Pritunl (VPN)')
1514
- `password_ref`: 1Password password reference (e.g., 'op://Employee/x9zm2kddpq4nvbwrfhgtsjloey/password')
1615

1716
### Example
1817

1918
```bash
20-
./pritunl_login.sh stark-industries 'Pritunl (VPN)' 'op://Employee/x9zm2kddpq4nvbwrfhgtsjloey/password'
19+
./pritunl_login.sh stark-industries 'op://Employee/x9zm2kddpq4nvbwrfhgtsjloey/password'
2120
```
2221

2322
## Prerequisites
@@ -36,7 +35,8 @@ A shell script for connecting to Pritunl VPN using credentials stored in 1Passwo
3635
## How It Works
3736

3837
1. Retrieves the first available Pritunl profile ID
39-
2. Fetches the password and OTP from the specified 1Password entry
40-
3. Concatenates the password and OTP for authentication
41-
4. Starts the VPN connection using the Pritunl client
42-
5. Displays the current VPN status upon success
38+
2. Extracts the item ID from the password reference
39+
3. Fetches the password and OTP from 1Password using the extracted item ID
40+
4. Concatenates the password and OTP for authentication
41+
5. Starts the VPN connection using the Pritunl client
42+
6. Displays the current VPN status upon success

pritunl_login/pritunl_login.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ readonly PRITUNL_CLIENT_PATH="/Applications/Pritunl.app/Contents/Resources/pritu
55

66
usage() {
77
cat << EOF
8-
Usage: $0 [OPTIONS] <account> <entry_name> <password_ref>
8+
Usage: $0 [OPTIONS] <account> <password_ref>
99
1010
Connect to Pritunl VPN using credentials from 1Password.
1111
1212
POSITIONAL ARGUMENTS:
1313
account 1Password account name/ID (e.g., 'stark-industries')
14-
entry_name Name of the 1Password entry (e.g., 'Pritunl (VPN)')
1514
password_ref 1Password password reference (e.g., 'op://Employee/x9zm2kddpq4nvbwrfhgtsjloey/password')
1615
1716
OPTIONS:
@@ -28,7 +27,7 @@ PREREQUISITES:
2827
- User must be logged into the specified 1Password account
2928
3029
EXAMPLES:
31-
$0 stark-industries 'Pritunl (VPN)' 'op://Employee/x9zm2kddpq4nvbwrfhgtsjloey/password'
30+
$0 stark-industries 'op://Employee/x9zm2kddpq4nvbwrfhgtsjloey/password'
3231
$0 --help
3332
3433
EXIT CODES:
@@ -42,8 +41,8 @@ if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]]; then
4241
exit 0
4342
fi
4443

45-
if [[ $# -ne 3 ]]; then
46-
echo "Error: Expected 3 arguments, got $#"
44+
if [[ $# -ne 2 ]]; then
45+
echo "Error: Expected 2 arguments, got $#"
4746
echo ""
4847
usage
4948
exit 1
@@ -77,14 +76,13 @@ check_dependencies() {
7776

7877
main() {
7978
local account_name="$1"
80-
local entry_name="$2"
81-
local password_ref="$3"
79+
local password_ref="$2"
8280

8381
check_dependencies
8482

8583
echo "Connecting to Pritunl VPN..."
86-
echo "Entry: $entry_name"
8784
echo "Account: $account_name"
85+
echo "Password reference: $password_ref"
8886
echo ""
8987

9088
echo "Getting Pritunl profile ID..."
@@ -99,11 +97,13 @@ main() {
9997
echo "Using profile ID: $profile_id"
10098

10199
echo "Retrieving credentials from 1Password..."
100+
101+
# Extract item ID from password reference (op://vault/item_id/field)
102102
local op_id
103-
op_id=$(op --account "$account_name" item get "$entry_name" --format json 2>/dev/null | jq -r '.id' 2>/dev/null)
103+
op_id=$(echo "$password_ref" | sed -n 's|op://[^/]*/\([^/]*\)/.*|\1|p')
104104

105-
if [[ -z "$op_id" || "$op_id" == "null" ]]; then
106-
echo "Error: Could not find 1Password entry '$entry_name' in account '$account_name'"
105+
if [[ -z "$op_id" ]]; then
106+
echo "Error: Could not extract item ID from password reference '$password_ref'"
107107
exit 1
108108
fi
109109

@@ -119,7 +119,7 @@ main() {
119119
otp=$(op --account "$account_name" item get "$op_id" --totp 2>/dev/null)
120120

121121
if [[ -z "$otp" ]]; then
122-
echo "Error: Could not retrieve OTP for entry '$entry_name'"
122+
echo "Error: Could not retrieve OTP for item '$op_id'"
123123
exit 1
124124
fi
125125

0 commit comments

Comments
 (0)