Skip to content

Commit 85883bf

Browse files
dbieberclaude
andcommitted
Refactor build workflow by extracting scripts
Move large script blocks from build.yml into separate script files: - WiFi access point setup - System boot configuration - Python environment setup - Geckodriver installation - Bash history setup This improves maintainability while preserving the current functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b11e39e commit 85883bf

File tree

7 files changed

+244
-192
lines changed

7 files changed

+244
-192
lines changed

.github/scripts/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# GoNoteGo Build Scripts
2+
3+
This directory contains scripts used in the build process for creating the GoNoteGo Raspberry Pi image.
4+
5+
## Scripts
6+
7+
- `setup_wifi_ap.sh`: Sets up the WiFi access point for the GoNoteGo device
8+
- `setup_boot.sh`: Configures the system to start GoNoteGo on boot and sets initial system settings
9+
- `setup_python_env.sh`: Sets up the Python environment for GoNoteGo
10+
- `install_geckodriver.sh`: Installs the geckodriver needed for browser automation
11+
- `setup_bash_history.sh`: Sets up useful commands in bash history for debugging purposes
12+
13+
These scripts are used by the GitHub workflow defined in `.github/workflows/build.yml`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Install geckodriver for browser automation
3+
4+
echo "Install geckodriver to known location"
5+
cd
6+
wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-arm7hf.tar.gz
7+
tar -xvf geckodriver-v0.23.0-arm7hf.tar.gz
8+
rm geckodriver-v0.23.0-arm7hf.tar.gz
9+
sudo mv geckodriver /usr/local/bin
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# Add useful commands to the bash history for debugging purposes
3+
4+
cat << EOF >> /home/pi/.bash_history
5+
sudo reboot now
6+
sudo systemctl daemon-reload
7+
sudo systemctl status uap0.service
8+
sudo systemctl status dnsmasq.service
9+
sudo systemctl status hostapd.service
10+
sudo journalctl -u uap0.service
11+
sudo journalctl -u dnsmasq.service
12+
sudo journalctl -u hostapd.service
13+
ip addr show uap0
14+
sudo ip addr add 192.168.4.1/24 dev uap0
15+
cat /etc/rc.local
16+
cat /etc/default/hostapd
17+
cat /etc/hostapd/hostapd.conf
18+
cat /etc/systemd/system/uap0.service
19+
cat /etc/sysctl.conf
20+
cat /etc/dhcpcd.conf
21+
cat /etc/dnsmasq.conf
22+
python -m http.server
23+
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
24+
sudo iptables -t nat -L
25+
sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
26+
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
27+
nano /home/pi/code/github/dbieber/GoNoteGo/gonotego/settings/secure_settings.py
28+
/home/pi/code/github/dbieber/GoNoteGo/env/bin/python
29+
/home/pi/code/github/dbieber/GoNoteGo/env/bin/supervisord -c /home/pi/code/github/dbieber/GoNoteGo/gonotego/supervisord.conf
30+
/home/pi/code/github/dbieber/GoNoteGo/env/bin/supervisorctl -u go -p notego status
31+
/home/pi/code/github/dbieber/GoNoteGo/env/bin/supervisorctl -u go -p notego restart all
32+
cd /home/pi/code/github/dbieber/GoNoteGo/
33+
EOF

.github/scripts/setup_boot.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Configure system to start GoNoteGo on boot
3+
4+
# Modify rc.local to start GoNoteGo on boot
5+
sudo cat /etc/rc.local
6+
sudo sed '/^exit 0/i \
7+
sudo -u pi mkdir -p /home/pi/out \
8+
bash /home/pi/code/github/dbieber/GoNoteGo/scripts/install_settings.sh \
9+
/home/pi/code/github/dbieber/GoNoteGo/env/bin/supervisord -c /home/pi/code/github/dbieber/GoNoteGo/gonotego/supervisord.conf \
10+
' /etc/rc.local > ./rc.local.modified && sudo mv ./rc.local.modified /etc/rc.local
11+
sudo chmod +x /etc/rc.local
12+
13+
# Configure initial system settings
14+
# Attempt to not run config on first boot
15+
sudo apt purge piwiz -y
16+
sudo raspi-config nonint do_wifi_country US
17+
# Configure US keyboard layout
18+
sudo raspi-config nonint do_configure_keyboard us
19+
touch /boot/ssh
20+
echo "pi:$(echo 'raspberry' | openssl passwd -6 -stdin)" | sudo tee /boot/userconf > /dev/null
21+
22+
# Enable SSH
23+
ssh-keygen -A &&
24+
update-rc.d ssh enable
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Setup Python environment for GoNoteGo
3+
4+
echo "Setting up Python environment"
5+
python3 -m venv env
6+
./env/bin/pip install -e . # Install Python dependencies
7+
8+
echo "Setting up Go Note Go:"
9+
cp gonotego/settings/secure_settings_template.py gonotego/settings/secure_settings.py
10+
echo "Manually edit secure_settings.py to configure your settings."
11+
12+
mkdir -p /home/pi/secrets
13+
echo "Manually transfer secrets to /home/pi/secrets."
14+
15+
# Ensure repository is owned by pi user instead of root
16+
chown -R pi:pi /home/pi/code/github/dbieber/GoNoteGo

.github/scripts/setup_wifi_ap.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/bash
2+
# Setup WiFi Access Point for GoNoteGo
3+
4+
# Install required packages
5+
sudo apt install -y rng-tools hostapd dnsmasq
6+
7+
# Configure dhcpcd
8+
cat <<EOF > /etc/dhcpcd.conf
9+
# Allow users of this group to interact with dhcpcd via the control socket.
10+
#controlgroup wheel
11+
12+
# Inform the DHCP server of our hostname for DDNS.
13+
hostname
14+
15+
# Use the hardware address of the interface for the Client ID.
16+
clientid
17+
# or
18+
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
19+
# Some non-RFC compliant DHCP servers do not reply with this set.
20+
# In this case, comment out duid and enable clientid above.
21+
#duid
22+
23+
# Persist interface configuration when dhcpcd exits.
24+
persistent
25+
26+
# Rapid commit support.
27+
# Safe to enable by default because it requires the equivalent option set
28+
# on the server to actually work.
29+
option rapid_commit
30+
31+
# A list of options to request from the DHCP server.
32+
option domain_name_servers, domain_name, domain_search, host_name
33+
option classless_static_routes
34+
# Respect the network MTU. This is applied to DHCP routes.
35+
option interface_mtu
36+
37+
# Most distributions have NTP support.
38+
#option ntp_servers
39+
40+
# A ServerID is required by RFC2131.
41+
require dhcp_server_identifier
42+
43+
# Generate SLAAC address using the Hardware Address of the interface
44+
#slaac hwaddr
45+
# OR generate Stable Private IPv6 Addresses based from the DUID
46+
slaac private
47+
48+
# Example static IP configuration:
49+
#interface eth0
50+
#static ip_address=192.168.0.10/24
51+
#static ip6_address=fd51:42f8:caae:d92e::ff/64
52+
#static routers=192.168.0.1
53+
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1
54+
55+
# It is possible to fall back to a static IP if DHCP fails:
56+
# define static profile
57+
#profile static_eth0
58+
#static ip_address=192.168.1.23/24
59+
#static routers=192.168.1.1
60+
#static domain_name_servers=192.168.1.1
61+
62+
# fallback to static profile on eth0
63+
#interface eth0
64+
#fallback static_eth0
65+
66+
# Interface for Go Note Go Access Point
67+
interface uap0
68+
static ip_address=192.168.4.1/24
69+
nohook wpa_supplicant
70+
EOF
71+
72+
# Configure dnsmasq
73+
cat <<EOF >> /etc/dnsmasq.conf
74+
interface=uap0
75+
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
76+
EOF
77+
78+
# Create uap0 service
79+
cat <<EOF >> /etc/systemd/system/uap0.service
80+
[Unit]
81+
Description=Create uap0 interface
82+
After=sys-subsystem-net-devices-wlan0.device
83+
84+
[Service]
85+
Type=oneshot
86+
RemainAfterExit=true
87+
ExecStart=/sbin/iw phy phy0 interface add uap0 type __ap
88+
ExecStartPost=/usr/bin/ip link set dev uap0 address d8:3a:dd:06:5e:ca
89+
ExecStartPost=/sbin/ifconfig uap0 up
90+
ExecStop=/sbin/iw dev uap0 del
91+
92+
[Install]
93+
WantedBy=multi-user.target
94+
EOF
95+
96+
# Enable and start uap0 service
97+
sudo systemctl daemon-reload
98+
sudo systemctl start uap0.service
99+
sudo systemctl enable uap0.service
100+
101+
# Configure hostapd
102+
cat <<EOF >> /etc/hostapd/hostapd.conf
103+
interface=uap0
104+
ssid=GoNoteGo-Wifi
105+
hw_mode=g
106+
channel=4
107+
wmm_enabled=0
108+
macaddr_acl=0
109+
auth_algs=1
110+
ignore_broadcast_ssid=0
111+
wpa=2
112+
wpa_passphrase=swingset
113+
wpa_key_mgmt=WPA-PSK
114+
wpa_pairwise=TKIP
115+
rsn_pairwise=CCMP
116+
EOF
117+
118+
# Update hostapd defaults
119+
cat <<EOF >> /etc/default/hostapd
120+
DAEMON_CONF="/etc/hostapd/hostapd.conf"
121+
EOF
122+
123+
# Start and enable hostapd and dnsmasq
124+
sudo systemctl start hostapd
125+
sudo systemctl start dnsmasq
126+
sudo systemctl enable hostapd
127+
sudo systemctl enable dnsmasq
128+
129+
# Enable IP forwarding
130+
cat <<EOF >> /etc/sysctl.conf
131+
net.ipv4.ip_forward=1
132+
EOF

0 commit comments

Comments
 (0)