-
Notifications
You must be signed in to change notification settings - Fork 0
feat(keepalive): add Starbucks WiFi captive portal detection for macOS #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,3 +6,15 @@ set -euo pipefail | |||||||||
|
|
||||||||||
| # Silently ping neverssl.com - ignore failures (network may be unavailable) | ||||||||||
| curl -fsS --max-time 10 http://neverssl.com >/dev/null 2>&1 || true | ||||||||||
|
|
||||||||||
| # macOS-specific: Open captive portal for Starbucks WiFi if connectivity is lost | ||||||||||
| if [[ $OSTYPE == "darwin"* ]]; then | ||||||||||
| SSID=$(networksetup -getairportnetwork en0 2>/dev/null | awk -F": " '{print $2}' || echo "") | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcode the WiFi interface name or detect it dynamically. The hardcoded 🤖 Prompt for AI Agents
|
||||||||||
| SSID=$(networksetup -getairportnetwork en0 2>/dev/null | awk -F": " '{print $2}' || echo "") | |
| WIFI_DEVICE=$(networksetup -listallhardwareports 2>/dev/null | awk '/Wi-Fi/{getline; if ($1=="Device:") {print $2; exit}}') | |
| : "${WIFI_DEVICE:=en0}" | |
| SSID=$(networksetup -getairportnetwork "$WIFI_DEVICE" 2>/dev/null | awk -F": " '{print $2}' || echo "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern *"STARBUCKS"* includes literal double quotes, so it would only match an SSID that contains "STARBUCKS" including the quotes, which is unlikely. The quotes should be removed from the pattern.
Additionally, the comparison is case-sensitive. A case-insensitive match would be more robust and catch variations like Starbucks or starbucks.
The suggested change addresses both issues.
| if [[ $SSID == *"STARBUCKS"* ]]; then | |
| if [[ ${SSID,,} == *starbucks* ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ping command's -W flag behaves differently on macOS compared to Linux. On macOS, it specifies the timeout in milliseconds, not seconds. A timeout of 2 milliseconds is far too short and will likely cause the ping to fail even with a good connection, leading to the captive portal opening unnecessarily on every script execution.
You should use the -t flag for a timeout in seconds on macOS, or increase the value for -W to 2000 for a 2-second timeout.
| if ! ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then | |
| if ! ping -c 1 -t 2 1.1.1.1 >/dev/null 2>&1; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: On macOS, ping -W expects time in milliseconds, not seconds. -W 2 sets a 2ms timeout, which is too short for any realistic network response and will almost always fail, causing the captive portal to open unnecessarily even when connectivity is working.
Use -W 2000 for a 2-second timeout, or use -t 2 which specifies timeout in seconds.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/neverssl-keepalive/keepalive.sh, line 16:
<comment>On macOS, `ping -W` expects time in **milliseconds**, not seconds. `-W 2` sets a 2ms timeout, which is too short for any realistic network response and will almost always fail, causing the captive portal to open unnecessarily even when connectivity is working.
Use `-W 2000` for a 2-second timeout, or use `-t 2` which specifies timeout in seconds.</comment>
<file context>
@@ -6,3 +6,15 @@ set -euo pipefail
+
+ # Check for Starbucks networks (e.g., at_STARBUCKS_Wi2)
+ if [[ $SSID == *"STARBUCKS"* ]]; then
+ if ! ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then
+ open "http://captive.apple.com" 2>/dev/null || true
+ fi
</file context>
| if ! ping -c 1 -W 2 1.1.1.1 >/dev/null 2>&1; then | |
| if ! ping -c 1 -W 2000 1.1.1.1 >/dev/null 2>&1; then |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,4 +83,27 @@ The output should include 'captive portal' | |
| End | ||
| End | ||
|
|
||
| Describe 'Starbucks WiFi detection (macOS)' | ||
| It 'checks for macOS via OSTYPE' | ||
| When run bash -c "cat '$SCRIPT'" | ||
| The output should include 'OSTYPE' | ||
| The output should include 'darwin' | ||
| End | ||
|
|
||
| It 'uses networksetup to get SSID' | ||
| When run bash -c "cat '$SCRIPT'" | ||
| The output should include 'networksetup -getairportnetwork' | ||
| End | ||
|
|
||
| It 'checks for STARBUCKS SSID pattern' | ||
| When run bash -c "cat '$SCRIPT'" | ||
| The output should include '*"STARBUCKS"*' | ||
| End | ||
|
|
||
| It 'opens captive portal when connectivity fails' | ||
| When run bash -c "cat '$SCRIPT'" | ||
| The output should include 'captive.apple.com' | ||
| End | ||
|
Comment on lines
+87
to
+106
|
||
| End | ||
|
Comment on lines
+86
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new tests for Starbucks WiFi detection only check the script's source code for specific strings. This makes them brittle and tightly coupled to implementation details. For example, if the string matching for "STARBUCKS" is improved (e.g., to be case-insensitive as I suggested elsewhere), these tests would fail. The existing tests in this file for For example, you could:
And another test where |
||
|
|
||
| End | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Wi-Fi network interface is hardcoded as
en0. While this is common on many Macs, it's not guaranteed. Other interfaces likeen1could be used, especially on older hardware or systems with multiple network adapters. To make this script more robust, you should dynamically determine the Wi-Fi interface device name.The suggestion below also refactors the
awkcommand to use-v FS=...which is a bit cleaner and avoids potential shell quoting issues.