-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset-host-machine-id.sh
executable file
·55 lines (47 loc) · 1.42 KB
/
reset-host-machine-id.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
if [ $(id -u) -ne "0" ]; then
echo "WARNING: This script requires root access!"
exit 1
fi
TRIGGER_FILE="/RESET-HOST-MACHINE-ID"
SCRIPT_PATH="/usr/local/sbin/reset-host-machine-id.sh"
SERVICE_NAME="reset-host-machine-id.service"
SERVICE_PATH="/etc/systemd/system/${SERVICE_NAME}"
SCRIPT=$( readlink -m $( type -p "${0}" ))
install_serv() {
if [ "${SCRIPT_PATH}" != "${SCRIPT}" ]; then
cp "${SCRIPT}" "${SCRIPT_PATH}"
rm -rf "${SCRIPT}"
chown root:root "${SCRIPT_PATH}"
chmod 0700 "${SCRIPT_PATH}"
fi
echo "[Unit]
Description=Reset hostname and machine ID on system start if required
Wants=basic.target
After=basic.target dbus-org.freedesktop.hostname1.service systemd-hostnamed.service
[Service]
Type=notify
ExecStart=${SCRIPT_PATH}
[Install]
WantedBy=multi-user.target" > "${SERVICE_PATH}"
systemctl daemon-reload
systemctl enable "${SERVICE_NAME}"
if [ "${1}" = "prep" ]; then
touch "${TRIGGER_FILE}"
poweroff
fi
}
if [ "${1}" = "install" -o "${1}" = "prep" ]; then
install_serv "${1}"
exit 0
fi
if [ -f "${TRIGGER_FILE}" ]; then
rm -rf "${TRIGGER_FILE}"
rm -rf /etc/ssh/ssh_host_* /etc/sysconfig/rhn/systemid /etc/machine-id /var/lib/dbus/machine-id /etc/venv-salt-minion/pki/minion/* /etc/venv-salt-minion/minion_id 2> /dev/null
dbus-uuidgen --ensure
systemd-machine-id-setup
systemctl disable reset-host-machine-id.service
rm -rf "${SERVICE_PATH}" "${SCRIPT_PATH}"
systemctl daemon-reload
reboot
fi