mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
75 lines
2.5 KiB
Bash
75 lines
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
# Generated A/B identity used only by WiFiManager's portal OTA test harness.
|
|
#
|
|
# Keeping the identity in a tiny header lets PlatformIO reuse the one platform
|
|
# environment's library objects. The header is ignored and removed on every
|
|
# normal test-harness exit; it is never part of a user sketch or release.
|
|
|
|
declare -A WM_OTA_FIXTURE_LOCK_FDS=()
|
|
|
|
wm_lock_ota_fixture_environment() {
|
|
local environment="$1" lock_root lock_file lock_fd
|
|
[[ "$environment" =~ ^[A-Za-z0-9_-]+$ ]] || {
|
|
echo "Unsafe OTA fixture environment name: $environment" >&2
|
|
return 2
|
|
}
|
|
[[ -n "${WM_OTA_FIXTURE_LOCK_FDS[$environment]:-}" ]] && return 0
|
|
command -v flock >/dev/null 2>&1 || {
|
|
echo "flock is required to protect PlatformIO OTA fixture inputs." >&2
|
|
return 1
|
|
}
|
|
lock_root="$root/test/portal-harness/.pio/harness-locks"
|
|
install -d -m 700 "$lock_root"
|
|
lock_file="$lock_root/${environment}.lock"
|
|
exec {lock_fd}>"$lock_file"
|
|
if ! flock -n "$lock_fd"; then
|
|
echo "OTA fixture environment '$environment' is already in use by another local test-harness run." >&2
|
|
return 1
|
|
fi
|
|
WM_OTA_FIXTURE_LOCK_FDS["$environment"]="$lock_fd"
|
|
}
|
|
|
|
wm_ota_fixture_identity_dir() {
|
|
[[ -n "${WIFIMANAGER_OTA_IDENTITY_DIR:-}" ]] || {
|
|
echo "WIFIMANAGER_OTA_IDENTITY_DIR must be set before writing an OTA fixture identity." >&2
|
|
return 2
|
|
}
|
|
printf '%s\n' "$WIFIMANAGER_OTA_IDENTITY_DIR"
|
|
}
|
|
|
|
wm_ota_fixture_identity_header() {
|
|
printf '%s/ota_fixture_identity.h\n' "$(wm_ota_fixture_identity_dir)"
|
|
}
|
|
|
|
wm_write_ota_fixture_identity() {
|
|
local image="$1" directory header temporary
|
|
case "$image" in
|
|
A|B) ;;
|
|
*)
|
|
echo "WiFiManager OTA fixture identity must be A or B." >&2
|
|
return 2
|
|
;;
|
|
esac
|
|
|
|
directory="$(wm_ota_fixture_identity_dir)" || return
|
|
header="$(wm_ota_fixture_identity_header)"
|
|
install -d -m 700 "$directory"
|
|
temporary="$(mktemp "$directory/ota_fixture_identity.XXXXXX")"
|
|
chmod 600 "$temporary"
|
|
printf '%s\n' \
|
|
'#pragma once' \
|
|
'// Generated by the WiFiManager OTA test harness. Do not commit.' \
|
|
"#define WM_OTA_FIXTURE_IMAGE \"$image\"" \
|
|
> "$temporary"
|
|
mv -f -- "$temporary" "$header"
|
|
}
|
|
|
|
wm_remove_ota_fixture_identity() {
|
|
local directory header
|
|
[[ -n "${WIFIMANAGER_OTA_IDENTITY_DIR:-}" ]] || return 0
|
|
directory="$(wm_ota_fixture_identity_dir)" || return
|
|
header="$(wm_ota_fixture_identity_header)"
|
|
rm -f -- "$header"
|
|
rmdir -- "$directory" 2>/dev/null || true
|
|
}
|