File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /bin/bash
22
3+ # Ensure running under Bash (required for mapfile, process substitution, arrays)
4+ if [ -z " ${BASH_VERSION:- } " ]; then
5+ echo " This script requires Bash. Run with: bash $0 " >&2
6+ exit 2
7+ fi
8+
39set -euo pipefail
410
511# Import Wi-Fi profiles from a KeePassXC database (kdbx) using keepassxc-cli.
Original file line number Diff line number Diff line change @@ -97,16 +97,28 @@ add_entry_to_kp() {
9797 fi
9898
9999 # Construct the command array
100- local cmd=(keepassxc-cli add " ${DB_FILE} " " ${GROUP} " " ${ssid} " --username " " --password " ${pw} " --comment " imported from macOS keychain " )
100+ local cmd=(keepassxc-cli add " ${DB_FILE} " " ${GROUP} / ${ssid} " --username " " --password-prompt )
101101 if [ -n " ${KEY_FILE} " ]; then
102- cmd=(keepassxc-cli add --key-file " ${KEY_FILE} " " ${DB_FILE} " " ${GROUP} " " ${ssid} " --username " " --password " ${pw} " --comment " imported from macOS keychain " )
102+ cmd=(keepassxc-cli add --key-file " ${KEY_FILE} " " ${DB_FILE} " " ${GROUP} / ${ssid} " --username " " --password-prompt )
103103 fi
104104
105105 # Execute with password pipe if KEEPASS_DB_PASS is set, otherwise interactive
106+ local output
106107 if [ -n " ${KEEPASS_DB_PASS:- } " ]; then
107- echo " ${KEEPASS_DB_PASS} " | " ${cmd[@]} "
108+ if output=$( printf " %s\n%s\n" " ${KEEPASS_DB_PASS} " " ${pw} " 2>&1 | " ${cmd[@]} " 2>&1 ) ; then
109+ return 0
110+ else
111+ log_err " keepassxc-cli error: ${output} "
112+ return 1
113+ fi
108114 else
109- " ${cmd[@]} "
115+ log " Enter KeePassXC database password, then Wi-Fi password for ${ssid} :"
116+ if output=$( printf " %s\n" " ${pw} " 2>&1 | " ${cmd[@]} " 2>&1 ) ; then
117+ return 0
118+ else
119+ log_err " keepassxc-cli error: ${output} "
120+ return 1
121+ fi
110122 fi
111123}
112124
You can’t perform that action at this time.
0 commit comments