forgot to attach last time :-)
On Tue, Oct 11, 2005 at 07:50:11PM +0000, Anand Avati wrote:
> hi,
> attached is a bmc-autconfig script which asks for ip/netmask/gateway in a
> wizard style and calls bmc-config to --commit them.
>
> regards,
> avati
> _______________________________________________
> Freeipmi-devel mailing list
> [email protected]
> http://lists.gnu.org/mailman/listinfo/freeipmi-devel
---end quoted text---
#!/bin/sh
_init ()
{
# autotool'ize these two?
TEMPLATE_DIR="/var/lib/freeipmi";
TEMPLATE="${TEMPLATE_DIR}/bmc-config-template";
PROG=$(which dialog 2>/dev/null || which whiptail 2>/dev/null);
BMC_CONFIG=$(which bmc-config 2>/dev/null) || {
echo "bmc-config not found, fatal!";
return 1;
}
exec 3>&1
ip="0.0.0.0";
nm="0.0.0.0";
gw="0.0.0.0";
return 0;
}
show_message ()
{
[ -z "${PROG}" ] && {
echo "${1}";
read;
return;
}
${PROG} --title "BMC Auto Config" --msgbox "${1}" 0 0 >&3;
return;
}
get_input ()
{
local input;
[ -z "${PROG}" ] && {
echo -n "${1}";
read input;
echo "${input}";
return;
}
${PROG} --title "BMC Auto Config" --inputbox "$1" 0 0 "$2" 2>&1 >&3;
}
validate_ip_address ()
{
local quad;
local oldIFS;
quad=${1}
echo "${oct}" | grep -Eq "^[0-9\.]+$" || {
echo "ERROR: Input cannot have non-numericals";
return 1;
}
oldIFS=${IFS};
IFS=.
set -- ${quad};
IFS=${oldIFS};
if [ "$#" -ne "4" ]; then
echo "ERROR: IP Address needs 4 octets";
return 1;
fi
for oct in $*;
do
if [ "${oct}" -lt "0" -o "${oct}" -gt "255" ]; then
echo "ERROR: Input octets should be between 0 - 255";
return 1
fi
done
return 0
}
get_ip_address ()
{
get_input "Enter BMC IP Address: " "${ip}";
}
get_netmask ()
{
get_input "Enter BMC Netmask: " "${nm}";
}
get_gateway_ip_address ()
{
get_input "Enter BMC Gateway: " "${gw}";
}
accept_input ()
{
iput_func=$1;
valid_func=$2;
local err;
local input;
input=$(${iput_func}) || return 1;
while ! err=$(${valid_func} ${input})
do
show_message "${err}";
input=$(${iput_func}) || return 1;
done
echo ${input};
return 0;
}
main ()
{
ip=$(accept_input get_ip_address validate_ip_address) &&
nm=$(accept_input get_netmask validate_ip_address) &&
gw=$(accept_input get_gateway_ip_address validate_ip_address) && {
${BMC_CONFIG} --commit -f "${TEMPLATE}";
${BMC_CONFIG} --commit -k "Lan_Conf:IP_Address=${ip}";
${BMC_CONFIG} --commit -k "Lan_Conf:Subnet_Mask=${nm}";
${BMC_CONFIG} --commit -k "Lan_Conf:Default_Gateway_IP_Address=${gw}";
}
}
_init "$@" && main "$@";
_______________________________________________
Freeipmi-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/freeipmi-devel