Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TojikCZ committed Jan 30, 2024
1 parent fb44610 commit 5ab5ae9
Show file tree
Hide file tree
Showing 42 changed files with 6,908 additions and 13 deletions.
11 changes: 11 additions & 0 deletions image_builder/image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ def build_image():
run_command(f"cp -r {KERNEL_VERSION_NAME} "
f"{ROOTFS_MOUNT}/lib/modules/{KERNEL_VERSION_NAME}")

print("Write polkit override, so Link can modify wifi settings")
nm_rule_path = join(BUILDER_DATA_PATH, "01-prusalink-nm.rules")
polkit_rules = join(ROOTFS_MOUNT, "etc/polkit-1/rules.d/")
run_command(f"cp {nm_rule_path} {polkit_rules}")

print("Write dnsmasq ap0 settings")
nm_dnsmasq_path = join(BUILDER_DATA_PATH, "ap0-dnsmasq.conf")
dnsmasq_shared_path = join(ROOTFS_MOUNT,
"etc/NetworkManager/dnsmasq-shared.d/")
run_command(f"cp {nm_dnsmasq_path} {dnsmasq_shared_path}")

config_txt_path = join(BOOTFS_MOUNT, "config.txt")
with open(config_txt_path, "a", encoding="utf-8") as config_txt:
config_txt.write("dtoverlay=disable-bt\n")
Expand Down
6 changes: 6 additions & 0 deletions prusa/link/data/image_builder/01-prusalink-nm.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
polkit.addRule(function(action, subject) {
if (action.id.match("org.freedesktop.NetworkManager") &&
(subject.isInGroup("sudo") || subject.isInGroup("netdev"))) {
return polkit.Result.YES;
}
});
15 changes: 15 additions & 0 deletions prusa/link/data/image_builder/add-ap0.service-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Add ap0 interface
Requires=sys-subsystem-net-devices-wlan0.device
Before=dhcpcd.service
Before=wpa_supplicant.service
Restart=on-failure
StartLimitIntervalSec=1
StartLimitBurst=5

[Service]
Type=oneshot
ExecStart=/usr/sbin/iw dev {device} interface add ap0 type __ap

[Install]
WantedBy=multi-user.target
19 changes: 19 additions & 0 deletions prusa/link/data/image_builder/ap0-dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Disable DNS server functionality
port=0

# Specify the interface
interface=ap0

# Define the range of IP addresses that will be handed out by the DHCP server
dhcp-range=172.16.188.100,172.16.188.200,255.255.255.0,43200

# Set the default gateway (note that this is a 'dummy' gateway as per your requ>
dhcp-option=option:router,172.16.188.1

# Set the lease time (you can adjust this as needed)
dhcp-leasefile=/var/lib/misc/dnsmasq.leases
dhcp-lease-max=150

# Disable DNS server functionality
no-resolv
no-hosts
1 change: 1 addition & 0 deletions prusa/link/data/image_builder/manager-start-script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Forward the port 80 to 8080 even on the loopback, so we van ping ourselves
iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i ap0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -I OUTPUT -p tcp -o lo -d localhost --dport 80 -j REDIRECT --to-ports 8080

set_up_port () {
Expand Down
1 change: 1 addition & 0 deletions prusa/link/data/image_builder/prusalink-start-script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Forward the port 80 to 8080 even on the loopback, so we van ping ourselves
iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i ap0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -I OUTPUT -p tcp -o lo -d localhost --dport 80 -j REDIRECT --to-ports 8080

set_up_port () {
Expand Down
Loading

0 comments on commit 5ab5ae9

Please sign in to comment.