Files
gitea-token-access/.entire/generate-device-id.sh
delta-cloud-208e 7cb2c66f11 chore: add Entire CLI, .claude config, CLAUDE.md auto-generation
Enable auto-commit tracking, git-sync hooks, session recovery,
and anonymous identity for the new repo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 14:51:46 +00:00

82 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# =============================================================================
# generate-device-id.sh — Generate anonymous device nickname for git commits
#
# Creates a persistent device identity like "phantom-fox-a3b2" that:
# - Hides real username, hostname, and IP
# - Stays the same across sessions on the same machine
# - Is unique per device (based on hardware ID hash)
# =============================================================================
set -euo pipefail
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/entire"
DEVICE_ID_FILE="$CONFIG_DIR/device-id"
# If already generated, just output it
if [ -f "$DEVICE_ID_FILE" ]; then
cat "$DEVICE_ID_FILE"
exit 0
fi
# --- Generate hardware fingerprint ---
get_machine_id() {
# Try multiple sources for a stable machine ID
if [ -f "/etc/machine-id" ]; then
cat /etc/machine-id
elif [ -f "/var/lib/dbus/machine-id" ]; then
cat /var/lib/dbus/machine-id
elif command -v ioreg &>/dev/null; then
# macOS: IOPlatformSerialNumber
ioreg -rd1 -c IOPlatformExpertDevice 2>/dev/null | grep -o '"IOPlatformSerialNumber" = "[^"]*"' | sed 's/.*= "//;s/"//'
elif command -v wmic &>/dev/null; then
# Windows
wmic csproduct get uuid 2>/dev/null | tail -1 | tr -d ' \r\n'
else
# Fallback: hostname + username hash
echo "$(hostname)$(whoami)$(date +%s)"
fi
}
# --- Word lists for readable nicknames ---
ADJECTIVES=(
phantom silent cosmic rapid swift
frozen arctic lunar solar neon
hidden shadow cipher binary quantum
iron steel chrome cobalt silver
alpha delta omega sigma theta
rogue ghost echo pulse drift
)
NOUNS=(
fox wolf hawk bear lynx
node core byte mesh grid
spark flame pulse wave beam
tower vault forge nexus axis
rover scout pilot agent proxy
cloud storm frost ember flare
)
# --- Deterministic selection from hardware ID ---
MACHINE_ID=$(get_machine_id)
if command -v sha256sum &>/dev/null; then
HASH=$(echo -n "$MACHINE_ID" | sha256sum | cut -c1-8)
elif command -v shasum &>/dev/null; then
HASH=$(echo -n "$MACHINE_ID" | shasum -a 256 | cut -c1-8)
else
HASH=$(echo -n "$MACHINE_ID" | md5sum 2>/dev/null | cut -c1-8 || echo "00000000")
fi
# Convert first 4 hex chars to indices
ADJ_IDX=$(( 16#${HASH:0:2} % ${#ADJECTIVES[@]} ))
NOUN_IDX=$(( 16#${HASH:2:2} % ${#NOUNS[@]} ))
SUFFIX="${HASH:4:4}"
DEVICE_NAME="${ADJECTIVES[$ADJ_IDX]}-${NOUNS[$NOUN_IDX]}-${SUFFIX}"
# --- Persist ---
mkdir -p "$CONFIG_DIR"
echo "$DEVICE_NAME" > "$DEVICE_ID_FILE"
echo "$DEVICE_NAME"