summarylogtreecommitdiffstats
path: root/random_machine_id.sh
blob: c4d5c1c5a5ada40910da7e373ab21751df835644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

VERSION=20230729.01

set -e # Abort on errors, so that a failing cd does not mess up elsewhere.

while [ "$#" -ge 1 ]; do
  case "$1" in
    '-V'|'--version')
      printf '%s\n' "${VERSION}"
      exit 0
    ;;
    '-h'|'--help')
      printf '%s\n' "See 'cat $0' for what this script does ;-)."
      exit 0
    ;;
  esac
  shift
done


### The idea for the following is taken from https://forum.artixlinux.org/index.php/topic,1547.msg10599.html#msg10599:

if [ -e /etc/machine-id ]; then
  if [ -e /etc/machine-id.prev ]; then
    rm -f /etc/machine-id.prev
  fi
  cp /etc/machine-id /etc/machine-id.prev # Create a backup
  rm -f /etc/machine-id
fi
dbus-uuidgen --ensure=/etc/machine-id

if [ -d /var/lib/dbus ]; then
  if [ -e /var/lib/dbus/machine-id ]; then
    if [ -e /var/lib/dbus/machine-id.prev ]; then
      rm -f /var/lib/dbus/machine-id.prev
    fi
    cp /var/lib/dbus/machine-id /var/lib/dbus/machine-id.prev # Create a backup
    rm -f /var/lib/dbus/machine-id
  fi
  ln -s /etc/machine-id /var/lib/dbus/machine-id
fi