From 7bb2f1bfadb5d9b75de6d1c859f169aaf03d2515 Mon Sep 17 00:00:00 2001 From: mikepell Date: Fri, 20 May 2022 17:38:41 +0000 Subject: [PATCH] update to remove machine-id --- vm-dehydrate | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/vm-dehydrate b/vm-dehydrate index 7133bec..fcd01f4 100644 --- a/vm-dehydrate +++ b/vm-dehydrate @@ -7,26 +7,30 @@ echo "Removing openssh-server's host keys..." rm -vf /etc/ssh/ssh_host_* cat /dev/null > /etc/rc.local -cat << EOF >> /etc/rc.local +cat << 'EOL' | sudo tee /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. -# Make sure that the script will "exit 0" on success or any other +# Make sure that the script will "" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. - -rm -vf /root/vm-dehydrate > /dev/null - -dpkg-reconfigure openssh-server > /dev/null - +# dynamically create hostname (optional) +if hostname | grep localhost; then + hostnamectl set-hostname "$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '')" +fi +test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server +if [ ! -f /etc/machine-id ] +then + /usr/bin/systemd-machine-id-setup +fi exit 0 -EOF +EOL echo "Cleaning up /var/mail..." rm -vf /var/mail/* @@ -61,6 +65,7 @@ find /var/log -type f -exec truncate -s0 \{\} \; echo "Compacting drive..." dd if=/dev/zero of=EMPTY bs=1M > /dev/null rm -vf /root/EMPTY +fstrim -av echo "Clearing bash history..." cat /dev/null > /root/.bash_history