xref: /OK3568_Linux_fs/kernel/tools/hv/hv_get_dhcp_info.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/bash
2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun# This example script retrieves the DHCP state of a given interface.
5*4882a593Smuzhiyun# In the interest of keeping the KVP daemon code free of distro specific
6*4882a593Smuzhiyun# information; the kvp daemon code invokes this external script to gather
7*4882a593Smuzhiyun# DHCP setting for the specific interface.
8*4882a593Smuzhiyun#
9*4882a593Smuzhiyun# Input: Name of the interface
10*4882a593Smuzhiyun#
11*4882a593Smuzhiyun# Output: The script prints the string "Enabled" to stdout to indicate
12*4882a593Smuzhiyun#	that DHCP is enabled on the interface. If DHCP is not enabled,
13*4882a593Smuzhiyun#	the script prints the string "Disabled" to stdout.
14*4882a593Smuzhiyun#
15*4882a593Smuzhiyun# Each Distro is expected to implement this script in a distro specific
16*4882a593Smuzhiyun# fashion. For instance, on Distros that ship with Network Manager enabled,
17*4882a593Smuzhiyun# this script can be based on the Network Manager APIs for retrieving DHCP
18*4882a593Smuzhiyun# information.
19*4882a593Smuzhiyun
20*4882a593Smuzhiyunif_file="/etc/sysconfig/network-scripts/ifcfg-"$1
21*4882a593Smuzhiyun
22*4882a593Smuzhiyundhcp=$(grep "dhcp" $if_file 2>/dev/null)
23*4882a593Smuzhiyun
24*4882a593Smuzhiyunif [ "$dhcp" != "" ];
25*4882a593Smuzhiyunthen
26*4882a593Smuzhiyunecho "Enabled"
27*4882a593Smuzhiyunelse
28*4882a593Smuzhiyunecho "Disabled"
29*4882a593Smuzhiyunfi
30