1 | 2 | simandl | #!/bin/bash |
2 | | | # author : Petr Simandl www.simandl.cz |
3 | | | # release date : 19/08/2004 |
4 | | | # name : sedlo |
5 | | | # description : dynamic side routing tables tool |
6 | | | # license : GPL |
7 | | | |
8 | | | sl_version="0.0.1" |
9 | | | |
10 | | | PATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin |
11 | | | |
12 | | | sl_nmcnf="sedlo.conf" |
13 | | | sl_sedlocnf="/etc/$sl_nmcnf" |
14 | | | sl_sedlocache="/var/cache/sedlo" |
15 | | | |
16 | | | sl_rttab="/etc/iproute2/rt_tables" |
17 | | | sl_rtnmin=110 |
18 | | | sl_rtnmax=125 |
19 | | | |
20 | | | sl_ipcmd=`which wget` |
21 | | | sl_hnmcmd=`which hostname` |
22 | | | sl_awkcmd=`which awk` |
23 | | | |
24 | | | |
25 | | | sl_time=`date '+%Y%m%d%H%M%S'` |
26 | | | |
27 | | | if [ -e $sl_sedlocnf ] |
28 | | | then |
29 | | | sl_nop=1 |
30 | | | else |
31 | | | echo "$sl_sedlocnf not found" |
32 | | | exit 1 |
33 | | | fi |
34 | | | |
35 | | | if [ -e $sl_rttab ] |
36 | | | then |
37 | | | sl_nop=1 |
38 | | | else |
39 | | | echo "$sl_rttab not found" |
40 | | | exit 1 |
41 | | | fi |
42 | | | |
43 | | | sl_murlcfg=`cat $sl_sedlocnf | grep mcnf | uniq | awk '{print $2}'` |
44 | | | |
45 | | | ###################################################################### |
46 | | | s_mktables() |
47 | | | { |
48 | | | echo s_mktables |
49 | | | |
50 | | | sl_igws=`cat $sl_sedlocache/$sl_nmcnf | grep "^igw" | awk '{print $3}'` |
51 | | | |
52 | | | for sl_igw in $sl_igws |
53 | | | do |
54 | | | sl_igwrttb=`cat $sl_rttab | awk '{print $2}' | grep $sl_igw ` |
55 | | | if [ "$sl_igwrttb x" = " x" ] |
56 | | | then |
57 | | | echo "Table for $sl_igw not found - creating" |
58 | | | sl_cnt="$sl_rtnmax" |
59 | | | sl_ok="no" |
60 | | | until [ "$sl_cnt" -eq "$sl_rtnmin" ] || [ "$sl_ok" = "yes" ] |
61 | | | do |
62 | | | #space is used to recognized two and three digit numbers |
63 | | | sl_igwrttb=`cat $sl_rttab | awk '{print $1" "}' | grep "$sl_cnt " ` |
64 | | | if [ "$sl_igwrttb x" = " x" ] |
65 | | | then |
66 | | | sl_ok="yes" |
67 | | | echo "$sl_cnt $sl_igw" >> $sl_rttab |
68 | | | fi |
69 | | | sl_cnt=$(($sl_cnt - 1 )) |
70 | | | done |
71 | | | |
72 | | | else |
73 | | | echo "Table for $sl_igw found" |
74 | | | fi |
75 | | | |
76 | | | done |
77 | | | } |
78 | | | ###################################################################### |
79 | | | s_getcfg() |
80 | | | { |
81 | | | echo s_getcfg |
82 | | | wget $sl_murlcfg -O "$sl_sedlocache/$sl_nmcnf.main" -q |
83 | | | echo "# generated file" > $sl_sedlocache/$sl_nmcnf |
84 | | | for sl_file in `ls $sl_sedlocnf $sl_sedlocache/$sl_nmcnf.main ` |
85 | | | do |
86 | | | cat $sl_file | grep "^mcnf" | awk '{print $1"\t"$2}' >> $sl_sedlocache/$sl_nmcnf |
87 | | | cat $sl_file | grep "^igw" | awk '{print $1"\t"$2"\t"$3}' >> $sl_sedlocache/$sl_nmcnf |
88 | | | cat $sl_file | grep "^ip" | awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}' >> $sl_sedlocache/$sl_nmcnf |
89 | | | done |
90 | | | cat $sl_sedlocache/$sl_nmcnf | sort | uniq > $sl_sedlocache/$sl_nmcnf.uniq |
91 | | | mv $sl_sedlocache/$sl_nmcnf.uniq $sl_sedlocache/$sl_nmcnf |
92 | | | |
93 | | | } |
94 | | | ###################################################################### |
95 | | | s_version() |
96 | | | { |
97 | | | echo sedlo $sl_version |
98 | | | exit 0 |
99 | | | } |
100 | | | ###################################################################### |
101 | | | s_help() |
102 | | | { |
103 | | | echo Pouziti: sedlo [param] |
104 | | | echo param: |
105 | | | echo -v vypise verzi |
106 | | | exit 0 |
107 | | | } |
108 | | | ###################################################################### |
109 | | | ###################################################################### |
110 | | | |
111 | | | s_getcfg |
112 | | | |
113 | | | s_mktables |
114 | | | exit 0 |