summaryrefslogtreecommitdiff
path: root/tools/hook-rhel.sh
blob: 513a55157f7eda9752324fc249df83310ade0669 (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
#!/bin/sh
# This file is part of cloud-init. See LICENSE file for license information.

# Current versions of RHEL and CentOS do not honor the directory
# /etc/dhcp/dhclient-exit-hooks.d so this file can be placed in
# /etc/dhcp/dhclient.d instead
is_azure() {
    local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
    if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
        [ "$vendor" = "Microsoft Corporation" ] && return 0
    fi
    return 1
}

is_enabled() {
    # only execute hooks if cloud-init is enabled and on azure
    [ -e /run/cloud-init/enabled ] || return 1
    is_azure
}

hook-rhel_config(){
    is_enabled || return 0
    cloud-init dhclient-hook up "$interface"
}

hook-rhel_restore(){
    is_enabled || return 0
    cloud-init dhclient-hook down "$interface"
}