mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-11-02 17:23:32 +00:00
d953d0a973
Ubuntu 26.04's openvswitch-switch declares Alias=openvswitch.service, so enabling it leaves an /etc symlink that distro_ovs_unit read as a second, EL-style umbrella unit. setup-ovn.sh then refused to pick one and every ubuntu-26.04 bootstrap failed. A symlink back to openvswitch-switch.service now counts as the Debian unit; a real or masked openvswitch.service still does not.
203 lines
8.5 KiB
Bash
203 lines
8.5 KiB
Bash
# shellcheck shell=bash
|
|
# distro.sh — host-OS capability probes. Each prints its answer, or names every
|
|
# candidate it tried on stderr and returns 1, also when it finds both of a pair.
|
|
# setup.sh and node-reset.sh carry inline copies; distro_test.sh keeps them equal.
|
|
|
|
# Reads unit files off disk, not through systemctl, so it answers in a chroot.
|
|
# DISTRO_ROOT prefixes every host path the probes read; tests set it.
|
|
distro_unit_exists() {
|
|
local dir
|
|
for dir in /etc/systemd/system /run/systemd/system /usr/lib/systemd/system /lib/systemd/system; do
|
|
if [ -e "${DISTRO_ROOT:-}$dir/$1" ] || [ -L "${DISTRO_ROOT:-}$dir/$1" ]; then
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
distro_pkg_manager() {
|
|
local apt=false dnf=false
|
|
command -v apt-get >/dev/null 2>&1 && apt=true
|
|
command -v dnf >/dev/null 2>&1 && dnf=true
|
|
if $apt && $dnf; then
|
|
echo "distro.sh: package manager: found both apt-get and dnf; cannot tell which one manages this host" >&2
|
|
return 1
|
|
fi
|
|
if $apt; then echo apt; return 0; fi
|
|
if $dnf; then echo dnf; return 0; fi
|
|
echo "distro.sh: package manager: found neither apt-get nor dnf on PATH" >&2
|
|
return 1
|
|
}
|
|
|
|
# The OVS umbrella unit: openvswitch-switch.service on Debian, openvswitch.service on EL.
|
|
# Ubuntu's openvswitch-switch declares Alias=openvswitch.service; the symlink that
|
|
# enabling it leaves points back at openvswitch-switch.service and is not the EL unit.
|
|
distro_ovs_unit() {
|
|
local deb=false el=false dir
|
|
distro_unit_exists openvswitch-switch.service && deb=true
|
|
for dir in /etc/systemd/system /run/systemd/system /usr/lib/systemd/system /lib/systemd/system; do
|
|
if [ -e "${DISTRO_ROOT:-}$dir/openvswitch.service" ] || [ -L "${DISTRO_ROOT:-}$dir/openvswitch.service" ]; then
|
|
case $(readlink "${DISTRO_ROOT:-}$dir/openvswitch.service" || true) in
|
|
openvswitch-switch.service | */openvswitch-switch.service) ;;
|
|
*) el=true ;;
|
|
esac
|
|
fi
|
|
done
|
|
if $deb && $el; then
|
|
echo "distro.sh: OVS unit: found both openvswitch-switch.service and openvswitch.service; cannot tell which one owns OVS" >&2
|
|
return 1
|
|
fi
|
|
if $deb; then echo openvswitch-switch.service; return 0; fi
|
|
if $el; then echo openvswitch.service; return 0; fi
|
|
echo "distro.sh: OVS unit: found neither openvswitch-switch.service nor openvswitch.service; is Open vSwitch installed?" >&2
|
|
return 1
|
|
}
|
|
|
|
# "split": Debian's ovn-central plus separate NB and SB DB units.
|
|
# "lone-northd": EL's single ovn-northd.service, which starts both DB servers.
|
|
distro_ovn_central_layout() {
|
|
local split=false lone=false unit missing=""
|
|
for unit in ovn-central.service ovn-ovsdb-server-nb.service ovn-ovsdb-server-sb.service; do
|
|
if distro_unit_exists "$unit"; then
|
|
split=true
|
|
else
|
|
missing="${missing:+$missing, }$unit"
|
|
fi
|
|
done
|
|
if distro_unit_exists ovn-northd.service && [ -f "${DISTRO_ROOT:-}/etc/sysconfig/ovn" ]; then
|
|
lone=true
|
|
fi
|
|
if $split && $lone; then
|
|
echo "distro.sh: OVN central layout: found both the split units (ovn-central.service) and a lone ovn-northd.service with /etc/sysconfig/ovn; cannot tell which one owns the OVN databases" >&2
|
|
return 1
|
|
fi
|
|
if $split; then
|
|
if [ -n "$missing" ]; then
|
|
echo "distro.sh: OVN central layout: ovn-central is installed but $missing is missing" >&2
|
|
return 1
|
|
fi
|
|
echo split
|
|
return 0
|
|
fi
|
|
if $lone; then echo lone-northd; return 0; fi
|
|
echo "distro.sh: OVN central layout: found neither ovn-central.service nor ovn-northd.service with /etc/sysconfig/ovn; is OVN central installed?" >&2
|
|
return 1
|
|
}
|
|
|
|
# The trust-store update command and its local anchor directory, space-separated.
|
|
distro_ca_trust() {
|
|
local deb=false el=false
|
|
command -v update-ca-certificates >/dev/null 2>&1 && deb=true
|
|
command -v update-ca-trust >/dev/null 2>&1 && el=true
|
|
if $deb && $el; then
|
|
echo "distro.sh: CA trust: found both update-ca-certificates and update-ca-trust; cannot tell which trust store TLS clients read" >&2
|
|
return 1
|
|
fi
|
|
if $deb; then echo "update-ca-certificates /usr/local/share/ca-certificates"; return 0; fi
|
|
if $el; then echo "update-ca-trust /etc/pki/ca-trust/source/anchors"; return 0; fi
|
|
echo "distro.sh: CA trust: found neither update-ca-certificates nor update-ca-trust on PATH" >&2
|
|
return 1
|
|
}
|
|
|
|
# chrony's main config file: /etc/chrony/chrony.conf on Debian, /etc/chrony.conf on EL.
|
|
distro_chrony_conf() {
|
|
local deb=false el=false
|
|
[ -f "${DISTRO_ROOT:-}/etc/chrony/chrony.conf" ] && deb=true
|
|
[ -f "${DISTRO_ROOT:-}/etc/chrony.conf" ] && el=true
|
|
if $deb && $el; then
|
|
echo "distro.sh: chrony config: found both /etc/chrony/chrony.conf and /etc/chrony.conf; cannot tell which one chronyd reads" >&2
|
|
return 1
|
|
fi
|
|
if $deb; then echo /etc/chrony/chrony.conf; return 0; fi
|
|
if $el; then echo /etc/chrony.conf; return 0; fi
|
|
echo "distro.sh: chrony config: found neither /etc/chrony/chrony.conf nor /etc/chrony.conf; is chrony installed?" >&2
|
|
return 1
|
|
}
|
|
|
|
distro_ovn_logrotate() {
|
|
local deb=false el=false
|
|
[ -f "${DISTRO_ROOT:-}/etc/logrotate.d/ovn-common" ] && deb=true
|
|
[ -f "${DISTRO_ROOT:-}/etc/logrotate.d/ovn" ] && el=true
|
|
if $deb && $el; then
|
|
echo "distro.sh: OVN logrotate: found both /etc/logrotate.d/ovn-common and /etc/logrotate.d/ovn; cannot tell which one the OVN packages own" >&2
|
|
return 1
|
|
fi
|
|
if $deb; then echo /etc/logrotate.d/ovn-common; return 0; fi
|
|
if $el; then echo /etc/logrotate.d/ovn; return 0; fi
|
|
echo "distro.sh: OVN logrotate: found neither /etc/logrotate.d/ovn-common nor /etc/logrotate.d/ovn; is OVN installed?" >&2
|
|
return 1
|
|
}
|
|
|
|
distro_ovs_logrotate() {
|
|
local deb=false el=false
|
|
[ -f "${DISTRO_ROOT:-}/etc/logrotate.d/openvswitch-switch" ] && deb=true
|
|
[ -f "${DISTRO_ROOT:-}/etc/logrotate.d/openvswitch" ] && el=true
|
|
if $deb && $el; then
|
|
echo "distro.sh: OVS logrotate: found both /etc/logrotate.d/openvswitch-switch and /etc/logrotate.d/openvswitch; cannot tell which one the OVS packages own" >&2
|
|
return 1
|
|
fi
|
|
if $deb; then echo /etc/logrotate.d/openvswitch-switch; return 0; fi
|
|
if $el; then echo /etc/logrotate.d/openvswitch; return 0; fi
|
|
echo "distro.sh: OVS logrotate: found neither /etc/logrotate.d/openvswitch-switch nor /etc/logrotate.d/openvswitch; is Open vSwitch installed?" >&2
|
|
return 1
|
|
}
|
|
|
|
# libreswan's IKE daemon. EL's openvswitch-ipsec drives libreswan even beside
|
|
# strongSwan, so this is a presence check rather than one of a pair.
|
|
distro_has_libreswan() {
|
|
[ -x "${DISTRO_ROOT:-}/usr/libexec/ipsec/pluto" ]
|
|
}
|
|
|
|
# The OS family of the os-release text on stdin, for install-node.sh's one-OS
|
|
# cluster check: "debian" for Debian and Ubuntu, so mixing those is not newly
|
|
# refused, and the ID itself for anything else.
|
|
distro_os_family() {
|
|
local line id="" like=""
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
case "$line" in
|
|
ID=*) id=${line#ID=} ;;
|
|
ID_LIKE=*) like=${line#ID_LIKE=} ;;
|
|
esac
|
|
done
|
|
id=${id//[\"\']/}
|
|
like=${like//[\"\']/}
|
|
if [ -z "$id" ]; then
|
|
echo "distro.sh: OS family: /etc/os-release has no ID" >&2
|
|
return 1
|
|
fi
|
|
case " $id $like " in
|
|
*" debian "*) echo debian ;;
|
|
*) echo "$id" ;;
|
|
esac
|
|
}
|
|
|
|
# The OVS and OVN units the given unit files depend on or order against that
|
|
# are not installed, one per line; prints nothing when all are. Fails only
|
|
# when a unit file cannot be read.
|
|
distro_missing_ovs_deps() {
|
|
local file line dep missing=""
|
|
for file in "$@"; do
|
|
if [ ! -r "${DISTRO_ROOT:-}$file" ]; then
|
|
echo "distro.sh: OVS dependencies: cannot read $file" >&2
|
|
return 1
|
|
fi
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
case "$line" in
|
|
After=* | Before=* | Wants=* | Requires=* | Requisite=* | BindsTo=* | PartOf=* | Upholds=*) ;;
|
|
*) continue ;;
|
|
esac
|
|
for dep in ${line#*=}; do
|
|
case "$dep" in
|
|
ovs* | ovn* | openvswitch*) ;;
|
|
*) continue ;;
|
|
esac
|
|
case " $missing " in
|
|
*" $dep "*) continue ;;
|
|
esac
|
|
distro_unit_exists "$dep" || missing="${missing:+$missing }$dep"
|
|
done
|
|
done <"${DISTRO_ROOT:-}$file"
|
|
done
|
|
for dep in $missing; do echo "$dep"; done
|
|
}
|