24 lines
605 B
Bash
24 lines
605 B
Bash
|
#/bin/sh
|
||
|
|
||
|
set -e
|
||
|
|
||
|
main() {
|
||
|
local machine_id_file="/etc/machine-id"
|
||
|
|
||
|
if [ -f "$machine_id_file" ]; then
|
||
|
echo "Machine ID already generated. Doing nothing."
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
# Accumulate data to create unique machine id
|
||
|
local mac_addresses=$(cat /sys/class/net/*/address | uniq | sort)
|
||
|
local device_uuid=$(dmidecode | grep UUID)
|
||
|
|
||
|
# Ensure destination directory
|
||
|
mkdir -p "$(dirname "$machine_id_file")"
|
||
|
|
||
|
# Generate SHA256 hash of data and save it to $machine_id_file
|
||
|
echo "$mac_adresses $device_uuid" | sha256sum | cut -d ' ' -f1 > "$machine_id_file"
|
||
|
}
|
||
|
|
||
|
main
|