forked from offspot/kiwix-plug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_master.sh
executable file
·244 lines (216 loc) · 7.54 KB
/
setup_master.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
KIWIX_X86_STATIC_URL=http://download.kiwix.org/bin/kiwix-linux-i686.tar.bz2
KIWIX_ARM_STATIC_URL=http://download.kiwix.org/bin/kiwix-server-arm.tar.bz2
KIWIX_WINDOWS_URL=http://download.kiwix.org/bin/kiwix-win.zip
KIWIX_OSX_URL=http://download.kiwix.org/bin/kiwix.dmg
KIWIX_ANDROID_URL=http://download.kiwix.org/bin/kiwix.apk
KIWIX_SRC_URL=http://download.kiwix.org/src/kiwix-src.tar.xz
BIN_TO_INSTALL="no"
# Compute script path
BINARY_ORG="$0"
if [ ! ${BINARY_ORG:0:1} = "/" ]
then
BINARY_ORG=`pwd`/$BINARY_ORG
fi
# Binary target script path (in case of symlink)
BINARY=$BINARY_ORG
while [ `readlink $BINARY` ]
do
BINARY=`readlink $BINARY`
done
# Compute script dir ($ROOT)
if [ ${BINARY:0:1} = "/" ]
then
ROOT=`dirname $BINARY`
else
ROOT=`dirname $BINARY_ORG`/`dirname $BINARY`
ROOT=`cd $ROOT ; pwd`
fi
# Check if the DNS works
`host -a www.kiwix.org 8.8.8.8 > /dev/null`
EXIT_VALUE=$?
if [ ! "$EXIT_VALUE" = "0" ]
then
echo "Was not able to resolve www.kiwix.org. Are you access to Internet is OK?"
exit 1
fi
# Check if the access to Internet works
`ping -c3 www.kiwix.org > /dev/null`
EXIT_VALUE=$?
if [ ! "$EXIT_VALUE" = "0" ]
then
echo "Was not able to ping www.kiwix.org. Are you access to Internet is OK?"
BIN_TO_INSTALL="yes"
fi
# Check if the mtools are installed
MLABEL=`whereis mlabel | cut --delimiter=":" -f2 | cut --delimiter=" " -f2`
if [ "$MLABEL" = "" ]
then
echo "You need to install the mtools (apt-get install mtools)."
BIN_TO_INSTALL="yes"
fi
# Check if "mkdosfs" is installed
MKDOSFS=`whereis -b mkdosfs | cut -d" " -f2`
if [ "$MKDOSFS" = "" ]
then
echo "You need to install the dosfstools (apt-get install dosfstools)."
BIN_TO_INSTALL="yes"
fi
# Check if "wget" is installed
WGET=`whereis -b wget | cut --delimiter=":" -f2 | cut --delimiter=" " -f2`
if [ "$WGET" = "" ]
then
echo "You need to install wget (apt-get install wget)."
BIN_TO_INSTALL="yes"
fi
# Check if "split" is installed
SPLIT=`whereis -b split | cut --delimiter=":" -f2 | cut --delimiter=" " -f2`
if [ "$SPLIT" = "" ]
then
echo "You need to install split (apt-get install coreutils)."
exit 1
fi
# Check if "arp-scan" is installed
ARP_SCAN=`whereis -b arp-scan | cut --delimiter=":" -f2 | cut --delimiter=" " -f2`
if [ "$ARP_SCAN" = "" ]
then
echo "You need to install arp-scan (apt-get install arp-scan)."
BIN_TO_INSTALL="yes"
fi
# Check if "plink" is installed
PLINK=`whereis -b plink | cut --delimiter=":" -f2 | cut --delimiter=" " -f2`
if [ "$PLINK" = "" ]
then
echo "You need to install plink (apt-get install putty-tools)."
BIN_TO_INSTALL="yes"
fi
# Check if "pscp" is installed
PSCP=`whereis -b pscp | cut --delimiter=":" -f2 | cut --delimiter=" " -f2`
if [ "$PSCP" = "" ]
then
echo "You need to install pscp (apt-get install putty-tools)."
BIN_TO_INSTALL="yes"
fi
# Check if "beep" is installed
BEEP=`whereis -b beep | cut --delimiter=":" -f2 | cut --delimiter=" " -f2`
if [ "$BEEP" = "" ]
then
echo "You need to install beep (apt-get install beep)."
BIN_TO_INSTALL="yes"
fi
# Check if packages need to be installed
if [ "$BIN_TO_INSTALL" = "yes" ]
then
echo "You need to install thus packages before going further..."
exit 1
fi
# Make a subversion update
echo "Resync kiwix-plug code with the online git repository"
git pull origin master
# Check if should clean
if [ "$1" == "clean" ]
then
echo "Remove file before a new downoad"
rm -rf $ROOT/bin/kiwix* $ROOT/bin/.kiwix-*
rm -rf $ROOT/data/library/library.xml
rm -rf $ROOT/data/index/*.idx
fi
# Download GNU/Linux static (for kiwix-index)
if [ ! -f "$ROOT/bin/.kiwix.tar.bz2.finished" -o ! -f "$ROOT/bin/kiwix.tar.bz2" ]
then
rm -f "$ROOT/bin/.kiwix.tar.bz2.finished" "$ROOT/bin/kiwix.tar.bz2"
wget -c $KIWIX_X86_STATIC_URL -O "$ROOT/bin/kiwix.tar.bz2"
cd "$ROOT/bin/" ; tar -xvf "$ROOT/bin/kiwix.tar.bz2" ; cd ../
touch "$ROOT/bin/.kiwix.tar.bz2.finished"
fi
# Download ARM static (for the kiwix-serve to install)
if [ ! -f "$ROOT/bin/.kiwix-arm.tar.bz2.finished" -o ! -f "$ROOT/bin/kiwix-arm.tar.bz2" ]
then
rm -f "$ROOT/bin/.kiwix-arm.tar.bz2.finished" "$ROOT/bin/kiwix-arm.tar.bz2"
wget -c $KIWIX_ARM_STATIC_URL -O "$ROOT/bin/kiwix-arm.tar.bz2"
cd $ROOT/bin/ ; tar -xvf "$ROOT/bin/kiwix-arm.tar.bz2" ; cd ../
touch "$ROOT/bin/.kiwix-arm.tar.bz2.finished"
fi
# Download Kiwix for Windows
if [ ! -f "$ROOT/bin/.kiwix.zip.finished" -o ! -f "$ROOT/bin/kiwix.zip" ]
then
rm -f "$ROOT/bin/.kiwix.zip.finished" "$ROOT/bin/kiwix.zip"
wget -c $KIWIX_WINDOWS_URL -O "$ROOT/bin/kiwix.zip"
touch "$ROOT/bin/.kiwix.zip.finished"
fi
# Download Kiwix for OSX
if [ ! -f "$ROOT/bin/.kiwix.dmg.finished" -o ! -f "$ROOT/bin/kiwix.dmg" ]
then
rm -f "$ROOT/bin/.kiwix.dmg.finished" "$ROOT/bin/kiwix.dmg"
wget -c $KIWIX_OSX_URL -O "$ROOT/bin/kiwix.dmg"
touch "$ROOT/bin/.kiwix.dmg.finished"
fi
# Download Kiwix for Android
if [ ! -f "$ROOT/bin/.kiwix.apk.finished" -o ! -f "$ROOT/bin/kiwix.apk" ]
then
rm -f "$ROOT/bin/.kiwix.apk.finished" "$ROOT/bin/kiwix.apk"
wget -c $KIWIX_ANDROID_URL -O "$ROOT/bin/kiwix.apk"
touch "$ROOT/bin/.kiwix.apk.finished"
fi
# Download the sources
if [ ! -f "$ROOT/bin/.kiwix-src.tar.xz.finished" -o ! -f "$ROOT/bin/kiwix-src.tar.xz" ]
then
rm -f "$ROOT/bin/.kiwix-src.tar.xz.finished" "$ROOT/bin/kiwix-src.tar.xz"
wget -c $KIWIX_SRC_URL -O "$ROOT/bin/kiwix-src.tar.xz"
touch "$ROOT/bin/.kiwix-src.tar.xz.finished"
fi
# Rename the ZIM files by adding a "_" at the beginning
for FILE in `find "$ROOT/data/content/" -name "*.zim*" ; find "$ROOT/data/content/" -name "*.zimaa"`
do
DIRNAME=`dirname "$FILE"`
BASENAME=`basename "$FILE"`
if [ ${BASENAME:0:1} != "_" ]
then
mv "$FILE" "$DIRNAME/_$BASENAME"
fi
done
# Index all ZIM files
for ZIM in `find "$ROOT/data/content/" -name "*.zim" ; find "$ROOT/data/content/" -name "*.zimaa"`
do
ZIM=`echo "$ZIM" | sed -e s/\.zimaa/.zim/`
BASENAME=`echo "$ZIM" | sed -e "s/.*\///"`
IDX="$ROOT/data/index/$BASENAME.idx"
if [ -f "$IDX/.finished" ]
then
echo "Index of $ZIM already created"
else
echo "Indexing $ZIM at $IDX ..."
sleep 3
rm -rf "$IDX"
"$ROOT/bin/kiwix/bin/kiwix-index" --verbose --backend=xapian "$ZIM" "$IDX"
touch "$IDX/.finished"
fi
done
# Check if there is ZIM files in the /data/content
ZIMS=`find "$ROOT/data/content/" -name "*.zim" ; find "$ROOT/data/content/" -name "*.zimaa"`
if [ "$ZIMS" = "" ]
then
echo "Please put ZIM files in /data/content"
exit 1
else
for ZIM in `find -L "$ROOT/data/content/" -name "*.zim" -size +2G`
do
echo "Splitting $ZIM in parts of 2GB..."
split --bytes=2000M "$ZIM" "$ZIM"
rm "$ZIM"
done
fi
# Create the library file "library.xml"
LIBRARY="$ROOT/data/library/library.xml"
rm -f "$LIBRARY"
echo "Recreating library at '$LIBRARY'"
for ZIM in `find "$ROOT/data/content/" -name "*.zim" ; find "$ROOT/data/content/" -name "*.zimaa"`
do
ZIM=`echo "$ZIM" | sed -e s/\.zimaa/.zim/`
BASENAME=`echo "$ZIM" | sed -e "s/.*\///"`
IDX="$BASENAME.idx"
echo "Adding $ZIM to library.xml"
"$ROOT/bin/kiwix/bin/kiwix-manage" "$LIBRARY" add "$ZIM" --zimPathToSave="../content/$BASENAME" --indexBackend=xapian --indexPath="../index/$IDX"
done
# End music
beep -f 659 -l 460 -n -f 784 -l 340 -n -f 659 -l 230 -n -f 659 -l 110 -n -f 880 -l 230 -n -f 659 -l 230 -n -f 587 -l 230 -n -f 659 -l 460 -n -f 988 -l 340 -n -f 659 -l 230 -n -f 659 -l 110 -n -f 1047 -l 230 -n -f 988 -l 230 -n -f 784 -l 230 -n -f 659 -l 230 -n -f 988 -l 230 -n -f 1318 -l 230 -n -f 659 -l 110 -n -f 587 -l 230 -n -f 587 -l 110 -n -f 494 -l 230 -n -f 740 -l 230 -n -f 659 -l 460