Skip to content

Instantly share code, notes, and snippets.

@JChristensen
Created January 9, 2023 00:52
Show Gist options
  • Save JChristensen/b416015220b617d4e137ccc1cb4e2ac6 to your computer and use it in GitHub Desktop.
Save JChristensen/b416015220b617d4e137ccc1cb4e2ac6 to your computer and use it in GitHub Desktop.
Script to generate unique machine ID for Linux Mint.
#!/bin/bash
# Regenerate /etc/machine-id and delete IPv6 lease information.
# Use this script to ensure unique machine IDs on each machine
# after installing Linux Mint.
# See https://github.com/linuxmint/linuxmint/issues/126
# and https://github.com/linuxmint/linuxmint/issues/361
#
# Copyright (C) 2019-2023 by Jack Christensen and licensed under
# GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
#
# J.Christensen 02May2019
usage()
{
PROGNAME=$(basename $0)
echo "usage: sudo $PROGNAME" >&2
return
}
# ensure we're root (sudo)
ROOT_UID=0
if [[ $UID != $ROOT_UID ]]; then
echo "This script must be run with sudo."
usage
echo "Current machine ID: $(cat /etc/machine-id)"
exit 1
# ensure we have no command line arguments
elif [[ $# -ne 0 ]]; then
echo "Unexpected command line argument(s)."
usage
exit 1
else
rm -v /var/lib/NetworkManager/dhclient6-*
rm -v /etc/machine-id
systemd-machine-id-setup
read -p "Reboot now? [Y/n] "
if [[ $REPLY == "Y" ]]; then
shutdown -r now
else
echo "Script done."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment