1 | 1 | unreal | #!/bin/sh |
2 | | | # |
3 | | | # skript na synchronizaci CZF4BFU serveru |
4 | | | # by Unreal][ |
5 | 21 | unreal | # verze 1.9 |
6 | 1 | unreal | # |
7 | 15 | unreal | ### DATADIR - adresar kam se maj ukladat soubory se zdroji (nejcasteji '/var/www/czf4bfu') |
8 | 1 | unreal | DATADIR='/var/www/www.kobylisy.czf/czf4bfu' |
9 | 15 | unreal | ### MYIP - ip adresa nebo DNS zaznam serveru |
10 | 1 | unreal | MYIP='czf4bfu.kobylisy.czf' |
11 | 21 | unreal | ### LIST - server s aktualnim seznamem rozcestniku |
12 | | | LIST='http://www.jklir.net/servers.list' |
13 | 15 | unreal | |
14 | | | ########################################################################################### |
15 | | | |
16 | 1 | unreal | cd $DATADIR |
17 | | | # stahneme si aktualni servers.list |
18 | 21 | unreal | if wget -T 3 -t 3 -N $LIST |
19 | 1 | unreal | then |
20 | | | echo "*** podarilo se ziskat servers.list z $LIST ***" |
21 | | | else |
22 | | | echo "*** servers.list z $LIST nelze stahnout, pracuju se starym seznamem... ***" |
23 | | | fi |
24 | | | |
25 | 15 | unreal | for IP in `cat servers.list` |
26 | | | do |
27 | | | if [ $IP != $MYIP ]; then |
28 | | | if wget -T 3 -t 3 -N -U CZF4BFU http://$IP/czf4bfu/global-$IP.txt |
29 | | | then |
30 | | | echo "*** podarilo se ziskat global-$IP.txt z $IP ***" |
31 | | | else |
32 | 21 | unreal | if wget -T 2 -t 2 -N -U CZF4BFU http://$IP/global-$IP.txt |
33 | | | then |
34 | | | echo "*** podarilo se ziskat global-$IP.txt z $IP ***" |
35 | | | else |
36 | | | echo "*** zkousim jine servery na global-$IP.txt... *** " |
37 | | | PRESKOC=0 |
38 | | | for SERVER in `cat servers.list` |
39 | | | do |
40 | | | if [ $SERVER != $MYIP ] && [ $PRESKOC -lt 1 ]; then |
41 | | | if wget -T 3 -t 3 -N -U CZF4BFU http://$SERVER/czf4bfu/global-$IP.txt |
42 | 20 | unreal | then |
43 | | | echo "***** podarilo se ziskat global-$IP.txt z $SERVER *****" |
44 | | | PRESKOC=1 |
45 | 21 | unreal | fi |
46 | | | fi |
47 | | | done |
48 | 20 | unreal | fi |
49 | 21 | unreal | fi |
50 | 15 | unreal | fi |
51 | | | done |
52 | | | |
53 | | | ### zkontrolujeme, jestli neni nejaky global navic |
54 | | | |
55 | | | GLOBALS=`ls global-*.txt | sed 's/^global-//' | sed 's/\.txt$//'` |
56 | | | for TMPSVR in $GLOBALS |
57 | | | do |
58 | | | OBSAHUJE=$(cat servers.list | grep $TMPSVR | wc -l) |
59 | | | if [ $OBSAHUJE != "0" ] |
60 | | | then |
61 | | | echo "*** $TMPSVR OK ***" |
62 | | | else |
63 | | | if [ $TMPSVR != $MYIP ]; then |
64 | | | mv ./global-$TMPSVR.txt ./global-$TMPSVR.txt.bckp |
65 | | | echo "*** $TMPSVR NEnalezen v servers.list a byl zalohovan ***" |
66 | | | fi |
67 | | | fi |
68 | | | done |
69 | 16 | unreal | ### mrkneme se po externich ikonkach |
70 | | | |
71 | | | OLD_IFS=$IFS; IFS=$'\n' |
72 | | | GLOBALS=`ls global-*.txt | sed 's/^global-//' | sed 's/\.txt$//'` |
73 | | | for TMPSVR in $GLOBALS |
74 | | | do |
75 | | | for ICONS in `grep 'ICON:' global-$TMPSVR.txt`; do |
76 | | | ICONURL=`echo "$ICONS" | sed -n "s/^ICON: \([[:space:]]+\)\?\([^[:space:]#].*\)/\2/p"` |
77 | | | ICONNAME=`echo "$ICONURL" | sed -n "s/^\(.*\)\/\([^[\/].*\)$/\2/p"` |
78 | 21 | unreal | if [ "$ICONNAME" != "" ] && [ ! -f "$DATADIR"/"$TMPSVR"_"$ICONNAME" ]; then |
79 | 18 | unreal | if wget -T 3 -t 3 -N -U CZF4BFU $ICONURL |
80 | 16 | unreal | then |
81 | 18 | unreal | mv $ICONNAME $DATADIR/cache/"$TMPSVR"_"$ICONNAME" |
82 | 16 | unreal | echo "***** podarilo se stahnout ikonku $ICONNAME ze serveru $TMPSVR *****" |
83 | | | else |
84 | | | PRESKOC=0 |
85 | | | for SERVER in `cat servers.list` |
86 | | | do |
87 | 21 | unreal | if [ $SERVER != $MYIP ] && [ $PRESKOC -lt 1 ]; then |
88 | | | if wget -T 3 -t 3 -N -U CZF4BFU http://$SERVER/czf4bfu/cache/"$TMPSVR"_"$ICONNAME" |
89 | 16 | unreal | then |
90 | 21 | unreal | mv "$TMPSVR"_"$ICONNAME" $DATADIR/cache/"$TMPSVR"_"$ICONNAME" |
91 | 16 | unreal | echo "***** podarilo se stahnout ikonku $ICONNAME ze serveru $SERVER *****" |
92 | | | PRESKOC=1 |
93 | 21 | unreal | else |
94 | | | if wget -T 2 -t 2 -N -U CZF4BFU http://$SERVER/cache/"$TMPSVR"_"$ICONNAME" |
95 | 20 | unreal | then |
96 | 21 | unreal | mv "$TMPSVR"_"$ICONNAME" $DATADIR/cache/"$TMPSVR"_"$ICONNAME" |
97 | 20 | unreal | echo "***** podarilo se stahnout ikonku $ICONNAME ze serveru $SERVER *****" |
98 | | | PRESKOC=1 |
99 | 21 | unreal | fi |
100 | 16 | unreal | fi |
101 | | | fi |
102 | | | done |
103 | | | fi |
104 | | | fi |
105 | | | done |
106 | | | done |
107 | | | IFS=$OLD_IFS |