Skip to content

Commit 0bad428

Browse files
authored
Merge pull request #188 from cassiosantos/check-file-before-extract
Check file before decompress
2 parents f7ad786 + 44a10df commit 0bad428

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

tools/download_wiki_index.sh

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
11
#!/bin/bash
22

3-
if [ ! -d wiki_indri_index ];
4-
then
5-
wget http://web.eecs.umich.edu/~jahausw/download/wiki_indri_index.tar.gz
3+
if [ -d wiki_indri_index ]; then
4+
echo "Wikipedia index already downloaded, skipping"
5+
exit 1
6+
else
7+
echo "Wikipedia index not found: OK"
8+
fi
9+
10+
FREE=`df -k --output=avail "$PWD" | tail -n1`
11+
if [[ $FREE -lt 11523524 ]]; then
12+
read -p "Not enough space to download. Do you want to continue (Y/n)? " -n 1 -r
13+
if [[ ! $REPLY =~ ^[Yy]$ ]]
14+
then
15+
echo ""
16+
echo "Aborting."
17+
exit 1
18+
fi
19+
echo ""
20+
else
21+
echo "Enough space to download.: OK"
22+
fi;
23+
24+
echo "Starting download."
25+
26+
wget -c http://web.eecs.umich.edu/~jahausw/download/wiki_indri_index.tar.gz
27+
28+
if [ $? -ne 0 ]; then
29+
echo "wget return code.........: FAIL"
30+
echo "wget exited with nonzero return, please retry"
31+
exit 1;
32+
else
33+
echo "wget return code.........: OK"
34+
fi
35+
36+
FILECHECKSUM="322ae59fd0473c6d055ea827ce791c758be1d632e67956ae385eed77aff2f4f3e84db2643e90845b35e1b6204822e9e6"
37+
38+
echo "Download completed. Checking file."
39+
if [ "$(sha384sum wiki_indri_index.tar.gz | cut -d' ' -f1)" == $FILECHECKSUM ]; then
40+
echo "sha384sum check..........: OK"
41+
echo "Decompressing data"
642
tar xzvf wiki_indri_index.tar.gz
743
else
8-
echo "Wikipedia index already downloaded, skipping"
44+
echo "sha384sum check..........: FAIL"
45+
echo "Broken download:"
46+
echo "- Delete the file wiki_indri_index.tar.gz"
47+
echo "- Run this script again"
948
fi
1049

1150
echo "******************************************************"

0 commit comments

Comments
 (0)