two-images/packer/scripts/check.sh
GnomeZworc fe401b9a12
Some checks failed
Tests / check (push) Failing after 39s
two-images: construction reproductible de rocky10 et debian13 par Packer, test de démarrage syonad/two#53
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-10-24 13:53:56 +02:00

60 lines
2 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
FAILED=0
check () {
local desc="${1}"
shift
if "$@"; then
echo "RÉUSSI: ${desc}"
else
echo "ÉCHOUÉ: ${desc}"
FAILED=1
fi
}
empty_or_absent () {
[ ! -e "${1}" ] || [ -z "$(find "${1}" -mindepth 1 -print -quit)" ]
}
no_match () {
local dir="${1}"
shift
[ ! -d "${dir}" ] || [ -z "$(find "${dir}" "$@" -print -quit)" ]
}
has_line () {
grep -qxF -- "${2}" "${1}"
}
no_build_user () {
! grep -q '^build:' /mnt/etc/passwd
}
machine_id_blank () {
[ ! -s /mnt/etc/machine-id ]
}
check "/var/lib/cloud vide" empty_or_absent /mnt/var/lib/cloud
check "aucune clé d'hôte SSH" no_match /mnt/etc/ssh -maxdepth 1 -name 'ssh_host_*'
check "aucun authorized_keys sous /root" no_match /mnt/root -name authorized_keys
check "aucun authorized_keys sous /home" no_match /mnt/home -name authorized_keys
check "machine-id vide" machine_id_blank
check "utilisateur de construction absent" no_build_user
check "aucun journal" no_match /mnt/var/log ! -type d
check "source NoCloud vers 169.254.169.254" has_line /mnt/etc/cloud/cloud.cfg.d/99_metadata.cfg " seedfrom: 'http://169.254.169.254:80/'"
check "network-config réappliqué à chaque démarrage" has_line /mnt/etc/cloud/cloud.cfg.d/98_network_updates.cfg " when: [boot-new-instance, boot, boot-legacy]"
check "règle udev xvd" test -s /mnt/etc/udev/rules.d/90-two-xvd.rules
case "${FAMILY}" in
debian)
check "DHCP sur toutes les interfaces (networkd)" has_line /mnt/etc/systemd/network/90-all-en.network "Name=en*"
;;
rocky)
check "DHCP sur toutes les interfaces (NetworkManager)" has_line /mnt/etc/NetworkManager/system-connections/90-all-en.nmconnection "interface-name=en*"
check "SELinux désactivé" has_line /mnt/etc/selinux/config "SELINUX=disabled"
check "utilisateur par défaut syonad" has_line /mnt/etc/cloud/cloud.cfg.d/20_user.cfg " name: syonad"
;;
esac
[ "${FAILED}" -eq 0 ] || { echo "!! image refusée" >&2; exit 1; }