Statistics
| Branch: | Revision:

root / example / hooks / linux / hostname @ 8d77389f

History | View | Annotate | Download (968 Bytes)

1
#!/bin/bash
2

    
3
set -e 
4
. common.sh
5
. common_linux.sh
6

    
7
debug set -x
8

    
9
CLEANUP=( )
10

    
11
trap cleanup EXIT
12

    
13
if [ -z "${HOSTNAME}" ] ; then
14
    log_error "Missing hostname"
15
    exit 1
16
fi
17

    
18
if [ -z "${TARGET}" -o ! -d "${TARGET}" ] ; then
19
    log_error "Missing target directory"
20
    exit 1
21
fi
22

    
23
get_os_type $TARGET
24

    
25
case "${OS_TYPE}" in
26
    debian)
27
        echo $HOSTNAME > ${TARGET}/etc/hostname
28
        ;;
29
    redhat)
30
        sed -ie "s/HOSTNAME=.*$/HOSTNAME=$HOSTNAME/g" ${TARGET}/etc/sysconfig/network
31

    
32
        ;;
33
    slackware|suse)
34
        #local domain=$(sed -e 's/^[^\.]*//g' < /etc/HOSTNAME)
35
        
36
        # In slackware hostname and domain name are joined together. For now I
37
        # will not retain the domain name.
38
        
39
        echo $HOSTNAME > ${TARGET}/etc/HOSTNAME
40
        ;;
41
    gentoo)
42
        sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"${instance}\"/" ${TARGET}/etc/conf.d/hostname
43
        ;;
44
esac
45

    
46
# execute cleanups
47
cleanup
48
trap - EXIT
49

    
50
exit 0