Skip to content

Instantly share code, notes, and snippets.

@gwire
Created March 30, 2026 15:50
Show Gist options
  • Select an option

  • Save gwire/af16b8d9ee81ee96fcca8f74561b620f to your computer and use it in GitHub Desktop.

Select an option

Save gwire/af16b8d9ee81ee96fcca8f74561b620f to your computer and use it in GitHub Desktop.
Generating a 10-bit id from a machine-id

NextCloud v33 requests that a "serverid" is set in the configuration - this is an integer between 0 and 1023 (ie 10-bit).

I looked at generating a stable value based on machine-id, with the hope that there would be no clash for a small number of servers.

sha256sum /etc/machine-id | head -c4 | od -An -tu2 | tr -d ' ' | awk '{print int($1) % 1024}'
  • get the first 4 hex characters from the sha256sum of the machine-id - although the SHAing is probably redundant
  • convert the input into 2 unsigned decimals, and truncate their representations into one value
  • use awk int() to render that value as a 10-bit number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment