mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 13:23:01 +02:00
confd: Dynamically generate factory-config
This allows you to define a single "logical" config that can be tailored to the specific system based on the available interfaces, base MAC address etc.
This commit is contained in:
committed by
Joachim Wiberg
parent
80d9312e36
commit
03e44dd5b1
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ietf-system:system": {
|
||||
"hostname": "infix"
|
||||
}
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
PATH=/lib/infix/factory:$PATH
|
||||
|
||||
[ "$FACTORY_D" ] || FACTORY_D=/etc/auto-factory.d
|
||||
[ "$CFG_D" ] || CFG_D=/cfg
|
||||
|
||||
gen-hostname >$FACTORY_D/20-auto-hostname.json
|
||||
gen-interfaces >$FACTORY_D/20-auto-interfaces.json
|
||||
|
||||
jq -s add $(find $FACTORY_D -name '*.json') >$CFG_D/auto-factory-config.cfg
|
||||
|
||||
# TODO: Look for statically defined factory-config, based on the
|
||||
# system's product ID.
|
||||
|
||||
# If we haven't found a better one, settle for auto-factory-config as
|
||||
# the system's factory-config.
|
||||
[ -h $CFG_D/factory-config.cfg ] || \
|
||||
ln -sf auto-factory-config.cfg $CFG_D/factory-config.cfg
|
||||
|
||||
# On first boot, install factory-config as startup-config
|
||||
[ -f $CFG_D/startup-config.cfg ] || \
|
||||
cp $CFG_D/factory-config.cfg $CFG_D/startup-config.cfg
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
base_mac_lowest_physical()
|
||||
{
|
||||
ip -d -j link show | jq -r '
|
||||
.[] |
|
||||
select(.link_type == "ether") |
|
||||
select(has("linkinfo") | not) | .address' \
|
||||
| sort | head -n 1
|
||||
}
|
||||
|
||||
source_base_mac()
|
||||
{
|
||||
# TODO: Source the base MAC from the vital product data memory, if
|
||||
# available.
|
||||
# base_mac=$(base_mac_vpd)
|
||||
# [ "$base_mac" ] && return
|
||||
|
||||
base_mac=$(base_mac_lowest_physical)
|
||||
[ "$base_mac" ] && return
|
||||
|
||||
base_mac=00:00:00:00:00:00
|
||||
}
|
||||
|
||||
if [ "$1" ]; then
|
||||
sysname="$1"
|
||||
else
|
||||
sysname="$(cat /etc/hostname)"
|
||||
fi
|
||||
|
||||
source_base_mac
|
||||
sysname="${sysname}-$(echo $base_mac | tail -c 9 | tr ':' '-')"
|
||||
|
||||
cat <<EOF
|
||||
{
|
||||
"ietf-system:system": {
|
||||
"hostname": "${sysname}"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
gen_interface()
|
||||
{
|
||||
cat <<EOF
|
||||
,{
|
||||
"name": "$1",
|
||||
"type": "iana-if-type:ethernetCsmacd"
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
phys_ifaces=$(ip -d -j link show | jq -r '
|
||||
.[] |
|
||||
select(.link_type == "ether") |
|
||||
select(has("linkinfo") | not) |
|
||||
.ifname')
|
||||
|
||||
cat <<EOF
|
||||
{
|
||||
"ietf-interfaces:interfaces": {
|
||||
"interface": [
|
||||
{
|
||||
"name": "lo",
|
||||
"type": "iana-if-type:softwareLoopback",
|
||||
"ietf-ip:ipv4": {
|
||||
"address": [{ "ip": "127.0.0.1", "prefix-length": 8 }]
|
||||
},
|
||||
"ietf-ip:ipv6": {
|
||||
"address": [{ "ip": "::1", "prefix-length": 128 }]
|
||||
}
|
||||
}
|
||||
$(for iface in $phys_ifaces; do gen_interface $iface; done)
|
||||
]
|
||||
}
|
||||
}
|
||||
EOF
|
||||
@@ -1,4 +1,5 @@
|
||||
run [S] /lib/infix/clean-etc --
|
||||
run [S] /lib/infix/cfg-bootstrap --
|
||||
|
||||
service name:sysrepo [S12345789] sysrepo-plugind -p /run/sysrepo.pid -n -- Configuration daemon
|
||||
run [S] log <pid/sysrepo> sysrepocfg -v4 -E/cfg/startup-config.cfg -f json --
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
d /run/resolvconf/interfaces - - -
|
||||
C /cfg/startup-config.cfg - - -
|
||||
|
||||
|
||||
Reference in New Issue
Block a user