#!/usr/bin/env bash set -euo pipefail die () { echo "!! ${1}" >&2; exit 1; } unit_exists () { [ -e "/mnt/usr/lib/systemd/system/${1}" ] || [ -e "/mnt/etc/systemd/system/${1}" ] } echo "The default user for Syonad VMs is 'syonad'." > /mnt/etc/banner augtool -r /mnt -s <<'EOF' set /files/etc/ssh/sshd_config/X11Forwarding no set /files/etc/ssh/sshd_config/PermitTunnel no set /files/etc/ssh/sshd_config/PermitRootLogin no set /files/etc/ssh/sshd_config/RSAAuthentication yes set /files/etc/ssh/sshd_config/PubkeyAuthentication yes set /files/etc/ssh/sshd_config/PasswordAuthentication no set /files/etc/ssh/sshd_config/UseDNS no set /files/etc/ssh/sshd_config/ChallengeResponseAuthentication no set /files/etc/ssh/sshd_config/GSSAPIAuthentication no set /files/etc/ssh/sshd_config/Match[1]/Condition/User "root,centos,ubuntu,debian,ec2-user" set /files/etc/ssh/sshd_config/Match[1]/Settings/Banner "/etc/banner" EOF cat > /mnt/etc/cloud/cloud.cfg.d/20_user.cfg <<'EOF' system_info: default_user: name: syonad EOF install -m 0600 /dev/stdin /mnt/etc/NetworkManager/system-connections/90-all-en.nmconnection <<'EOF' [connection] id=two-all-en type=ethernet autoconnect-priority=-100 multi-connect=3 [match] interface-name=en* [ipv4] method=auto [ipv6] method=ignore EOF chroot /mnt systemctl enable fstrim.timer for unit in rpcbind.service rpcbind.socket; do if unit_exists "${unit}"; then chroot /mnt systemctl disable "${unit}" fi done CLOUDINIT=$(chroot /mnt python3 -c 'import cloudinit, os; print(os.path.dirname(cloudinit.__file__))') [ -n "${CLOUDINIT}" ] || die "module cloudinit introuvable dans la cible" patch -d "/mnt${CLOUDINIT}" -p1 --forward --fuzz=0 --no-backup-if-mismatch <<'EOF' --- a/net/network_manager.py +++ b/net/network_manager.py @@ -594,10 +594,11 @@ conn.render_interface(iface, network_state, self) # And finally write the files - for con_id, conn in self.connections.items(): + for iface in network_state.iter_interfaces(): + conn = self.connections[iface.get("config_id") or iface["name"]] if not conn.valid(): continue - name = nm_conn_filename(con_id, target) + name = nm_conn_filename(iface["name"], target) util.write_file(name, conn.dump(), 0o600) # Select EUI64 to be used by default by NM for creating the address EOF chroot /mnt python3 -m py_compile "${CLOUDINIT}/net/network_manager.py" augtool -r /mnt -s set /files/etc/selinux/config/SELINUX disabled augtool -r /mnt -s rm /files/etc/chrony.conf/pool mapfile -t cockpit < <(chroot /mnt rpm -qa 'cockpit*') if [ "${#cockpit[@]}" -gt 0 ]; then chroot /mnt dnf -y -q --disablerepo='*' remove "${cockpit[@]}" fi [ -z "$(chroot /mnt rpm -qa 'cockpit*')" ] || die "cockpit toujours installé" rm -rf /mnt/run/cockpit