#!/bin/bash

LOCAL=/etc/machine-id
CONFIG=/config/uid
if [ -f "$LOCAL" ]; then
    echo "machine-id exist."
else
    echo "machine-id does not exist."
    if [ -f "$CONFIG" ]; then
        echo "coying $CONFIG to $LOCAL..."
        cp $CONFIG $LOCAL
        dbus-uuidgen --ensure
    else
        echo "$CONFIG does not exist, generating new machine-id..."
        dbus-uuidgen --ensure=$LOCAL
        dbus-uuidgen --ensure
        cp $LOCAL $CONFIG
    fi
fi

exec "$@"
