Skip to content

Commit 61511d3

Browse files
authored
Add comments to wireless access point scripts (#1784)
Related #1711 This is a follow-up PR to a [review comment](https://codeapprove.com/pr/tiny-pilot/tinypilot/1778#thread-4d8c230a-afdd-4361-8e21-0a7be15efb06) asking for more code comments in our `enable-wifi-ap` and `disable-wifi-ap` scripts. <a data-ca-tag href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1784"><img src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review on CodeApprove" /></a>
1 parent 3d33c4d commit 61511d3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

debian-pkg/opt/tinypilot-privileged/scripts/disable-wifi-ap

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,24 @@ readonly SCRIPT_DIR
5151
# shellcheck source=lib/markers.sh
5252
. "${SCRIPT_DIR}/lib/markers.sh"
5353

54+
# Clear existing TinyPilot network configurations.
5455
"${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf
5556

56-
mv \
57-
/etc/wpa_supplicant/wpa_supplicant.conf.bak \
58-
/etc/wpa_supplicant/wpa_supplicant.conf
57+
# Restore previously backed up WPA configurations.
58+
if [[ -e /etc/wpa_supplicant/wpa_supplicant.conf.bak ]]; then
59+
mv \
60+
/etc/wpa_supplicant/wpa_supplicant.conf.bak \
61+
/etc/wpa_supplicant/wpa_supplicant.conf
62+
fi
5963

64+
# Disable WPA.
6065
if [[ -e /etc/wpa_supplicant/wlan_enabled ]]; then
6166
rm --force /etc/wpa_supplicant/wlan_enabled
6267
else
6368
rfkill block wlan
6469
fi
6570

71+
# Stop wireless access point.
6672
systemctl stop hostapd dnsmasq
6773
rm --force \
6874
/etc/hostapd/hostapd.conf \

debian-pkg/opt/tinypilot-privileged/scripts/enable-wifi-ap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ readonly SCRIPT_DIR
124124
# shellcheck source=lib/markers.sh
125125
. "${SCRIPT_DIR}/lib/markers.sh"
126126

127+
# Clear existing TinyPilot network configurations.
127128
"${SCRIPT_DIR}/strip-marker-sections" /etc/dhcpcd.conf
128129

130+
# Enable wireless network interface.
129131
cat <<EOF | tee --append /etc/dhcpcd.conf
130132
${MARKER_START}
131133
interface wlan0
@@ -134,6 +136,7 @@ nohook wpa_supplicant
134136
${MARKER_END}
135137
EOF
136138

139+
# Configure wireless access point.
137140
cat <<EOF | tee /etc/hostapd/hostapd.conf
138141
country_code=${NETWORK_COUNTRY}
139142
interface=wlan0
@@ -150,13 +153,15 @@ wpa_pairwise=TKIP
150153
rsn_pairwise=CCMP
151154
EOF
152155

156+
# Configure DHCP server for wireless access point.
153157
cat <<EOF | tee /etc/dnsmasq.conf
154158
interface=wlan0
155159
dhcp-range=${NETWORK_AP_CLIENT_IP_RANGE_START},${NETWORK_AP_CLIENT_IP_RANGE_END},255.255.255.0,24h
156160
domain=wlan
157161
address=/gw.wlan/${NETWORK_AP_IP_ADDRESS}
158162
EOF
159163

164+
# Backup WPA configurations.
160165
cp \
161166
--no-clobber \
162167
/etc/wpa_supplicant/wpa_supplicant.conf \
@@ -166,11 +171,13 @@ if ! rfkill list wlan | grep -q 'yes'; then
166171
touch /etc/wpa_supplicant/wlan_enabled
167172
fi
168173

174+
# Clear WPA configurations.
169175
cat <<'EOF' | tee /etc/wpa_supplicant/wpa_supplicant.conf
170176
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
171177
update_config=1
172178
EOF
173179

180+
# Start wireless access point.
174181
rfkill unblock wlan
175182
systemctl unmask hostapd dnsmasq
176183
systemctl enable hostapd dnsmasq

0 commit comments

Comments
 (0)