1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#!/bin/sh
#******************************************************************
#ident /etc/netenv/netenv_setup Time-stamp: <03/03/31 08:47:21 bav>
#******************************************************************
# Gerd Bavendiek bav@epost.de 03-03-11
#
# If there is a variable NETENV_SCRIPT pointing to this executable
# file, netenv will source this script during boot.
#
# This is an Debian-only example. It creates an
# /etc/network/interfaces in a hopefully safe manner.
# This way non PCMCIA-NIC-users can use netenv on Debian without
# further configuration steps.
#------------------------------------------------------------------
print_action()
{
printf "netenv: %s ... " "$*"
}
print_status()
{
if [ $? -eq 0 ]; then
echo done
else
echo failed
fi
}
if ! grep Debian /etc/issue >/dev/null 2>&1; then
print_action Doing nothing, as this is obviously no Debian
echo
exit 0
fi
# Save /etc/network/interfaces if it has not been created by netenv
if grep netenv /etc/network/interfaces >/dev/null 2>&1; then
cp -p /etc/network/interfaces /etc/network/interfaces.pre-netenv
print_action /etc/network/interfaces was backuped as /etc/network/interfaces.pre-netenv
fi
print_action creating new /etc/network/interfaces
(
if [ -z "$NETENV_IFACE" ]; then
NETENV_IFACE=eth0
fi
echo "# /etc/network/interfaces autogenerated by netenv "`date`
echo "# old /etc/network/interfaces backup as /etc/network/interfaces.pre-netenv"
echo auto lo
echo iface lo inet loopback
echo auto $NETENV_IFACE
if [ "$BOOTPROTO" = "dhcp" ]; then
echo iface $NETENV_IFACE inet dhcp
else
echo iface $NETENV_IFACE inet static
echo -e "\taddress $IPADDR"
echo -e "\tnetmask $NETMASK"
echo -e "\tnetwork $NETWORK"
echo -e "\tbroadcast $BROADCAST"
echo -e "\tgateway $GATEWAY"
fi
if [ ! -z "$UP" ]; then echo -e "\tup $UP"; fi
if [ ! -z "$DOWN" ]; then echo -e "\tdown $DOWN"; fi
if [ ! -z "$WIRELESS_ESSID" ]; then echo -e "\twireless-essid $WIRELESS_ESSID"; fi
if [ ! -z "$WIRELESS_NWID" ]; then echo -e "\twireless-nwid $WIRELESS_NWID"; fi
if [ ! -z "$WIRELESS_FREQ" ]; then echo -e "\twireless-freq $WIRELESS_FREQ"; fi
if [ ! -z "$WIRELESS_CHANNEL" ]; then echo -e "\twireless-channel $WIRELESS_CHANNEL"; fi
if [ ! -z "$WIRELESS_SENS" ]; then echo -e "\twireless-sens $WIRELESS_SENS"; fi
if [ ! -z "$WIRELESS_MODE" ]; then echo -e "\twireless-mode $WIRELESS_MODE"; fi
if [ ! -z "$WIRELESS_AP" ]; then echo -e "\twireless-ap $WIRELESS_AP"; fi
if [ ! -z "$WIRELESS_NICK" ]; then echo -e "\twireless-nick $WIRELESS_NICK"; fi
if [ ! -z "$WIRELESS_RATE" ]; then echo -e "\twireless-rate $WIRELESS_RATE"; fi
if [ ! -z "$WIRELESS_RTS" ]; then echo -e "\twireless-rts $WIRELESS_RTS"; fi
if [ ! -z "$WIRELESS_FRAG" ]; then echo -e "\twireless-frag $WIRELESS_FRAG"; fi
if [ ! -z "$WIRELESS_TXPOWER" ]; then echo -e "\twireless-txpower $WIRELESS_TXPOWER"; fi
if [ ! -z "$WIRELESS_ENC" ]; then echo -e "\twireless-enc $WIRELESS_ENC"; fi
if [ ! -z "$WIRELESS_KEY" ]; then echo -e "\twireless-key $WIRELESS_KEY"; fi
if [ ! -z "$WIRELESS_KEYMODE" ]; then echo -e "\twireless-keymode $WIRELESS_KEYMODE"; fi
if [ ! -z "$WIRELESS_POWER" ]; then echo -e "\twireless-power $WIRELESS_POWER"; fi
if [ ! -z "$WIRELESS_RETRY" ]; then echo -e "\twireless-retry $WIRELESS_RETRY"; fi
) > /etc/network/interfaces
print_status done
#--- Set up /etc/resolv.conf ----------------------------------
if [ ! -z "$DNS_1" ]; then
rm -f /etc/resolv.conf
(
echo "# resolv.conf autogenerated by netenv "`date`
if [ ! -z "$DOMAIN" ]; then echo domain $DOMAIN; fi
if [ ! -z "$SEARCH" ]; then echo search $SEARCH; fi
echo nameserver $DNS_1
if [ ! -z "$DNS_2" ]; then echo nameserver $DNS_2; fi
if [ ! -z "$DNS_3" ]; then echo nameserver $DNS_3; fi
) > /etc/resolv.conf.netenv
chmod 644 /etc/resolv.conf.netenv
print_action setting up new /etc/resolv.conf
ln -s /etc/resolv.conf.netenv /etc/resolv.conf
print_status
fi
#--- Edit /etc/hosts -------------------------------------------
NETENV_HOSTS_FILE=/etc/netenv/$(echo $1 |cut -d_ -f1)-hosts
if [ -r $NETENV_HOSTS_FILE ]; then
export NETENV_HOST_ENTRIES="$(cat $NETENV_HOSTS_FILE |tr '\n' ':')"
fi
if [ "$BOOTPROTO" = "dhcp" ]; then
export NETENV_HOST_ENTRIES="127.0.0.1 $NODE:$NETENV_HOST_ENTRIES"
else
if [ ! -z "$DOMAIN" ]; then
NETENV_DOMAIN=$DOMAIN
elif [ ! -z "$SEARCH" ]; then
NETENV_DOMAIN=$SEARCH
fi
if [ -z "$NETENV_DOMAIN" ]; then
export NETENV_HOST_ENTRIES="$IPADDR $NODE:$NETENV_HOST_ENTRIES"
else
export NETENV_HOST_ENTRIES="$IPADDR $NODE.$NETENV_DOMAIN $NODE:$NETENV_HOST_ENTRIES"
fi
fi
if [ -n "$NETENV_HOST_ENTRIES" ]; then
if egrep '^# netenv hosts begin$' /etc/hosts > /dev/null 2>&1; then
(
awk 'NR==1,/^# netenv hosts begin$/' /etc/hosts
echo $NETENV_HOST_ENTRIES | awk -F':' '{ for ( j=1; j<=NF; j++ ) print $j }'
awk '/^# netenv hosts end$/,/*/' /etc/hosts
) > /etc/hosts.netenv
print_action modifying /etc/hosts
mv -f /etc/hosts.netenv /etc/hosts
chmod 644 /etc/hosts
print_status
fi
else
if egrep '^# netenv hosts begin$' /etc/hosts > /dev/null 2>&1; then
(
awk 'NR==1,/^# netenv hosts begin$/' /etc/hosts
awk '/^# netenv hosts end$/,/*/' /etc/hosts
) > /etc/hosts.netenv
print_action cleaning up /etc/hosts
mv -f /etc/hosts.netenv /etc/hosts
chmod 644 /etc/hosts
print_status
fi
fi
|