Accept printable Wi-Fi hotspot passwords

This commit is contained in:
2026-07-31 20:32:47 +02:00
parent c6c76b78cb
commit e52d2690ee
2 changed files with 12 additions and 5 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ fi
echo "[1/7] Installing operating-system packages"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y ca-certificates curl gnupg git rsync sudo util-linux avahi-daemon sqlite3 android-tools-adb build-essential network-manager
apt-get install -y ca-certificates curl gnupg git rsync sudo util-linux avahi-daemon sqlite3 android-tools-adb build-essential network-manager wpasupplicant
node_major=""
if command -v node >/dev/null 2>&1; then
+11 -4
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
set -Eeuo pipefail
export LC_ALL=C
CONFIG_FILE="/etc/pi-car-companion/companion.env"
HOTSPOT_CONNECTION="pi-car-hotspot"
@@ -25,10 +26,15 @@ if [[ "$(nmcli --get-values GENERAL.STATE device show "${UPSTREAM_INTERFACE}" 2>
exit 1
fi
read -r -s -p "Password for ${HOTSPOT_SSID} (8-63 characters): " hotspot_password
IFS= read -r -s -p "Password for ${HOTSPOT_SSID} (8-63 characters): " hotspot_password
echo
if (( ${#hotspot_password} < 8 || ${#hotspot_password} > 63 )) || [[ ! "${hotspot_password}" =~ ^[[:alnum:]_.-]+$ ]]; then
echo "The hotspot password must contain 8-63 letters, numbers, dots, hyphens, or underscores." >&2
if (( ${#hotspot_password} < 8 || ${#hotspot_password} > 63 )) || [[ ! "${hotspot_password}" =~ ^[[:print:]]+$ ]]; then
echo "The hotspot password must contain 8-63 printable ASCII characters." >&2
exit 1
fi
psk_hex="$(printf '%s\n' "${hotspot_password}" | wpa_passphrase "${HOTSPOT_SSID}" | sed -n 's/^[[:space:]]*psk=//p')"
if [[ ! "${psk_hex}" =~ ^[[:xdigit:]]{64}$ ]]; then
echo "The hotspot password could not be converted into a WPA key." >&2
exit 1
fi
@@ -51,7 +57,7 @@ ssid=${HOTSPOT_SSID}
[wifi-security]
key-mgmt=wpa-psk
psk=${hotspot_password}
psk=${psk_hex}
[ipv4]
address1=${HOTSPOT_ADDRESS}
@@ -66,6 +72,7 @@ fi
install -m 0600 -o root -g root "${temporary_file}" "${hotspot_file}"
nmcli connection load "${hotspot_file}"
hotspot_password=""
psk_hex=""
set_env() {
local key="$1"