]>
Commit | Line | Data |
---|---|---|
cfeaec54 CALP |
1 | #!/bin/sh |
2 | set -e | |
3 | # The hostname and hostid of the last system to access a ZFS pool are stored in | |
4 | # the ZFS pool itself. A pool is foreign if, during `zpool import`, the | |
5 | # current hostname and hostid are different than the stored values thereof. | |
6 | # | |
7 | # The hostid on Solaris is intrinsic, but is not on Linux (see #595790), so the | |
8 | # spl kernel module invokes /usr/bin/hostid from the userland in its initialization | |
9 | # routine. | |
10 | # | |
11 | # /usr/bin/hostid will return the 4 first bytes of the file /etc/hostid. | |
12 | # If this file is not present or contains less than 4 bytes, then /usr/bin/hostid | |
13 | # will return the bytes of the IP address of $(hostname) flipped, or zero if | |
14 | # such IP couldn't be obtained | |
15 | # | |
16 | # This means that things like a DHCP lease change can affect the hostid. | |
17 | # | |
18 | # Therefore the only way of having a stable hostid is to define it on /etc/hostid. | |
19 | # This postinst helper will check if we already have the hostid stabilized by | |
20 | # checking the existence of the file /etc/hostid to be 4 bytes at least. | |
21 | # If this file don't already exists on our system or has less than 4 bytes, then | |
22 | # we will stabilize our current hostid by writing its value to /etc/hostid | |
23 | ||
c932eac9 AX |
24 | # Detect if /etc/hostid is a conffile of previous spl package, migrate if yes |
25 | # hostid file should preserve even when package is purged | |
26 | if $(dpkg-query --showformat='${Conffiles}\n' --show spl >/dev/null 2>&1); then | |
27 | dpkg-maintscript-helper rm_conffile /etc/hostid -- "$@" | |
28 | fi | |
29 | ||
cfeaec54 CALP |
30 | if [ ! -f /etc/hostid ] || [ $(stat -c %s /etc/hostid) -lt 4 ] ; then |
31 | ||
32 | # Write our current hostid to /etc/hostid | |
33 | HOSTID=$(hostid) | |
34 | AA=$(echo $HOSTID | cut -b 1,2) | |
35 | BB=$(echo $HOSTID | cut -b 3,4) | |
36 | CC=$(echo $HOSTID | cut -b 5,6) | |
37 | DD=$(echo $HOSTID | cut -b 7,8) | |
38 | ||
39 | # Big Endian | |
c932eac9 | 40 | if [ $(echo -n I | od -to2 | awk 'FNR==1{ print substr($2,6,1)}' 2>/dev/null) = 0 ]; then |
7f4ae0c7 AX |
41 | # Invoke the printf from coreutils. shell builtin lacks the byte format. |
42 | /usr/bin/printf "\x$AA\x$BB\x$CC\x$DD" >/etc/hostid | |
cfeaec54 CALP |
43 | else |
44 | # Little Endian | |
7f4ae0c7 | 45 | /usr/bin/printf "\x$DD\x$CC\x$BB\x$AA" >/etc/hostid |
cfeaec54 CALP |
46 | fi |
47 | fi | |
0fbe1fc0 DH |
48 | |
49 | #DEBHELPER# |