2023-03-10 11:21:22 +01:00
|
|
|
#/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
|
2024-03-08 20:15:11 +01:00
|
|
|
local random_uuid=$(cat /proc/sys/kernel/random/uuid)
|
2023-03-10 11:21:22 +01:00
|
|
|
|
|
|
|
# Ensure destination directory
|
|
|
|
mkdir -p "$(dirname "$machine_id_file")"
|
|
|
|
|
|
|
|
# Generate SHA256 hash of data and save it to $machine_id_file
|
2024-03-08 20:15:11 +01:00
|
|
|
echo "$random_uuid" | sha256sum | cut -d ' ' -f1 > "$machine_id_file"
|
2023-03-10 11:21:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main
|