diff options
Diffstat (limited to 'urunlevel/my_linux/Trinux/net-start')
-rwxr-xr-x | urunlevel/my_linux/Trinux/net-start | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/urunlevel/my_linux/Trinux/net-start b/urunlevel/my_linux/Trinux/net-start new file mode 100755 index 0000000..a090d85 --- /dev/null +++ b/urunlevel/my_linux/Trinux/net-start | |||
@@ -0,0 +1,141 @@ | |||
1 | #!/bin/sh | ||
2 | # net-start | ||
3 | # | ||
4 | # can also be run via "start net" or "start network" | ||
5 | # | ||
6 | |||
7 | |||
8 | # find which dhcp client | ||
9 | |||
10 | |||
11 | if [ -x /usr/sbin/dhcpcd ] | ||
12 | then | ||
13 | DHCPCLIENT="/usr/sbin/dhcpcd" | ||
14 | elif [ -x /sbin/udhcpc ] | ||
15 | then | ||
16 | DHCPCLIENT="/sbin/udhcpc" | ||
17 | else | ||
18 | echo "No DHCP client found!" | ||
19 | fi | ||
20 | |||
21 | /sbin/net-stop # bring down any interfaces and kill dhcp clients | ||
22 | |||
23 | [ -d /etc/proc ] || mkdir /etc/proc | ||
24 | |||
25 | probed=`dmesg | grep eth[0-9]: | cut -d: -f1` | ||
26 | |||
27 | cd /etc/tux/config/ | ||
28 | found_faces=`ls eth*` | ||
29 | |||
30 | echo "Found configs for: $found_faces" | ||
31 | |||
32 | # first bring up interfaces | ||
33 | |||
34 | for i in $found_faces | ||
35 | do | ||
36 | echo -n "Configuring $i:" | ||
37 | |||
38 | if grep dhcp /etc/tux/config/$i > /dev/null 2> /dev/null | ||
39 | then | ||
40 | DHCP="true" | ||
41 | # things are really easy we just do dhcp | ||
42 | echo " using DHCP" | ||
43 | killall dhcpcd 2> /dev/null | ||
44 | sleep 1 | ||
45 | if [ $DHCPCLIENT = "/usr/sbin/dhcpcd" ] | ||
46 | then | ||
47 | $DHCPCLIENT $i 2> /dev/null | ||
48 | else | ||
49 | $DHCPCLIENT -i $i 2> /dev/null | ||
50 | fi | ||
51 | |||
52 | else # static IP | ||
53 | |||
54 | if [ -f /etc/tux/config/$i ] | ||
55 | then | ||
56 | echo "settings found" | ||
57 | IP=`cut -d" " -f1 /etc/tux/config/$i` | ||
58 | MASK=`cut -d" " -f2 /etc/tux/config/$i` | ||
59 | |||
60 | if [ "$IP" ] | ||
61 | then | ||
62 | ifconfig $i $IP netmask $MASK up | ||
63 | fi | ||
64 | |||
65 | else | ||
66 | echo "no settings found, skipping..." | ||
67 | fi | ||
68 | fi | ||
69 | |||
70 | |||
71 | if [ "$i" = "eth0" ] | ||
72 | then | ||
73 | ifconfig $face | grep inet | cut -d":" -f2 | cut -d" " -f1 | grep -v 127.0.0.1 > /etc/proc/ipaddr | ||
74 | ln -sf /etc/proc/ipaddr /etc/proc/$i | ||
75 | nslookup `cat /etc/proc/ipaddr` | grep -v default | grep Name | cut -d":" -f2 | tr -d ' ' | tail -n 1 > /etc/proc/hostname | ||
76 | fi | ||
77 | |||
78 | done | ||
79 | |||
80 | if [ "$DHCP" ] | ||
81 | then | ||
82 | echo "Skipping DNS and gateway config" | ||
83 | else | ||
84 | echo -n "Adding default route: " | ||
85 | |||
86 | GW=`cat /etc/tux/config/gateway` | ||
87 | |||
88 | echo "$GW" | ||
89 | if [ "$GW" ] | ||
90 | then | ||
91 | route add default gw $GW | ||
92 | echo "done" | ||
93 | else | ||
94 | echo "failed" | ||
95 | fi | ||
96 | |||
97 | echo -n "Builing /etc/resolv.conf (DNS): " | ||
98 | # need to fix this for multiple DNS servers | ||
99 | |||
100 | DNS=`cat /etc/tux/config/dns 2>/dev/null` | ||
101 | |||
102 | if [ "$DNS" ] | ||
103 | then | ||
104 | echo "nameserver $DNS" > /etc/resolv.conf | ||
105 | else | ||
106 | echo "failed" | ||
107 | fi | ||
108 | fi | ||
109 | |||
110 | |||
111 | # update /etc/hosts and set HOSTNAME | ||
112 | |||
113 | IPADDR=`cat /etc/proc/ipaddr` | ||
114 | |||
115 | if [ -f /etc/tux/config/hostname ] | ||
116 | then | ||
117 | HOSTNAME=`cat /etc/tux/config/hostname` | ||
118 | else | ||
119 | HOSTNAME=`cat /etc/proc/hostname` | ||
120 | hlen=`length "$HOSTNAME"` | ||
121 | |||
122 | if [ "$hlen" -lt 1 ] | ||
123 | then | ||
124 | HOSTNAME='trinux' | ||
125 | fi | ||
126 | fi | ||
127 | |||
128 | echo "Setting hostname: $HOSTNAME" | ||
129 | hostname $HOSTNAME | ||
130 | |||
131 | echo "Building /etc/hosts" | ||
132 | if [ -f /etc/tux/config/hosts ] | ||
133 | then | ||
134 | cp /etc/tux/config/hosts /etc/hosts | ||
135 | fi | ||
136 | |||
137 | echo "127.0.0.1 localhost" >> /etc/hosts | ||
138 | echo "$IPADDR $HOSTNAME" >> /etc/hosts | ||
139 | |||
140 | sleep 3 | ||
141 | |||