#!/bin/bash # This example script retrieves the DHCP state of a given interface. # In the interest of keeping the KVP daemon code free of distro specific # information; the kvp daemon code invokes this external script to gather # DHCP setting for the specific interface. # # Input: Name of the interface # # Output: The script prints the string "Enabled" to stdout to indicate # that DHCP is enabled on the interface. If DHCP is not enabled, # the script prints the string "Disabled" to stdout. # # Each Distro is expected to implement this script in a distro specific # fashion. For instance on Distros that ship with Network Manager enabled, # this script can be based on the Network Manager APIs for retrieving DHCP # information. global if_file := ""/etc/sysconfig/network-scripts/ifcfg-"$1" global dhcp := $[grep "dhcp" $if_file !2 >/dev/null] if test $dhcp != "" { echo "Enabled" } else { echo "Disabled" } (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:if_file) op: Equal rhs: {(DQ (/etc/sysconfig/network-scripts/ifcfg-)) ($ VSub_Number "$1")} spids: [50] ) ] spids: [50] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dhcp) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(grep)} {(DQ (dhcp))} {($ VSub_Name "$if_file")}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[67])] ) ] ) left_token: spids: [58 69] ) } spids: [57] ) ] spids: [57] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$dhcp"))} {(KW_Bang "!") (Lit_Other "=")} {(DQ )} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(echo)} {(DQ (Enabled))})] spids: [-1 89] ) ] else_action: [(C {(echo)} {(DQ (Disabled))})] spids: [97 105] ) ] )