Skip to content

Commit fa299c3

Browse files
committed
wifi_from_kdbx: add bash version check to prevent mapfile errors
1 parent d6f5738 commit fa299c3

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/wifi_from_kdbx.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
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+
39
set -euo pipefail
410

511
# Import Wi-Fi profiles from a KeePassXC database (kdbx) using keepassxc-cli.

src/wifi_from_keychain.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)