-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_downloader.sh
More file actions
executable file
·376 lines (337 loc) · 12.4 KB
/
dump_downloader.sh
File metadata and controls
executable file
·376 lines (337 loc) · 12.4 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/bin/bash
# Determin OS
help=false
skip_install=false
keep_data=false
output_dir=$(pwd)
jar_location=$(pwd)/Converter/out/artifacts/converter_main_jar/converter_main.jar
clear
echo "This program runs under following license:"
echo ""
echo ""
echo ""
echo "-------------------------------------------"
echo "-------------------------------------------"
less -FX ./LICENSE
echo "-------------------------------------------"
echo "-------------------------------------------"
echo ""
echo ""
echo ""
echo "Please state:"
echo "I HAVE READ AND ACCEPT THE LICENSE AGREEMENT"
echo "by typing: yes"
read -r confirm
if [ "$confirm" != "yes" ]; then
exit 499
fi
clear
# Check options
for option in "$@"
do
if [ "$option" == "-h" ] || [ "$option" == "-help" ]; then
help=true
elif [ "$option" == "-s" ] || [ "$option" == "-skip_install" ]; then
skip_install=true
elif [ "$option" == "-k" ] || [ "$option" == "-keep_data" ]; then
keep_data=true
elif [ $( echo "$option" |cut -d '=' -f1 ) == "-output_dir" ]; then
output_dir=$( echo "$option" |cut -d '=' -f2 )
if [ ! -d "$output_dir" ]; then
echo ""
echo "$output_dir not found. Please make sure it exists and your parameter fullfills follwing form: "
echo "<folder>/.../<subfolder>"
help=true
fi
else
echo ""
echo "Unkown option $option. Help will be automatically printed"
help=true
fi
done
# Print help if required
if [ "$help" == true ]; then
clear
echo "Printing help file:"
echo ""
echo 'Options:'
echo '-------------------'
echo '-skip_install, -s: Skip automatic installation of requirements'
echo '-keep_everything, -k: Keep intermediate .csv Datasets.'
echo '-output_dir=<path>: Write output files (RDF Files, Logs, control files) to <path>'
echo '-------------------'
echo -e '-h , -help: Print help file'
else
# Skip install if required
if ( ! "$skip_install" == true ); then
clear
echo "Installing dependencies if required"
echo "------------------"
if ( ! $( which apt ) != "" ) ; then
command="sudo apt-get install"
echo "Auto-detected: apt - package manager"
elif ( ! $( which pacman ) != "" ) ; then
command="sudo pacman -S"
echo "Auto-detected: pacman - package manager"
elif ( ! $( yum apt ) != "" ) ; then
command="sudo yum install"
echo "Auto-detected: yum - package manager"
elif ( ! $( which zipper ) != "" ) ; then
command="sudo zipper install"
echo "Auto-detected: zipper - package manager"
else
echo "no package-manager auto-detected. Please check if following dependencies are met: "
echo "curl"
echo "java"
echo "pigz"
break
fi
echo "------------------"
#Check dependencies
while [ ! $( which curl ) != "" ]; do
echo ""
echo "Package curl not found. Do you want to execute:"
echo "-------------------------"
echo $command " curl [Y/N]"
echo "-------------------------"
echo "If you choose 'N' this programm will terminate and you have to install it manually"
read confirm
if [ "$confirm" == "Y" ]; then
$command curl
if [ $(which curl) == '' ]; then
echo "Something went wrong during the installation."
fi
else
exit 499
fi
done;
while [ ! $( which pigz ) != "" ]; do
echo ""
echo "Package pigz not found. Do you want to execute:"
echo "-------------------------"
echo $command " pigz [Y/N]"
echo "-------------------------"
echo "If you choose 'N' this programm will terminate and you have to install it manually"
read confirm
if [ "$confirm" == "Y" ]; then
$command pigz
if [ $(which pigz) == '' ]; then
echo "Something went wrong during the installation."
fi
else
exit 499
fi
done;
while [ ! $( which java ) != "" ]; do
echo ""
echo "No java runtime environment found in the systems path variable. Do you want to execute:"
echo "-------------------------"
echo $command "default-jre [Y/N]"
echo "-------------------------"
echo "If you choose 'N' this programm will terminate and you have to install it manually"
read confirm
if [ "$confirm" == "Y" ]; then
$command default-jre
if [ $(which java) == '' ]; then
echo "Something went wrong during the installation."
fi
else
exit 499
fi
done;
fi
#Check for required folders etc, create log file in output_dir
if [ ! -d "$output_dir/ghtorrent.com" ]; then
mkdir "$output_dir/ghtorrent.com/"
fi
if [ ! -d "$output_dir/logs" ]; then
mkdir "$output_dir/logs"
fi
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
log="$output_dir/logs/log_$timestamp"
#Download overview from ghtorrent.com
clear
curl http://ghtorrent.org/downloads.html > $output_dir/ghtorrent.com/ghtorrent_new
grep 'http://ghtorrent-downloads.ewi.tudelft.nl/mysql' $output_dir/ghtorrent.com/ghtorrent_new > $output_dir/ghtorrent.com/ghtorrent_links
curl_exit_code=$?
if [ "$curl_exit_code" == "0" ]; then
clear
echo "Following files are available for Download:"
echo "-------------------------"
count_files=0
while IFS= read -r line; do
str_link=$( echo "$line" |cut -d '"' -f2 )
str_file_name=$( echo "$str_link"| cut -s -d/ -f5)
str_folder_name=$( echo "$str_file_name"| cut -s -d "." -f1)
str_size=$( echo "$line"| cut -s -d "(" -f2 |cut -s -d " " -f1)
if [[ ! (($str_folder_name =~ "2013") || ($str_folder_name =~ "2014") || ($str_folder_name =~ "2015")) ]]; then
count_files=$((count_files+1))
echo "$count_files) $str_file_name"
fi
done <<< "$(tac $output_dir/ghtorrent.com/ghtorrent_links)"
else
echo ""
echo "An Error with curl occured. Please check your internet connection"
exit 503
fi
# Choose dump to be downloaded
echo "-------------------------"
echo "Which dump do you want to download ? (Example: Type 13 for dump mysql-2017-01-19.tar.gz)"
read -r dump_no
echo ""
count_files=0
found=false
while IFS= read -r line; do
str_link=$( echo "$line" |cut -d '"' -f2 )
str_file_name=$( echo "$str_link"| cut -s -d/ -f5)
str_folder_name=$( echo "$str_file_name"| cut -s -d "." -f1)
str_size=$( echo "$line"| cut -s -d "(" -f2 |cut -s -d " " -f1)
if [[ ! (($str_folder_name =~ "2013") || ($str_folder_name =~ "2014") || ($str_folder_name =~ "2015")) ]]; then
count_files=$((count_files+1))
if [[ "$dump_no" == "$count_files" ]]; then
found=true
break
fi
fi
done <<< "$(tac $output_dir/ghtorrent.com/ghtorrent_links)"
echo $found
if [ "$found" == false ]; then
echo "Input not recognized"
exit 400
fi
# Ask user about confirmation for processing
processing_size=$(expr $str_size \* 8 / 1024)
final_size=$(expr $str_size \* 4 / 1024 )
folder_available=$(expr $(df -k $output_dir | cut -d ' ' -f4) / 1024 / 1024)
clear
echo "For the processing of $str_file_name we estimate a requirement of:"
echo "-------------------------"
echo "Processing space: $processing_size GiB "
echo "Output Space: $final_size GiB "
echo "-------------------------"
echo "The target directory has about $folder_available GiB of available space."
echo ""
echo ""
echo "WARNINGS:"
echo "- Having not enough available space for the processing, may harm your system"
echo ""
echo "NOTES:"
echo "- The following steps consist of Downloading, Extracting and Transforming the data."
echo "- In dependence of your download speed and system resources each step can take several hours"
echo "- If you want to abort the script, the result of each uncompleted step is lost."
echo "- If you rerun the dump_downloader, it will continue with the last successfull step"
echo "- "
echo "Do you really want to continue? [Y/N]"
read -r confirm_processing
if [ $confirm_processing != "Y" ]; then
exit 499
else
#Prepare Folders and Files
clear
str_folder_name="$output_dir/$str_folder_name"
if [ ! -d "$str_folder_name" ]; then
mkdir "$str_folder_name"
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- Folder: $str_folder_name created" >> $log
fi
# Save information from the ghtorrent website in the folder
echo "$str_link" > "$str_folder_name/SG_LINK"
echo "$str_file_name" > "$str_folder_name/SG_FNAME"
echo "$str_size" > "$str_folder_name/SG_FSIZE"
# Check if file is already downlaoded
if [ ! -f "$str_folder_name/SG_DOWNLOAD_DONE" ]; then
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- Folder: $str_folder_name no SG_DOWNLOAD_DONE" >> $log
if [ -f "$str_folder_name/$str_file_name" ]; then
rm $str_folder_name/$str_file_name
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- File: removing $str_folder_name/$str_file_name" >> $log
fi
curl -o "$str_folder_name/$str_file_name" "$str_link"
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- File: Downloading $str_folder_name/$str_file_name" >> $log
curl_exit_code=$?
if [ "$curl_exit_code" == "0" ]; then
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- File: Downloading $str_folder_name/$str_file_name sucseeded" >> $log
tar -tzf "$str_folder_name/$str_file_name" >/dev/null
tar_exit_code=$?
if [ "$tar_exit_code" == "0" ]; then
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "" > "$str_folder_name/SG_DOWNLOAD_DONE"
echo "$timestamp --- File: $str_folder_name/$str_file_name is extractable" >> $log
echo "$timestamp --- File: Creating $str_folder_nam/SG_DOWNLOAD_DONE" >> $log
fi
fi
else
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- File: $str_folder_name/$str_file_name already Downloaded" >> $log
fi
# Start processing if last processing did not suceeded
if [ -f "$str_folder_name/SG_DOWNLOAD_DONE" ] && [ ! -f "$str_folder_name/SG_PROCESSING_DONE" ]; then
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#Check validity
if [ -d "$str_folder_name" ] ; then
cd "$str_folder_name"
if [ -f "SG_PROCESSING_DONE" ]; then
exit 0
fi
if [ -f "SG_DOWNLOAD_DONE" ] && [ ! -f "SG_UNPACKING_DONE" ]; then
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- Starting Extraction" >> $log
tar -I pigz -xvf "$str_file_name" >> $log
tar_exit_code=$?
if [ "$tar_exit_code" == "0" ]; then
echo "" > "SG_UNPACKING_DONE"
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- Unpacking finished successfully" >> $log
else
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- Tar exit code: $tar_exit_code" >> $log
exit 3
fi
elif [ ! -f "SG_UNPACKING_DONE" ]; then
echo "Downloaded-File not found. This message should never appear."
exit 2
fi
if [ -f "SG_UNPACKING_DONE" ] ; then
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- Starting Conversion" >> $log
for d in */ ; do
java -jar "$jar_location" "$d" -debug >> $log 2>&1 ; java_exit_code=$?
done
if [ "$java_exit_code" == "0" ]; then
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
if [ "$keep_data" == false ]; then
echo "$timestamp --- Translation sucseeded. Removing .csv and unused .ttl ." >> $log
echo "$timestamp --- Translation sucseeded. Removing .csv and unused .ttl ."
rm **/* >/dev/null 2>&1
else
echo "$timestamp --- Translation sucseeded. Removing .ttl. Please remove all .csv manually if needed." >> $log
echo "$timestamp --- Translation sucseeded. Removing .ttl. Please remove all .csv manually if needed."
fi
echo "" > "SG_PROCESSING_DONE"
elif [ "$java_exit_code" == "2" ]; then
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- Translation sucseeded partially, as some input lines are corrupted. Please remove all .csv manually if needed." >> $log
echo "$timestamp --- Translation sucseeded partially, as some input lines are corrupted. Please remove all .csv manually if needed."
echo "" > "SG_PROCESSING_DONE"
else
timestamp=`date "+%Y_%m_%d_%H_%M_%S"`
echo "$timestamp --- Translation did not sucseed. Check for Java Errors" >> $log
echo "$timestamp --- Translation did not sucseed. Check for Java Errors"
exit 4
fi
fi
else
echo "Faulty Parameters set."
exit 1
fi
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#--------------------------------------------------------------------
fi
fi
fi