#!/bin/sh # Network configuration script for the Pixil Operating Environment # # Usage: ./pixil-ifup # TODO: # This does some stupid stuff that only allows one device at at time # We should do more checking for gateway / nameserver that will work # across multiple interfaces # RANT: # I hate sed! CONFIG=${1} IFS=NULL [ -z "${CONFIG}" ] && { echo "usage: ./pixil-ifup " exit 1 } # We assume a default file of /usr/pixil/scripts/pixil-.conf [ -f "${CONFIG}" ] || CONFIG=/usr/pixil/scripts/pixil-${CONFIG}.conf [ -f "${CONFIG}" ] || { echo "No config '${CONFIG}' found" echo "Usage: ./pixil-ifup " exit 1 } # Source the main configuration file # provides HOSTNAME and GATEWAY if [ -f ./pixil-network.conf ]; then source pixil-network.conf fi # Source the config file source ${CONFIG} # Verify that the device actually exists /sbin/ifconfig ${DEVICE} 2>&1 | grep -s "not found" > /dev/null if [ "$?" = "0" ]; then echo "Device ${DEVICE} is not available. Delaying initialization..." exit 1 fi # Make sure it is down if /sbin/ifconfig ${DEVICE} 2>/dev/null | grep " UP " >/dev/null 2>&1; then echo "Device ${DEVICE} is already started....." exit 1 fi # Ok, so now the fun stuff if [ "${PROTO}" = dynamic ]; then PUMPARGS= if [ -n "HOSTNAME" ]; then PUMPARGS="${PUMPARGS} -h ${HOSTNAME}" else PUMPARGS="${PUMPARGS} --lookup-hostname" fi if [ ! -x /sbin/pump ]; then echo "You don't have pump installed!" exit 1 fi # Run the pump echo -n "Bringing up ${DEVICE}..." #if ! /sbin/dhcpcd -n ${DEVICE}; then # echo "error" # exit 1 #else # echo "done" #fi if [ ! -x "/sbin/pump ${PUMPARGS} -i ${DEVICE}" ]; then echo "error /sbin/pump ${PUMPARGS} -i ${DEVICE}" exit 1 else echo "done" fi else # static # We need at least a IP address if [ -z "${IPADDR}" ]; then echo "No ip address was specified. Bye!" exit 1 fi # We can calculate the rest of the required functions if [ -z "${NETMASK}" ]; then eval `/bin/ipcalc --netmask ${IPADDR}` fi if [ -z "${BROADCAST}" ]; then eval `/bin/ipcalc --broadcast ${IPADDR} ${NETMASK}` fi if [ -z "${NETWORK}" ]; then eval `/bin/ipcalc --network ${IPADDR} ${NETMASK}` fi # Other flags make be required here /sbin/ifconfig ${DEVICE} ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST} # Go ahead and construct all of the routes /sbin/route add -net ${NETWORK} netmask ${NETMASK} dev ${DEVICE} # If there is no specified gateway, then add it # TODO: Remove the previous one that is there???? if ! /sbin/route -n 2>/dev/null | grep " UG " >/dev/null 2>&1; then if [ -n "${GATEWAY}" ]; then /sbin/route add default gw ${GATEWAY} dev ${DEVICE} fi fi # Make a new nameserver file # This is only possible because we have one interface. Otherwise, we # have a whole world of hurt here if [ -n "${NAMESERVER1}" ]; then if [ -f /etc/resolv.conf ]; then cp /etc/resolv.conf /etc/resolv.conf.backup-${DEVICE} fi echo "" > /etc/resolv.conf if [ -n "${DOMAIN}" ]; then echo "search ${DOMAIN}" >> /etc/resolv.conf fi if [ -n "${NAMESERVER1}" ]; then echo "nameserver ${NAMESERVER1}" >> /etc/resolv.conf fi if [ -n "${NAMESERVER2}" ]; then echo "nameserver ${NAMESERVER2}" >> /etc/resolve.conf fi fi fi # If we don't want to set any wireless settings, # then leave quietly if [ ! -n "${ESSID}" ] && [ ! -n "${WEPID}" ]; then echo "No ESSID or WEPID key." exit 0 fi if [ ! -x /sbin/iwconfig ]; then echo "/sbin/iwconfig not found." exit 1 fi if /sbin/iwconfig ${DEVICE} 2>&1 | grep "no wireless extensions" >/dev/null 2>&1; then echo "No wireless available for ${DEVICE}" exit 1 fi IWCONFIG_ARGS= if [ -n "${ESSID}" ]; then echo -n "setting essid to ${ESSID}..." IWCONFIG_ARGS="/sbin/iwconfig ${DEVICE} essid \"${ESSID}\"" echo "done." fi if [ -n "${IWCONFIG_ARGS}" ]; then echo "${IWCONFIG_ARGS}" ${IWCONFIG_ARGS} fi exit 0