Skip to content

Commit

Permalink
Update network setup to allow node management without re-signing /usr
Browse files Browse the repository at this point in the history
  • Loading branch information
valtzu committed Apr 23, 2024
1 parent 67021b1 commit 1bf1a33
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 5 deletions.
7 changes: 7 additions & 0 deletions mkosi.extra/efi/loader/credentials/instances.json.cred
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"10000000EA5D8564": "rpi-01",
"100000007673E239": "rpi-02",
"10000000D0AC99BD": "rpi-03",
"10000000DA074F61": "rpi-04",
"1000000069738888": "rpi-05"
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Match]
Name=static
Type=vlan
MACAddress=e4:5f:01:27:9c:3b
Host=rpi-01

[Network]
LinkLocalAddressing=no
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Match]
Name=static
Type=vlan
MACAddress=e4:5f:01:83:fa:b0
Host=rpi-02

[Network]
LinkLocalAddressing=no
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Match]
Name=static
Type=vlan
MACAddress=e4:5f:01:83:fb:73
Host=rpi-03

[Network]
LinkLocalAddressing=no
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Match]
Name=static
Type=vlan
MACAddress=e4:5f:01:83:fd:5f
Host=rpi-04

[Network]
LinkLocalAddressing=no
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Match]
Name=static
Type=vlan
MACAddress=e4:5f:01:83:fd:68
Host=rpi-05

[Network]
LinkLocalAddressing=no
Expand Down
23 changes: 23 additions & 0 deletions mkosi.extra/usr/lib/systemd/system-generators/static-network
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

dir=$1
instances_file=$CREDENTIALS_DIRECTORY/instances.json
etc_hosts=/etc/hosts

[ -f $instances_file ] && [ -f $etc_hosts ] || exit 0

hostname=$([ -f /etc/hostname ] && cat /etc/hostname || /usr/bin/jq -jrs '.[0][.[1]|tostring]' $instances_file /proc/device-tree/serial-number)
! [ -z "$hostname" ] || exit 0
ip=$(grep -m1 $hostname $etc_hosts | cut -f1 -d' ')
! [ -z "$ip" ] || exit 0

mkdir -p /run/systemd/network
cat > /run/systemd/network/10-static.network <<INI
[Match]
Name=static
Type=vlan
[Network]
LinkLocalAddressing=no
Address=$ip/24
INI
1 change: 1 addition & 0 deletions mkosi.extra/usr/lib/systemd/system-preset/00-mkosi.preset
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
enable hostname-setup.service
enable sshd-keygen.service
15 changes: 15 additions & 0 deletions mkosi.extra/usr/lib/systemd/system/hostname-setup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Set hostname
DefaultDependencies=no
Before=first-boot-complete.target
ConditionCredential=instances.json
ConditionFirstBoot=yes

[Service]
Type=oneshot
LoadCredential=instances.json
ExecStart=/usr/bin/jq -jrs '.[0][.[1]|tostring]' %d/instances.json /proc/device-tree/serial-number
StandardOutput=file:/etc/hostname

[Install]
WantedBy=first-boot-complete.target

0 comments on commit 1bf1a33

Please sign in to comment.