root / example / hooks / hostname @ d129fd5f
History | View | Annotate | Download (1.2 kB)
1 |
#!/bin/bash |
---|---|
2 |
|
3 |
set -e |
4 |
. common.sh |
5 |
|
6 |
debug set -x |
7 |
|
8 |
CLEANUP=( ) |
9 |
|
10 |
trap cleanup EXIT |
11 |
|
12 |
if [ -z "${HOSTNAME}" ] ; then |
13 |
log_error "Missing hostname" |
14 |
exit 1 |
15 |
fi |
16 |
|
17 |
if [ -z "${TARGET}" -o ! -d "${TARGET}" ] ; then |
18 |
log_error "Missing target directory" |
19 |
exit 1 |
20 |
fi |
21 |
|
22 |
get_os_type $TARGET |
23 |
|
24 |
case "${OS_TYPE}" in |
25 |
debian) |
26 |
echo $HOSTNAME > ${TARGET}/etc/hostname |
27 |
;; |
28 |
redhat) |
29 |
sed -ie "s/HOSTNAME=.*$/HOSTNAME=$HOSTNAME/g" ${TARGET}/etc/sysconfig/network |
30 |
|
31 |
;; |
32 |
slackware|suse) |
33 |
#local domain=$(sed -e 's/^[^\.]*//g' < /etc/HOSTNAME) |
34 |
|
35 |
# In slackware hostname and domain name are joined together. For now I |
36 |
# will not retain the domain name. |
37 |
|
38 |
echo $HOSTNAME > ${TARGET}/etc/HOSTNAME |
39 |
;; |
40 |
gentoo) |
41 |
sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"${instance}\"/" ${TARGET}/etc/conf.d/hostname |
42 |
;; |
43 |
esac |
44 |
|
45 |
# Some Linux distributions assign the hostname to 127.0.1.1 in order to be |
46 |
# resolvable to an IP address. Lets replace this if found in /etc/hosts |
47 |
sed -ie "s/^[[:blank:]]*127\.0\.1\.1[[:blank:]].\+$/127.0.1.1\t${instance}/" ${TARGET}/etc/hosts |
48 |
|
49 |
# execute cleanups |
50 |
cleanup |
51 |
trap - EXIT |
52 |
|
53 |
exit 0 |