1 | 1 | unreal | #!/bin/sh |
2 | | | # |
3 | | | # skript na synchronizaci CZF4BFU serveru |
4 | | | # by Unreal][ |
5 | 20 | unreal | # verze 1.8 |
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 | 15 | unreal | ### LIST - server s aktualnim seznamem rozcestniku (bez http://) ... /servers.list |
12 | 1 | unreal | LIST='www.jklir.net' |
13 | 15 | unreal | |
14 | | | ########################################################################################### |
15 | | | |
16 | 1 | unreal | cd $DATADIR |
17 | | | # stahneme si aktualni servers.list |
18 | 14 | unreal | if wget -T 3 -t 3 -N http://$LIST/servers.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 | 20 | unreal | if wget -T 3 -t 3 -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 | | | then |
43 | | | echo "***** podarilo se ziskat global-$IP.txt z $SERVER *****" |
44 | | | PRESKOC=1 |
45 | | | else |
46 | | | if wget -T 3 -t 3 -N -U CZF4BFU http://$SERVER/global-$IP.txt |
47 | | | then |
48 | | | echo "***** podarilo se ziskat global-$IP.txt z $SERVER *****" |
49 | | | PRESKOC=1 |
50 | | | fi |
51 | | | fi |
52 | | | fi |
53 | | | done |
54 | | | fi |
55 | 15 | unreal | fi |
56 | | | fi |
57 | | | done |
58 | | | |
59 | | | ### zkontrolujeme, jestli neni nejaky global navic |
60 | | | |
61 | | | GLOBALS=`ls global-*.txt | sed 's/^global-//' | sed 's/\.txt$//'` |
62 | | | for TMPSVR in $GLOBALS |
63 | | | do |
64 | | | OBSAHUJE=$(cat servers.list | grep $TMPSVR | wc -l) |
65 | | | if [ $OBSAHUJE != "0" ] |
66 | | | then |
67 | | | echo "*** $TMPSVR OK ***" |
68 | | | else |
69 | | | if [ $TMPSVR != $MYIP ]; then |
70 | | | mv ./global-$TMPSVR.txt ./global-$TMPSVR.txt.bckp |
71 | | | echo "*** $TMPSVR NEnalezen v servers.list a byl zalohovan ***" |
72 | | | fi |
73 | | | fi |
74 | | | done |
75 | 16 | unreal | ### mrkneme se po externich ikonkach |
76 | | | |
77 | | | OLD_IFS=$IFS; IFS=$'\n' |
78 | | | GLOBALS=`ls global-*.txt | sed 's/^global-//' | sed 's/\.txt$//'` |
79 | | | for TMPSVR in $GLOBALS |
80 | | | do |
81 | | | for ICONS in `grep 'ICON:' global-$TMPSVR.txt`; do |
82 | | | ICONURL=`echo "$ICONS" | sed -n "s/^ICON: \([[:space:]]+\)\?\([^[:space:]#].*\)/\2/p"` |
83 | | | ICONNAME=`echo "$ICONURL" | sed -n "s/^\(.*\)\/\([^[\/].*\)$/\2/p"` |
84 | | | if [ "$ICONNAME" != "" ]; then |
85 | 18 | unreal | if wget -T 3 -t 3 -N -U CZF4BFU $ICONURL |
86 | 16 | unreal | then |
87 | 18 | unreal | mv $ICONNAME $DATADIR/cache/"$TMPSVR"_"$ICONNAME" |
88 | 16 | unreal | echo "***** podarilo se stahnout ikonku $ICONNAME ze serveru $TMPSVR *****" |
89 | | | else |
90 | | | PRESKOC=0 |
91 | | | for SERVER in `cat servers.list` |
92 | | | do |
93 | | | if [ $PRESKOC -lt 1 ]; then |
94 | 18 | unreal | if wget -T 3 -t 3 -N -U CZF4BFU http://$SERVER/czf4bfu/cache/"$SERVER"_"$ICONNAME" |
95 | 16 | unreal | then |
96 | 18 | unreal | mv "$SERVER"_"$ICONNAME" $DATADIR/cache/"$SERVER"_"$ICONNAME" |
97 | 16 | unreal | echo "***** podarilo se stahnout ikonku $ICONNAME ze serveru $SERVER *****" |
98 | | | PRESKOC=1 |
99 | 20 | unreal | else |
100 | | | if wget -T 3 -t 3 -N -U CZF4BFU http://$SERVER/cache/"$SERVER"_"$ICONNAME" |
101 | | | then |
102 | | | mv "$SERVER"_"$ICONNAME" $DATADIR/cache/"$SERVER"_"$ICONNAME" |
103 | | | echo "***** podarilo se stahnout ikonku $ICONNAME ze serveru $SERVER *****" |
104 | | | PRESKOC=1 |
105 | | | fi |
106 | 16 | unreal | fi |
107 | | | fi |
108 | | | done |
109 | | | fi |
110 | | | fi |
111 | | | done |
112 | | | done |
113 | | | IFS=$OLD_IFS |