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