Contents of /alx-src/branches/alxconf-060/functions/config_network.sh
Parent Directory | Revision Log
Revision 218 -
(show annotations)
(download)
(as text)
Tue Mar 8 20:29:46 2005 UTC (19 years, 6 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_network.sh
File MIME type: application/x-sh
File size: 2869 byte(s)
Tue Mar 8 20:29:46 2005 UTC (19 years, 6 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_network.sh
File MIME type: application/x-sh
File size: 2869 byte(s)
new
1 | # configures networkin on the host via mysql db settings |
2 | |
3 | #delme settings |
4 | SQL_USER=alx_install |
5 | SQL_PASS=@lx |
6 | SQL_HOST=128.20.41.110 |
7 | SQL_DB=alx_web |
8 | ALX_SERIAL=10 |
9 | |
10 | get_network_settings() |
11 | { |
12 | local x i all DB_NETWORK |
13 | |
14 | #all arrays: |
15 | # -> hostname modules domain networking ip netmask dns gateway broadcast |
16 | |
17 | all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
18 | "select hostname, |
19 | module, |
20 | domain, |
21 | networking, |
22 | ip, |
23 | netmask, |
24 | dns, |
25 | gateway, |
26 | broadcast |
27 | from cfg_network where serial='${ALX_SERIAL}'") |
28 | |
29 | #split'em up and put 'em in an array |
30 | declare -i i=0 |
31 | for x in ${all} |
32 | do |
33 | DB_NETWORK[${i}]="${x}" |
34 | ((i++)) |
35 | done |
36 | |
37 | # and now put them in usable var names and export them systemwide |
38 | export ALX_HOSTNAME="${DB_NETWORK[0]:=NULL}" |
39 | export ALX_MODULE="${DB_NETWORK[1]:=NULL}" |
40 | export ALX_DOMAIN="${DB_NETWORK[2]:=NULL}" |
41 | export ALX_NETWORKING="${DB_NETWORK[3]:=NULL}" |
42 | export ALX_IP="${DB_NETWORK[4]:=NULL}" |
43 | export ALX_NETMASK="${DB_NETWORK[5]:=NULL}" |
44 | export ALX_DNS="${DB_NETWORK[6]:=NULL}" |
45 | export ALX_GATEWAY="${DB_NETWORK[7]:=NULL}" |
46 | export ALX_BROADCAST="${DB_NETWORK[8]:=NULL}" |
47 | } |
48 | |
49 | config_networking() |
50 | { |
51 | #first of all get the vars |
52 | get_network_settings |
53 | |
54 | # debug |
55 | echo "0: ${ALX_HOSTNAME}" |
56 | echo "1: ${ALX_MODULE}" |
57 | echo "2: ${ALX_DOMAIN}" |
58 | echo "3: ${ALX_NETWORKING}" |
59 | echo "4: ${ALX_IP}" |
60 | echo "5: ${ALX_NETMASK}" |
61 | echo "6: ${ALX_DNS}" |
62 | echo "7: ${ALX_GATEWAY}" |
63 | echo "8: ${ALX_BROADCAST}" |
64 | |
65 | # hostname && hosts |
66 | echo "${ALX_HOSTNAME}" > /etc/hostname |
67 | echo -e "127.0.0.1\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}" > /etc/hosts |
68 | |
69 | # network devices |
70 | |
71 | # always on boot |
72 | echo 'ONBOOT="yes"' > /etc/conf.d/net.eth0 |
73 | echo "NETWORKING=\"${ALX_NETWORKING}\"" >> /etc/conf.d/net.eth0 |
74 | |
75 | case ${ALX_NETWORKING} in |
76 | dhcp|DHCP) |
77 | echo 'DHCP_PROG="/sbin/dhcpcd"' >> /etc/conf.d/net.eth0 |
78 | # -k kills the dhcp-cache at system shutdown |
79 | # -z will not |
80 | echo 'DHCP_STOP="-z"' >> /etc/conf.d/net.eth0 |
81 | #timeout after 10 seconds |
82 | echo 'DHCP_START="-t 10"' >> /etc/conf.d/net.eth0 |
83 | ;; |
84 | |
85 | static|STATIC) |
86 | # add hostname with valid ip to hosts |
87 | echo -e "${ALX_IP}\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}" >> /etc/hosts |
88 | echo "IP=\"${ALX_IP}\"" >> /etc/conf.d/net.eth0 |
89 | echo "NETMASK=\"${ALX_NETMASK}\"" >> /etc/conf.d/net.eth0 |
90 | echo "BROADCAST=\"${ALX_BROADCAST}\"" >> /etc/conf.d/net.eth0 |
91 | ;; |
92 | esac |
93 | |
94 | # gateway or gateway overrides |
95 | if [[ ${ALX_GATEWAY} != NULL ]] |
96 | then |
97 | echo "GATEWAY=\"${ALX_GATEWAY}\"" >> /etc/conf.d/net.eth0 |
98 | echo 'GATEWAY_IF="eth0"' >> /etc/conf.d/net.eth0 |
99 | fi |
100 | |
101 | # nameserver or nameserver overrides |
102 | if [[ ${ALX_DNS} != NULL ]] |
103 | then |
104 | echo "nameserver ${ALX_DNS}" > /etc/resolv.conf |
105 | fi |
106 | |
107 | # unset all vars |
108 | unset ALX_HOSTNAME |
109 | unset ALX_MODULE |
110 | unset ALX_DOMAIN |
111 | unset ALX_NETWORKING |
112 | unset ALX_IP |
113 | unset ALX_NETMASK |
114 | unset ALX_DNS |
115 | unset ALX_GATEWAY |
116 | unset ALX_BROADCAST |
117 | } |