2023-02-03 16:40:47 +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
|
|
|
|
local mac_addresses=$(cat /sys/class/net/*/address | uniq | sort)
|
|
|
|
local device_model=$(cat /sys/firmware/devicetree/base/model)
|
2023-03-06 13:09:32 +01:00
|
|
|
local urandom_seed=$(cat /etc/urandom.seed | sha256sum | cut -d ' ' -f1)
|
2023-02-03 16:40:47 +01:00
|
|
|
|
|
|
|
# Ensure destination directory
|
|
|
|
mkdir -p "$(dirname "$machine_id_file")"
|
|
|
|
|
|
|
|
# Generate SHA256 hash of data and save it to $machine_id_file
|
2023-03-06 13:09:32 +01:00
|
|
|
echo "$mac_adresses $device_model $urandom_seed" | sha256sum | cut -d ' ' -f1 > "$machine_id_file"
|
2023-02-03 16:40:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main
|