|
1 |
| -#bin/bash |
| 1 | +#!/bin/bash |
2 | 2 |
|
| 3 | +# ____ __ __ |
| 4 | +# / __ \___ _ __/ / / /___ __ __________ |
| 5 | +# / / / / _ \ | / / /_/ / __ \/ / / / ___/ _ \ |
| 6 | +# / /_/ / __/ |/ / __ / /_/ / /_/ (__ ) __/ |
| 7 | +# /_____/\___/|___/_/ /_/\____/\__,_/____/\___/ . com . br |
| 8 | +# |
| 9 | +# Created by Leonardo Lima de Vasconcellos on 08-19-2012 |
| 10 | + |
| 11 | +# |
| 12 | +# * This script requires bash 4 or later |
| 13 | +# |
| 14 | + |
| 15 | +# Default language is English |
| 16 | +language="en" |
3 | 17 |
|
| 18 | +# if system language is Portuguese then set language to portuguese |
| 19 | +if [ `expr match "$LANG" "pt_BR"` -gt 0 ] || [ `expr match "$LANG" "pt_PT"` -gt 0 ] ; then |
| 20 | + language="pt" |
| 21 | +fi |
4 | 22 |
|
5 |
| -if |
| 23 | +# definition of messages |
| 24 | +if [ "$language" == "pt" ] ; then |
| 25 | + declare -A messages=( |
| 26 | + ["error_no_arguments"]="\n\033[1;31mFaltam argumentos.\033[0m\n\n\tUso:\n\n\t$ wgetmd5 url_arquivo url_arquivo_md5\n\n" |
| 27 | + ["download_started"]="\n\n\033[1;32mIniciando download...\033[0m\n\n" |
| 28 | + ["download_success"]="\n\n\033[1;32mDownload concluido com sucesso!\033[0m\n\n" |
| 29 | + ["download_fail"]="\n\n\033[1;31mDownload corrompido!\033[0m\n\n" |
| 30 | + ) |
| 31 | +else |
| 32 | + declare -A messages=( |
| 33 | + ["error_no_arguments"]="\n\033[1;31mArgument missing.\033[0m\n\n\tUsage:\n\n\t$ wgetmd5 file_url md5_file_url\n\n" |
| 34 | + ["download_started"]="\n\n\033[1;32mStarting download...\033[0m\n\n" |
| 35 | + ["download_success"]="\n\n\033[1;32mDownload successful!\033[0m\n\n" |
| 36 | + ["download_fail"]="\n\n\033[1;31mDownload corrupted!\033[0m\n\n" |
| 37 | + ) |
| 38 | +fi |
6 | 39 |
|
| 40 | +# if no arguments print usage message |
7 | 41 | if [ ! $1 ] && [ ! $2 ] ; then
|
8 |
| - echo "Strings \"$1\" and \"$2\" are null." |
9 |
| - exit 1 |
| 42 | + echo -e ${messages["error_no_arguments"]} |
| 43 | + exit 1 |
10 | 44 | fi
|
11 | 45 |
|
12 |
| -# echo "O arquivo para download é: $1"; |
| 46 | + |
| 47 | +# extract file names |
| 48 | +filename=`basename $1` |
| 49 | +md5filename=`basename $2` |
| 50 | + |
| 51 | +# start download |
| 52 | +echo -e ${messages["download_started"]} |
| 53 | +wget $1 $2 |
| 54 | + |
| 55 | +# check md5sum from downloaded file |
| 56 | +md5test=`md5sum "$filename" | awk '{print $1}'` |
| 57 | + |
| 58 | +# extract md5sum string from downloaded md5 file |
| 59 | +md5string=`cat "$md5filename" | awk '{print $1}'` |
| 60 | + |
| 61 | +# if strings match then download ok |
| 62 | +if [ "$md5test" == "$md5string" ] ; then |
| 63 | + echo -e ${messages["download_success"]} |
| 64 | + echo -e "$md5test" "==" "$md5string" "\n\n" |
| 65 | + exit 0 |
| 66 | +else |
| 67 | + echo -e ${messages["download_fail"]} |
| 68 | + echo -e "$md5test" "!=" "$md5string" "\n\n" |
| 69 | + exit 1 |
| 70 | +fi |
0 commit comments