]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - debian/cloud-tools/hv_get_dhcp_info
UBUNTU: [Config] CONFIG_REGULATOR_HI6421V530=m
[mirror_ubuntu-artful-kernel.git] / debian / cloud-tools / hv_get_dhcp_info
1 #!/bin/bash
2
3 # This example script retrieves the DHCP state of a given interface.
4 # In the interest of keeping the KVP daemon code free of distro specific
5 # information; the kvp daemon code invokes this external script to gather
6 # DHCP setting for the specific interface.
7 #
8 # Input: Name of the interface
9 #
10 # Output: The script prints the string "Enabled" to stdout to indicate
11 # that DHCP is enabled on the interface. If DHCP is not enabled,
12 # the script prints the string "Disabled" to stdout.
13 #
14 # Each Distro is expected to implement this script in a distro specific
15 # fashion.
16
17 #set -x
18
19 IF_FILE="/etc/network/interfaces"
20 NMCMD="nmcli"
21
22 function checknetworkmanager {
23 #Assumes if $NMCMD exists, inteface exists and interface is not
24 # in $IF_FILE then dhcp is being used by NM
25 if hash $NMCMD >/dev/null 2>&1 ; then
26 if $NMCMD dev status |grep -q $1 ; then
27 echo "Enabled"
28 else
29 echo "Disabled"
30 fi
31 else
32 #Give up
33 echo "Disabled"
34 fi
35 }
36
37 if [ -z $1 ] ; then echo "Disabled"; exit; fi
38
39 if [ -e $IF_FILE ]; then
40 if grep -v -e "^#" $IF_FILE|grep -q $1 ; then
41 #interface exists so
42 if grep -q -e $1\.\*dhcp $IF_FILE; then
43 echo "Enabled"; exit;
44 else
45 echo "Disabled"; exit;
46 fi
47 else
48 checknetworkmanager $1
49 exit
50 fi
51 else
52 checknetworkmanager $1
53 exit
54 fi
55