[1c48007] | 1 | #!/bin/sh
|
---|
| 2 | ########################################################################
|
---|
[c2db087] | 3 | # Begin /sbin/ifdown
|
---|
[1c48007] | 4 | #
|
---|
| 5 | # Description : Interface Up
|
---|
| 6 | #
|
---|
[c2db087] | 7 | # Authors : DJ Lucas - dj@linuxfromscratch.org
|
---|
[1c48007] | 8 | #
|
---|
[c2db087] | 9 | # Version : 00.02
|
---|
[1c48007] | 10 | #
|
---|
| 11 | ########################################################################
|
---|
| 12 |
|
---|
[c2db087] | 13 | . /lib/lsb/init-functions
|
---|
[1c48007] | 14 |
|
---|
[c2db087] | 15 | function get_args()
|
---|
| 16 | {
|
---|
| 17 | if test -z "${1}" ; then
|
---|
| 18 | showhelp
|
---|
| 19 | exit 1
|
---|
| 20 | fi
|
---|
[1c48007] | 21 |
|
---|
[c2db087] | 22 | while test -n "${1}" ; do
|
---|
| 23 | case "${1}" in
|
---|
| 24 | -c | --configfile)
|
---|
| 25 | check_arg $1 $2
|
---|
| 26 | CONFIGFILE="${2}"
|
---|
| 27 | shift 2
|
---|
| 28 | ;;
|
---|
| 29 | eth* | iw* | wlan*)
|
---|
| 30 | INTERFACE="${1}"
|
---|
| 31 | shift 1
|
---|
| 32 | ;;
|
---|
| 33 | -h | --help)
|
---|
| 34 | showhelp
|
---|
| 35 | exit 0
|
---|
| 36 | ;;
|
---|
| 37 | *)
|
---|
| 38 | showhelp
|
---|
| 39 | echo "ERROR: '${1}' unknown argument"
|
---|
| 40 | echo ""
|
---|
| 41 | exit 2
|
---|
| 42 | ;;
|
---|
| 43 | esac
|
---|
| 44 | done
|
---|
| 45 | }
|
---|
[1c48007] | 46 |
|
---|
[c2db087] | 47 | function check_arg()
|
---|
| 48 | {
|
---|
| 49 | echo "${2}" | grep -v "^-" > /dev/null
|
---|
| 50 | if [ -z "${?}" -o ! -n "${2}" ]; then
|
---|
| 51 | echo "Error: ${1} requires a valid argument."
|
---|
| 52 | exit 2
|
---|
| 53 | fi
|
---|
| 54 | }
|
---|
[1c48007] | 55 |
|
---|
[c2db087] | 56 | function showhelp()
|
---|
| 57 | {
|
---|
| 58 | echo "`/usr/bin/basename ${0}` brings up a valid network interface."
|
---|
| 59 | echo ""
|
---|
| 60 | echo "Options:"
|
---|
| 61 | echo " -c --configfile The path to an interface configuration file"
|
---|
| 62 | echo " If no configuration file is given, all files"
|
---|
| 63 | echo " listed in ${NETWORK_DEVICES}/ifconfig.<int> will"
|
---|
| 64 | echo " be processed, regarless of the value of ONBOOT"
|
---|
| 65 | echo " -h --help Show this help message and exit."
|
---|
| 66 | echo ""
|
---|
| 67 | echo "Examples:"
|
---|
| 68 | echo " `/usr/bin/basename ${0}` eth0 -c ${NETWORK_DEVICES}/ifconfig.eth0/ipv4"
|
---|
| 69 | echo " `/usr/bin/basename ${0}` eth0"
|
---|
| 70 | echo ""
|
---|
| 71 | echo ""
|
---|
| 72 | }
|
---|
[1c48007] | 73 |
|
---|
[c2db087] | 74 | # Intialize empty variables so that the shell does not polute the script
|
---|
| 75 | CONFIGFILE=""
|
---|
| 76 | CONFIGDIR=""
|
---|
| 77 | INTERFACE=""
|
---|
| 78 |
|
---|
| 79 | # Process command line arguments
|
---|
| 80 | get_args ${@}
|
---|
[1c48007] | 81 |
|
---|
[c2db087] | 82 | # Handle common errors - No need to account for bootscripts, this should not
|
---|
| 83 | # happen during boot or shutdown.
|
---|
| 84 | if [ "${CONFIGFILE}x" != "x" -a ! -f "${CONFIGFILE}" ]; then
|
---|
| 85 | echo "ERROR: ${CONFIGFILE} is not a valid network configuration file."
|
---|
| 86 | echo ""
|
---|
| 87 | exit 2
|
---|
| 88 | fi
|
---|
| 89 |
|
---|
| 90 | if [ "${INTERFACE}x" == "x" ]; then
|
---|
| 91 | echo "ERROR: No interface was given"
|
---|
| 92 | echo ""
|
---|
| 93 | exit 2
|
---|
| 94 | else
|
---|
| 95 | if ! grep "${INTERFACE}" /proc/net/dev 2>&1 > /dev/null; then
|
---|
| 96 | echo "ERROR: ${INTERFACE} is not a valid network interface."
|
---|
| 97 | echo ""
|
---|
| 98 | exit 2
|
---|
| 99 | fi
|
---|
| 100 | fi
|
---|
| 101 |
|
---|
| 102 | # If a configuration file is present, use it
|
---|
| 103 | if [ "${CONFIGFILE}x" != "x" ]; then
|
---|
| 104 | . "${CONFIGFILE}"
|
---|
| 105 | if [ -x "/lib/network-services/${SERVICE}" ]; then
|
---|
| 106 | # do the work
|
---|
| 107 | # Check to make sure the interface is up
|
---|
| 108 | link_status=`/sbin/ip link show "${INTERFACE}" | \
|
---|
| 109 | grep -o "state UP"`
|
---|
| 110 | if [ "${link_status}" != "state UP" ]; then
|
---|
| 111 | message="Bringing up the ${INTERFACE} interface..."
|
---|
| 112 | /sbin/ip link set ${INTERFACE} up
|
---|
| 113 | evaluate_retval standard
|
---|
[1c48007] | 114 | fi
|
---|
[c2db087] | 115 | if IFCONFIG=${CONFIGFILE} \
|
---|
| 116 | /lib/network-services/${SERVICE} ${INTERFACE} up; then
|
---|
| 117 | mkdir -p "/run/network/ifconfig.${INTERFACE}"
|
---|
| 118 | cp "${CONFIGFILE}" "/run/network/ifconfig.${INTERFACE}/"
|
---|
[1c48007] | 119 | fi
|
---|
[c2db087] | 120 | else
|
---|
| 121 | echo "ERROR: Service '${SERVICE}' is not a valid service."
|
---|
| 122 | echo ""
|
---|
| 123 | exit 2
|
---|
| 124 | fi
|
---|
| 125 | # No interface configuration file was given
|
---|
| 126 | else
|
---|
| 127 | # Process all available interface configuration files
|
---|
| 128 | CONFIGDIR="/etc/network/ifconfig.${INTERFACE}"
|
---|
| 129 | if [ -d "${CONFIGDIR}" ]; then
|
---|
| 130 | FILES=`ls "${CONFIGDIR}"`
|
---|
| 131 | for CONFIGFILE in ${FILES}
|
---|
| 132 | do
|
---|
| 133 | (
|
---|
| 134 | . "${CONFIGDIR}/${CONFIGFILE}"
|
---|
| 135 | if [ -x "/lib/network-services/${SERVICE}" ]; then
|
---|
| 136 | # Check to make sure the interface is up
|
---|
| 137 | link_status=`/sbin/ip link show "${INTERFACE}" | \
|
---|
| 138 | grep -o "state UP"`
|
---|
| 139 | if [ "${link_status}" != "state UP" ]; then
|
---|
| 140 | message="Bringing up the ${INTERFACE} interface..."
|
---|
| 141 | /sbin/ip link set ${INTERFACE} up
|
---|
| 142 | evaluate_retval standard
|
---|
| 143 | fi
|
---|
| 144 | if IFCONFIG="${CONFIGDIR}/${CONFIGFILE}" \
|
---|
| 145 | /lib/network-services/${SERVICE} ${INTERFACE} up; then
|
---|
| 146 | mkdir -p "/run/network/ifconfig.${INTERFACE}"
|
---|
| 147 | cp "${CONFIGDIR}/${CONFIGFILE}" \
|
---|
| 148 | "/run/network/ifconfig.${INTERFACE}/"
|
---|
[1c48007] | 149 | fi
|
---|
| 150 | else
|
---|
[c2db087] | 151 | echo "ERROR: Service '${SERVICE}' is not a valid service."
|
---|
| 152 | echo ""
|
---|
| 153 | exit 2
|
---|
[1c48007] | 154 | fi
|
---|
| 155 |
|
---|
[c2db087] | 156 | )
|
---|
| 157 | done
|
---|
| 158 | fi
|
---|
| 159 | fi
|
---|
| 160 |
|
---|