Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 13759 Details for
Bug 23363
New ebuild: Netprofiles Interface Management System 0.1.0134 (Initial Release)
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Netprofiles IMS card management utility.
netprofiles (text/plain), 12.46 KB, created by
Curtis Hogg
on 2003-06-24 02:45:20 UTC
(
hide
)
Description:
Netprofiles IMS card management utility.
Filename:
MIME Type:
Creator:
Curtis Hogg
Created:
2003-06-24 02:45:20 UTC
Size:
12.46 KB
patch
obsolete
>#!/bin/bash ># >#netprofiles: A script for selecting profiles for ethernet cards, ># and configuring based on those profiles. ># >### Author and program information ### >AUTHOR="buckminst" >AUTHOR_EMAIL="buckminst@inconnu.isu.edu" >VERSION=0.1 >BUILD=0133 > >### Configuration variables ### >CONFIG_DIR=/etc/conf.d >CONFIG_FILE=${CONFIG_DIR}/netprofiles >STATE_DIR=/var/state/netprofiles >USE_DEFAULT_PROFILE=0 >VERBOSE=1 >NEW_VERBOSE=1 > >### External function including ### >source /etc/init.d/functions.sh > >### Functions ### >vecho () { > if [ $VERBOSE -ge $1 ]; then > echo "$2" > fi >} > >vechon () { > if [ $VERBOSE -ge $1 ]; then > echo -n "$2" > fi >} > >veinfo () { > if [ $VERBOSE -ge $1 ]; then > einfo "$2" > fi >} > >veinfon () { > if [ $VERBOSE -ge $1 ]; then > einfon "$2" > fi >} > >print_version () { > veinfo 1 "netprofiles v${VERSION}.${BUILD} by $AUTHOR (${AUTHOR_EMAIL})" >} > >print_help () { > print_version > einfo "-----------------------------------" > einfo "Usage:" > einfo " netprofiles [options] action" > echo > einfo "Options:" > einfo " -d : Automatically configures interface with" > einfo " settings from default profile (profile 1)." > einfo " -i <interface> : Interface to (de)configure." > einfo " -v <verbosity> : Set verbosity level of netprofiles." > einfo " -V : Print version information." > echo > einfo "Actions:" > einfo " start : Configures and starts up interface (-i)" > einfo " reconfigure : Reconfigures and restarts interface (-i)" > einfo " stop : Deconfigures and shuts down interface (-i)" > einfo " status : Provides status of interface (-i)" > echo > einfo "Verbosity levels:" > einfo " 0 : Only displays the most important messages" > einfo " 1 (default) : Displays info banner and everything in V0" > einfo " 2 : Displays extra status info and all in V1" > einfo " 3 : Displays debug information and all in V2" > echo >} > >print_status () { > print_version > veinfo 1 "-----------------------------------" > if [ ! -e ${STATE_DIR}/${ETHER}.state ]; then > eerror "Unable to locate ${STATE_DIR}/${ETHER}.state, aborting." > exit 1 > fi > source ${STATE_DIR}/${ETHER}.state > einfo "${ETHER} is a ${Current_Type} interface using ${Current_Mode} address assignment." > einfo "${ETHER} is currently set to profile ${Current_Profile}: ${Current_ID}" > exit 0 >} > >set_status () { > if [ ! -e ${STATE_DIR}/${ETHER}.state ]; then > echo "Current_Profile=${use_profile}" > ${STATE_DIR}/${ETHER}.state > echo "Current_ID=\"${ID}\"" >> ${STATE_DIR}/${ETHER}.state > echo "Current_Type=\"${Interface_Type}\"" >> ${STATE_DIR}/${ETHER}.state > echo "Current_Mode=\"${Interface_Mode}\"" >> ${STATE_DIR}/${ETHER}.state > echo "Current_DHCP_PID=${DHCP_PID}" >> ${STATE_DIR}/${ETHER}.state > else > eerror "Interface ${ETHER} is already configured -- " > eerror "Please use 'reconfigure' to change ${ETHER}'s profile." > exit 1 > fi >} > >start_interface () { > use_profile=$1 > veinfon 2 " -) Loading settings for $ETHER from profile ${use_profile}..." > source ${PROFILE_DIR}/${HWADDR}/${use_profile}/settings > vecho 2 " done." > veinfo 3 "${ETHER}: use_profile: ${use_profile}, ID: ${ID}" > veinfo 3 "${ETHER}: ITYPE: ${Interface_Type}, IMODE: ${Interface_Mode}" > veinfo 3 "${ETHER}: IADDR: ${Interface_Address}, IBRD: ${Interface_Broadcast}" > veinfo 3 "${ETHER}: INETMSK: ${Interface_Netmask}, IGTW: ${Interface_Gateway}" > veinfo 3 "${ETHER}: ESSID: ${Interface_ESSID}, APMODE: ${Interface_APMode}" > veinfo 3 "${ETHER}: WEPKEY: ${Interface_WEPKey}, NICK: ${Interface_Nickname}" > > if [ "$Interface_Type" == "wireless" ]; then > # Begin wireless pre-config > veinfon 2 " -) Configuring wireless card..." > iwconfig $ETHER essid $Interface_ESSID mode $Interface_APMode key $Interface_WEPKey nick $Interface_Nickname > /dev/null 2>&1 > RETVAL=$? > if [ $RETVAL -eq 0 ]; then > vecho 2 " success." > else > vecho 2 " failed." > fi > fi > > if [ "$Interface_Mode" = "dhcp" ]; then > veinfon 2 " -) Negotiating DHCP lease..." > ${DHCP_CLIENT} $ETHER > /dev/null 2>&1 > RETVAL=$? > if [ $RETVAL -eq 0 ]; then > vecho 2 " success." > else > vecho 2 " failed." > fi > else > veinfon 2 " -) Configuring $ETHER with static IP information..." > ifconfig $ETHER $Interface_Address broadcast $Interface_Broadcast netmask $Interface_Netmask up > /dev/null 2>&1 > RETVAL=$? > if [ $RETVAL -eq 0 ]; then > vecho 2 "success." > else > vecho 2 " failed." > fi > veinfon 2 " -) Setting up default route..." > route add default gw $Interface_Gateway > /dev/null 2>&1 > RETVAL=$? > if [ $RETVAL -eq 0 ]; then > vecho 2 " success." > else > vecho 2 " failed." > fi > fi > set_status > einfo "Interface ${ETHER} successfully started up." > exit 0 >} > >stop_interface () { > if [ ! -e ${STATE_DIR}/${ETHER}.state ]; then > eerror "Unable to find statefile for ${ETHER}. Either the interface was never" > eerror "brought up, or something is wrong. Try using 'start'." > exit 1 > else > source ${STATE_DIR}/${ETHER}.state > rm ${STATE_DIR}/${ETHER}.state > if [ "$Current_Mode" == "dhcp" ]; then > veinfon 1 " -) Attempting to shutdown DHCP client (pid: ${Current_DHCP_PID})..." > while ${DHCP_CLIENT} ${DHCP_STOP_FLAG} ${ETHER} &>/dev/null && [ "${count}" -lt 9 ] > do > sleep 1 > count=$((count + 1)) > done > if [ "${count}" -ge 9 ]; then > # We have ways of making you stop, DHCP... > kill -9 ${Current_DHCP_PID} > fi > vecho 1 "done." > fi > /sbin/ifconfig ${ETHER} down >/dev/null 2>&1 > RETVAL=$? > if [ $RETVAL -eq 0 ]; then > einfo "Interface ${ETHER} successfully shut down." > else > eerror "Unable to shut down interface ${ETHER}" > exit 1 > fi > fi >} > >check_dirs () { > if [ ! -d ${CONFIG_DIR} ]; then > veinfon 1 " -) Creating configuration storage directory..." > mkdir -p ${CONFIG_DIR} > vecho 1 " done." > fi > > if [ ! -d ${PROFILE_DIR} ]; then > veinfon 1 " -) Creating profile storage directory..." > mkdir -p ${PROFILE_DIR} > vecho 1 " done." > fi > > if [ ! -d ${STATE_DIR} ]; then > veinfon 1 " -) Creating interface state directory..." > mkdir -p ${STATE_DIR} > vecho 1 " done." > fi >} > >create_configuration () { > einfon " -) Creating configuration file..." > echo "PROFILE_DIR=\"/etc/netprofiles.d\"" >> ${CONFIG_FILE} > echo "# Valid modes are 'text' and 'dialog'" >> ${CONFIG_FILE} > echo "UI_MODE=\"text\"" >> ${CONFIG_FILE} > echo "DHCP_CLIENT=\"dhcpcd\"" >> ${CONFIG_FILE} > echo "TIMEOUT_VALUE=5" >> ${CONFIG_FILE} > echo "VERBOSE=0" >> ${CONFIG_FILE} > echo " done." >} > >make_profile () { > einfon " -) Creating profile ${PROFILE_NUM}..." > mkdir ${PROFILE_DIR}/${HWADDR}/${PROFILE_NUM} > CURRENT_PROFILE=${PROFILE_DIR}/${HWADDR}/${PROFILE_NUM} > echo "# Profile ${PROFILE_NUM} for ${HWADDR} generated on ${DATESTAMP}" > ${CURRENT_PROFILE}/settings > echo "ID=\"Wired DHCP Network\"" >> ${CURRENT_PROFILE}/settings > echo >> ${CURRENT_PROFILE}/settings > echo "# Valid interface types are 'wired' and 'wireless'" >> ${CURRENT_PROFILE}/settings > echo "Interface_Type=\"wired\"" >> ${CURRENT_PROFILE}/settings > echo >> ${CURRENT_PROFILE}/settings > echo "# Valid interface modes are 'dhcp' and 'static'" >> ${CURRENT_PROFILE}/settings > echo "Interface_Mode=\"dhcp\"" >> ${CURRENT_PROFILE}/settings > echo >> ${CURRENT_PROFILE}/settings > echo "# Settings used for static-mode configuration" >> ${CURRENT_PROFILE}/settings > echo "#Interface_Address=\"0.0.0.0\"" >> ${CURRENT_PROFILE}/settings > echo "#Interface_Broadcast=\"0.0.0.0\"" >> ${CURRENT_PROFILE}/settings > echo "#Interface_Netmask=\"0.0.0.0\"" >> ${CURRENT_PROFILE}/settings > echo "#Interface_Gateway=\"0.0.0.0\"" >> ${CURRENT_PROFILE}/settings > echo >> ${CURRENT_PROFILE}/settings > echo "# Settings used for wireless-type configuration" >> ${CURRENT_PROFILE}/settings > echo "#Interface_ESSID=\"\"" >> ${CURRENT_PROFILE}/settings > echo "#Interface_APMode=\"\"" >> ${CURRENT_PROFILE}/settings > echo "#Interface_WEPKey=\"\"" >> ${CURRENT_PROFILE}/settings > echo "#Interface_Nickname=\"\"" >> ${CURRENT_PROFILE}/settings > echo " done." > echo "PROFILES=${PROFILE_NUM}" > ${PROFILE_DIR}/${HWADDR}/profiles > PROFILES=${PROFILE_NUM} >} > >text_ui () { > veinfo 2 " -) Text UI starting..." > > if [ "$ACTION" == "stop" ]; then > stop_interface > exit 0 > fi > > if [ "$ACTION" == "reconfigure" ]; then > stop_interface > USE_DEFAULT_PROFILE=0 > veinfo 1 " Reconfiguring ${ETHER}..." > fi > > if [ ! -e ${STATE_DIR}/${ETHER}.state -o "$ACTION" == "reconfigure" ]; then > if [ $USE_DEFAULT_PROFILE -eq 0 ]; then > einfo " Select a networking profile --" > for ((foo=1; foo < (${PROFILES} + 1); foo++)); do > source ${PROFILE_DIR}/${HWADDR}/${foo}/settings > einfo " $foo : $ID" > done > einfo " 0 : Leave unconfigured." > einfon " Enter selection number, then press Enter (Default: [1]): " > read -t $TIMEOUT_VALUE PROFILE_NUMBER > RETVAL=$? > > if [ $RETVAL -eq 1 ]; then > echo > PROFILE_NUMBER=1 > fi > > if [ -z ${PROFILE_NUMBER} ]; then > PROFILE_NUMBER=1 > fi > > if [ ${PROFILE_NUMBER} -eq 0 ]; then > eerror " Not configuring interface ${ETHER} at this time, exiting..." > exit 1 > fi > else > PROFILE_NUMBER=1 > einfo "Configuring $ETHER using default profile (1)..."; > fi > > start_interface ${PROFILE_NUMBER} > else > eerror "Interface ${ETHER} is already configured -- " > eerror "Please use 'reconfigure' to change ${ETHER}'s profile." > exit 1 > fi >} > >dialog_ui () { > veinfo 1 " -) Dialog UI not implemented at this time" ># TEMPFILE=`mktemp -q /tmp/netprofiles.XXXXXXXXXX` ># BLAH=`echo $(for ((foo=1; foo < (${PROFILES} + 1); foo++)); do source ${PROFILE_DIR}/${HWADDR}/${foo}/settings; echo -n "$foo $(echo "${ID}" | sed s/\ /_/g) "; done)` ># dialog --backtitle "netprofiles v${VERSION}.${BUILD} by $AUTHOR (${AUTHOR_EMAIL})" --timeout $TIMEOUT_VALUE --title "Select a networking profile" --menu "Use [UP], [DOWN], [ENTER] to select." 20 60 0 $BLAH 2>${TEMPFILE} ># ># RETVAL=$? > ># SELECTED_PROFILE=$(cat ${TEMPFILE}) ># rm -f ${TEMPFILE} > ># if [ $RETVAL -eq 1 ]; then ># echo " -) Not configuring interface at this time, exiting..." ># exit 1 ># fi > ># if [ $RETVAL -eq 255 ]; then ># SELECTED_PROFILE="1" ># fi ># if [ $VERBOSE -eq 1 ]; then ># echo " -) Setting up for profile ${SELECTED_PROFILE}..." ># fi ># setup_profile ${SELECTED_PROFILE} ># >} > >### Command-line option parsing ### >while getopts "di:v:V" Option >do > case $Option in > d ) USE_DEFAULT_PROFILE=1 ;; > i ) ETHER=$OPTARG ;; > v ) VERBOSE=$OPTARG ; NEW_VERBOSE=$OPTARG ;; > V ) VERBOSE=1 ; print_version ; echo ; exit 1;; > * ) VERBOSE=1 ; print_help ; exit 1 ;; > esac >done >shift $(($OPTIND - 1)) > >if [ -z $ETHER ]; then > print_help > exit 1 >fi > >ACTION=$1 > >if [ -z $ACTION ]; then > print_help > exit 1 >fi > >case $ACTION in > start ) ;; # OK > stop ) ;; # OK > status ) print_status ; exit 0 ;; # OK > reconfigure ) ;; # OK > * ) print_help ; exit 1 ;; # NOT OK >esac > >### Main processing ### >grep -q $ETHER /proc/net/dev >RETVAL=$? > >if [ $RETVAL -eq 1 ]; then > eerror "netprofiles: ${ETHER}: Interface not found." > exit 1 >fi > >HWADDR=`echo $(ifconfig $ETHER | head -n1 | cut -d r -f 3 | sed s/":"//g)` >DATESTAMP=$(date) > >print_version >veinfo 1 "-----------------------------------" >check_dirs >if [ -e /etc/conf.d/netprofiles ]; then > veinfon 2 " -) Reading configuration file..." > source /etc/conf.d/netprofiles > if [ $VERBOSE -ne $NEW_VERBOSE ]; then > VERBOSE=$NEW_VERBOSE > fi > vecho 2 " done." >else > create_configuration > source /etc/conf.d/netprofiles >fi > >veinfo 2 "-----------------------------------" >veinfo 2 "Profile directory: ${PROFILE_DIR}" >veinfo 2 "-----------------------------------" >veinfo 2 "Beginning profile selection for ${HWADDR}..." >veinfo 2 " 1) Checking for existing profile set..." > >if [ ! -e ${PROFILE_DIR}/${HWADDR} ]; then > echo > veinfo 1 " -) Creating profile directory..." > mkdir -p ${PROFILE_DIR}/${HWADDR} > echo "PROFILES=0" > ${PROFILE_DIR}/${HWADDR}/profiles > source ${PROFILE_DIR}/${HWADDR}/profiles > PROFILE_NUM=$(($PROFILES + 1)) > make_profile >else > source ${PROFILE_DIR}/${HWADDR}/profiles >fi > >veinfo 2 " -) ${PROFILES} profile(s) found." >veinfo 2 " 2) Starting up UI..." > >if [ "$UI_MODE" == "text" ]; then > text_ui >fi > >if [ "$UI_MODE" == "dialog" ]; then > dialog_ui >fi > >exit 0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 23363
:
13758
| 13759 |
13760