Skip to content

Commit

Permalink
Add comments to wireless access point scripts (#1784)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jdeanwallace authored Jul 31, 2024
1 parent 3d33c4d commit 61511d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions debian-pkg/opt/tinypilot-privileged/scripts/disable-wifi-ap
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,24 @@ readonly SCRIPT_DIR
# shellcheck source=lib/markers.sh
. "${SCRIPT_DIR}/lib/markers.sh"

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

mv \
/etc/wpa_supplicant/wpa_supplicant.conf.bak \
/etc/wpa_supplicant/wpa_supplicant.conf
# Restore previously backed up WPA configurations.
if [[ -e /etc/wpa_supplicant/wpa_supplicant.conf.bak ]]; then
mv \
/etc/wpa_supplicant/wpa_supplicant.conf.bak \
/etc/wpa_supplicant/wpa_supplicant.conf
fi

# Disable WPA.
if [[ -e /etc/wpa_supplicant/wlan_enabled ]]; then
rm --force /etc/wpa_supplicant/wlan_enabled
else
rfkill block wlan
fi

# Stop wireless access point.
systemctl stop hostapd dnsmasq
rm --force \
/etc/hostapd/hostapd.conf \
Expand Down
7 changes: 7 additions & 0 deletions debian-pkg/opt/tinypilot-privileged/scripts/enable-wifi-ap
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ readonly SCRIPT_DIR
# shellcheck source=lib/markers.sh
. "${SCRIPT_DIR}/lib/markers.sh"

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

# Enable wireless network interface.
cat <<EOF | tee --append /etc/dhcpcd.conf
${MARKER_START}
interface wlan0
Expand All @@ -134,6 +136,7 @@ nohook wpa_supplicant
${MARKER_END}
EOF

# Configure wireless access point.
cat <<EOF | tee /etc/hostapd/hostapd.conf
country_code=${NETWORK_COUNTRY}
interface=wlan0
Expand All @@ -150,13 +153,15 @@ wpa_pairwise=TKIP
rsn_pairwise=CCMP
EOF

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

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

# Clear WPA configurations.
cat <<'EOF' | tee /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
EOF

# Start wireless access point.
rfkill unblock wlan
systemctl unmask hostapd dnsmasq
systemctl enable hostapd dnsmasq
Expand Down

0 comments on commit 61511d3

Please sign in to comment.