@@ -5,13 +5,12 @@ readonly PRITUNL_CLIENT_PATH="/Applications/Pritunl.app/Contents/Resources/pritu
55
66usage () {
77 cat << EOF
8- Usage: $0 [OPTIONS] <account> <entry_name> < password_ref>
8+ Usage: $0 [OPTIONS] <account> <password_ref>
99
1010Connect to Pritunl VPN using credentials from 1Password.
1111
1212POSITIONAL 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
1716OPTIONS:
@@ -28,7 +27,7 @@ PREREQUISITES:
2827 - User must be logged into the specified 1Password account
2928
3029EXAMPLES:
31- $0 stark-industries 'Pritunl (VPN)' ' op://Employee/x9zm2kddpq4nvbwrfhgtsjloey/password'
30+ $0 stark-industries 'op://Employee/x9zm2kddpq4nvbwrfhgtsjloey/password'
3231 $0 --help
3332
3433EXIT CODES:
@@ -42,8 +41,8 @@ if [[ "${1:-}" == "-h" ]] || [[ "${1:-}" == "--help" ]]; then
4241 exit 0
4342fi
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
7877main () {
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