1 |
# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_network.sh,v 1.4 2005-04-12 20:45:55 niro Exp $ |
# $Id$ |
2 |
# configures networkin on the host via mysql db settings |
# configures networking on the host via mysql db settings |
3 |
|
|
4 |
get_network_settings() |
config_networking() |
5 |
{ |
{ |
6 |
local x i all DB_NETWORK |
local iface |
7 |
|
local CONFIG |
8 |
|
|
9 |
#all arrays: |
# first of all get the vars |
10 |
# -> hostname modules domain networking ip netmask dns gateway broadcast |
evaluate_table cfg_network |
11 |
|
|
12 |
all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
# get the right nic |
13 |
"select hostname, |
if [[ -z ${cfg_network_iface} ]] || [[ ${cfg_network_iface} = NULL ]] |
14 |
module, |
then |
15 |
domain, |
# default is 'eth0' |
16 |
networking, |
iface="eth0" |
17 |
ip, |
else |
18 |
netmask, |
iface="${cfg_network_iface}" |
19 |
dns, |
fi |
|
gateway, |
|
|
broadcast |
|
|
from cfg_network where serial='${ALX_SERIAL}'") |
|
|
|
|
|
#split'em up and put 'em in an array |
|
|
declare -i i=0 |
|
|
for x in ${all} |
|
|
do |
|
|
DB_NETWORK[${i}]="${x}" |
|
|
((i++)) |
|
|
done |
|
20 |
|
|
21 |
# and now put them in usable var names and export them systemwide |
# never ever overwrite network settings, if NETWORKING is unknown |
22 |
export ALX_HOSTNAME="${DB_NETWORK[0]:=NULL}" |
case ${cfg_network_networking} in |
23 |
export ALX_MODULE="${DB_NETWORK[1]:=NULL}" |
static|STATIC|dhcp|DHCP) ;; |
24 |
export ALX_DOMAIN="${DB_NETWORK[2]:=NULL}" |
*) |
25 |
export ALX_NETWORKING="${DB_NETWORK[3]:=NULL}" |
echo -e "${COLRED}Received network-settings are not complete, aborting ...${COLDEFAULT}" |
26 |
export ALX_IP="${DB_NETWORK[4]:=NULL}" |
return 1 |
27 |
export ALX_NETMASK="${DB_NETWORK[5]:=NULL}" |
;; |
28 |
export ALX_DNS="${DB_NETWORK[6]:=NULL}" |
esac |
|
export ALX_GATEWAY="${DB_NETWORK[7]:=NULL}" |
|
|
export ALX_BROADCAST="${DB_NETWORK[8]:=NULL}" |
|
|
} |
|
29 |
|
|
30 |
config_networking() |
# remove all old nics and modules configs |
31 |
{ |
find /etc/conf.d -type f -name 'net.*' | xargs rm |
32 |
#first of all get the vars |
find /etc/modprobe.d -type f -name 'net.*' | xargs rm |
33 |
get_network_settings |
|
34 |
|
# update the preliminary network |
35 |
|
# set an device alias for modprobe.conf |
36 |
|
[ ! -d /etc/modprobe.d ] && install -d /etc/modprobe.d |
37 |
|
# update only if not the same (to speed up bootprocess - no depmod) |
38 |
|
if [ ! -f /etc/modprobe.d/net.${iface}.conf ] || |
39 |
|
[[ ${iface} != $(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f2) ]] |
40 |
|
then |
41 |
|
CONFIG="/etc/modprobe.d/net.${iface}.conf" |
42 |
|
clearconfig |
43 |
|
addconfig "alias ${iface} ${cfg_network_module}" |
44 |
|
fi |
45 |
|
|
46 |
# debug |
# update confd-networking default iface |
47 |
echo "0: ${ALX_HOSTNAME}" |
[ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} |
48 |
echo "1: ${ALX_MODULE}" |
CONFIG="${SETTINGSPATH}/confd-networking" |
49 |
echo "2: ${ALX_DOMAIN}" |
clearconfig |
50 |
echo "3: ${ALX_NETWORKING}" |
addconfig "${iface}" |
|
echo "4: ${ALX_IP}" |
|
|
echo "5: ${ALX_NETMASK}" |
|
|
echo "6: ${ALX_DNS}" |
|
|
echo "7: ${ALX_GATEWAY}" |
|
|
echo "8: ${ALX_BROADCAST}" |
|
51 |
|
|
52 |
# hostname && hosts |
# hostname && hosts |
53 |
echo "${ALX_HOSTNAME}" > /etc/hostname |
CONFIG="/etc/hostname" |
54 |
echo -e "127.0.0.1\tlocalhost\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}" > /etc/hosts |
clearconfig |
55 |
|
addconfig "${cfg_network_hostname}" |
56 |
|
CONFIG="/etc/hosts" |
57 |
|
clearconfig |
58 |
|
addconfig -e "127.0.0.1\tlocalhost.${cfg_network_domain}\tlocalhost\t${cfg_network_hostname}" |
59 |
|
case ${cfg_network_networking} in |
60 |
|
static|STATIC) |
61 |
|
# add hostname with valid ip to hosts |
62 |
|
addconfig -e "${ALX_IP}\t${cfg_network_hostname}.${cfg_network_domain}\t${cfg_network_hostname}" |
63 |
|
;; |
64 |
|
esac |
65 |
|
|
66 |
# network devices |
# network devices |
67 |
|
|
68 |
# always on boot |
# always on boot |
69 |
echo 'ONBOOT="yes"' > /etc/conf.d/net.eth0 |
CONFIG="/etc/conf.d/net.${iface}" |
70 |
echo "NETWORKING=\"${ALX_NETWORKING}\"" >> /etc/conf.d/net.eth0 |
clearconfig |
71 |
|
|
72 |
case ${ALX_NETWORKING} in |
addconfig 'ONBOOT="yes"' |
73 |
|
addconfig "NETWORKING=\"${cfg_network_networking}\"" |
74 |
|
case ${cfg_network_networking} in |
75 |
dhcp|DHCP) |
dhcp|DHCP) |
76 |
echo 'DHCP_PROG="/sbin/dhcpcd"' >> /etc/conf.d/net.eth0 |
addconfig "DHCP_PROG=\"${ALX_DHCP_PROG}\"" |
77 |
# -k kills the dhcp-cache at system shutdown |
addconfig "DHCP_STOP=\"${ALX_DHCP_STOP}\"" |
78 |
# -z will not |
addconfig "DHCP_START=\"${ALX_DHCP_START}\"" |
|
echo 'DHCP_STOP="-z"' >> /etc/conf.d/net.eth0 |
|
|
#timeout after 10 seconds |
|
|
echo 'DHCP_START="-t 10"' >> /etc/conf.d/net.eth0 |
|
79 |
;; |
;; |
80 |
|
|
81 |
static|STATIC) |
static|STATIC) |
82 |
# add hostname with valid ip to hosts |
addconfig "IP=\"${cfg_network_ip}\"" |
83 |
echo -e "${ALX_IP}\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}" >> /etc/hosts |
addconfig "NETMASK=\"${cfg_network_netmask}\"" |
84 |
echo "IP=\"${ALX_IP}\"" >> /etc/conf.d/net.eth0 |
addconfig "BROADCAST=\"${cfg_network_broadcast}\"" |
|
echo "NETMASK=\"${ALX_NETMASK}\"" >> /etc/conf.d/net.eth0 |
|
|
echo "BROADCAST=\"${ALX_BROADCAST}\"" >> /etc/conf.d/net.eth0 |
|
85 |
;; |
;; |
86 |
esac |
esac |
87 |
|
|
88 |
|
# force mac address override |
89 |
|
if [[ ${cfg_network_forcemacto} != NULL ]] && [[ ! -z ${cfg_network_forcemacto} ]] |
90 |
|
then |
91 |
|
addconfig "FORCE_MAC_TO=\"${cfg_network_forcemacto}\"" |
92 |
|
fi |
93 |
|
|
94 |
|
# wireless extensions |
95 |
|
local value |
96 |
|
local var |
97 |
|
for var in bitrate \ |
98 |
|
channel \ |
99 |
|
essid \ |
100 |
|
frequency \ |
101 |
|
mode \ |
102 |
|
nick \ |
103 |
|
auth_mode \ |
104 |
|
key_length \ |
105 |
|
key \ |
106 |
|
key_ascii |
107 |
|
do |
108 |
|
# get the value of $var |
109 |
|
eval value="\${cfg_network_wireless_$(echo ${var})}" |
110 |
|
|
111 |
|
# write it only if not empty |
112 |
|
if [[ ! -z ${value} ]] && [[ ${value} != NULL ]] |
113 |
|
then |
114 |
|
# add WIRELESS and use uppercases |
115 |
|
addconfig "WIRELESS_$(echo ${var} | tr [[:lower:] [[:upper:]])=\"${value}\"" |
116 |
|
fi |
117 |
|
|
118 |
|
# clear value |
119 |
|
unset value |
120 |
|
done |
121 |
|
|
122 |
|
# FIXME !!! |
123 |
|
# setup wpa-driver (only zydas atm) |
124 |
|
if [[ ${cfg_network_module} = zd1211 ]] |
125 |
|
then |
126 |
|
addconfig "WIRELESS_WPA_DRIVER=zydas" |
127 |
|
fi |
128 |
|
|
129 |
|
CONFIG="/etc/conf.d/net.routes" |
130 |
|
clearconfig |
131 |
# gateway or gateway overrides |
# gateway or gateway overrides |
132 |
if [[ ${ALX_GATEWAY} != NULL ]] |
if [[ ${cfg_network_gateway} != NULL ]] && [[ ! -z ${cfg_network_gateway} ]] |
133 |
then |
then |
134 |
echo "GATEWAY=\"${ALX_GATEWAY}\"" >> /etc/conf.d/net.eth0 |
addconfig "default gw ${cfg_network_gateway}" |
|
echo 'GATEWAY_IF="eth0"' >> /etc/conf.d/net.eth0 |
|
135 |
fi |
fi |
136 |
|
|
137 |
|
CONFIG="/etc/resolv.conf" |
138 |
|
clearconfig |
139 |
# nameserver or nameserver overrides |
# nameserver or nameserver overrides |
140 |
if [[ ${ALX_DNS} != NULL ]] |
if [[ ${cfg_network_dns} != NULL ]] && [[ ! -z ${cfg_network_dns} ]] |
141 |
then |
then |
142 |
echo "nameserver ${ALX_DNS}" > /etc/resolv.conf |
addconfig "nameserver ${cfg_network_dns}" |
143 |
fi |
fi |
144 |
|
|
145 |
# unset all vars |
# netbios daemon |
146 |
unset ALX_HOSTNAME |
if [[ -x /usr/sbin/nmbd ]] |
147 |
unset ALX_MODULE |
then |
148 |
unset ALX_DOMAIN |
CONFIG="/etc/samba/smb.conf" |
149 |
unset ALX_NETWORKING |
clearconfig |
150 |
unset ALX_IP |
addconfig "[global]" |
151 |
unset ALX_NETMASK |
addconfig "workgroup = ${cfg_network_domain}" |
152 |
unset ALX_DNS |
addconfig "netbios name = ${cfg_network_hostname}" |
153 |
unset ALX_GATEWAY |
addconfig "dns proxy = no" |
154 |
unset ALX_BROADCAST |
|
155 |
|
rc-config add nmbd &> /dev/null |
156 |
|
else |
157 |
|
rc-config del nmbd &> /dev/null |
158 |
|
fi |
159 |
} |
} |