1 | 1 | unreal | #!/bin/sh |
2 | | | # |
3 | | | # skript na synchronizaci CZF4BFU serveru |
4 | | | # by Unreal][ |
5 | 18 | unreal | # verze 1.7 |
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 | | | echo "*** zkousim jine servery na global-$IP.txt... *** " |
33 | | | PRESKOC=0 |
34 | | | for SERVER in `cat servers.list` |
35 | | | do |
36 | | | if [ $SERVER != $MYIP ] && [ $PRESKOC -lt 1 ]; then |
37 | | | if wget -T 3 -t 3 -N -U CZF4BFU http://$SERVER/czf4bfu/global-$IP.txt |
38 | | | then |
39 | | | echo "***** podarilo se ziskat global-$IP.txt z $SERVER *****" |
40 | | | PRESKOC=1 |
41 | | | fi |
42 | | | fi |
43 | | | done |
44 | | | fi |
45 | | | fi |
46 | | | done |
47 | | | |
48 | | | ### zkontrolujeme, jestli neni nejaky global navic |
49 | | | |
50 | | | GLOBALS=`ls global-*.txt | sed 's/^global-//' | sed 's/\.txt$//'` |
51 | | | for TMPSVR in $GLOBALS |
52 | | | do |
53 | | | OBSAHUJE=$(cat servers.list | grep $TMPSVR | wc -l) |
54 | | | if [ $OBSAHUJE != "0" ] |
55 | | | then |
56 | | | echo "*** $TMPSVR OK ***" |
57 | | | else |
58 | | | if [ $TMPSVR != $MYIP ]; then |
59 | | | mv ./global-$TMPSVR.txt ./global-$TMPSVR.txt.bckp |
60 | | | echo "*** $TMPSVR NEnalezen v servers.list a byl zalohovan ***" |
61 | | | fi |
62 | | | fi |
63 | | | done |
64 | 16 | unreal | ### mrkneme se po externich ikonkach |
65 | | | |
66 | | | OLD_IFS=$IFS; IFS=$'\n' |
67 | | | GLOBALS=`ls global-*.txt | sed 's/^global-//' | sed 's/\.txt$//'` |
68 | | | for TMPSVR in $GLOBALS |
69 | | | do |
70 | | | for ICONS in `grep 'ICON:' global-$TMPSVR.txt`; do |
71 | | | ICONURL=`echo "$ICONS" | sed -n "s/^ICON: \([[:space:]]+\)\?\([^[:space:]#].*\)/\2/p"` |
72 | | | ICONNAME=`echo "$ICONURL" | sed -n "s/^\(.*\)\/\([^[\/].*\)$/\2/p"` |
73 | | | if [ "$ICONNAME" != "" ]; then |
74 | 18 | unreal | if wget -T 3 -t 3 -N -U CZF4BFU $ICONURL |
75 | 16 | unreal | then |
76 | 18 | unreal | mv $ICONNAME $DATADIR/cache/"$TMPSVR"_"$ICONNAME" |
77 | 16 | unreal | echo "***** podarilo se stahnout ikonku $ICONNAME ze serveru $TMPSVR *****" |
78 | | | else |
79 | | | PRESKOC=0 |
80 | | | for SERVER in `cat servers.list` |
81 | | | do |
82 | | | if [ $PRESKOC -lt 1 ]; then |
83 | 18 | unreal | if wget -T 3 -t 3 -N -U CZF4BFU http://$SERVER/czf4bfu/cache/"$SERVER"_"$ICONNAME" |
84 | 16 | unreal | then |
85 | 18 | unreal | mv "$SERVER"_"$ICONNAME" $DATADIR/cache/"$SERVER"_"$ICONNAME" |
86 | 16 | unreal | echo "***** podarilo se stahnout ikonku $ICONNAME ze serveru $SERVER *****" |
87 | | | PRESKOC=1 |
88 | | | fi |
89 | | | fi |
90 | | | done |
91 | | | fi |
92 | | | fi |
93 | | | done |
94 | | | done |
95 | | | IFS=$OLD_IFS |