First commit

This commit is contained in:
Yorick Barbanneau 2018-04-27 16:13:59 +02:00
commit c9b7172d6a
50 changed files with 1214 additions and 0 deletions

24
lib/download.sh Normal file
View file

@ -0,0 +1,24 @@
#!/bin/bash
download (){
#Download function
# $1 : filename
# $2 : url
message "\nDownloading $1 : "
http_response=$(wget --spider --server-response $2/$1 2>&1 | grep HTTP/ | tail -1 | awk ' { printf $2 }')
if [[ $http_response -eq 200 ]]
then
wget -c --progress=dot $2/$1 2>&1 | grep --line-buffered "[0-9]\{1,3\}%" -o | awk '{printf ("\b\b\b\b%4s", $1)}'
if [ $? -eq 0 ]
then
message " \b\b\b\b\b done\n " "ok"
else
message " \b\b\b\b\b error.\n" "ok"
exit 1
fi
else
message "\b\b\b\b\b Error 404\n" "err"
exit 1
fi
}

38
lib/messages.sh Normal file
View file

@ -0,0 +1,38 @@
#/bin/bash
#
# message ()
# ----------
#
# External library to display colored messages
#
message () {
local red=$'\e[1;31m'
local grn=$'\e[1;32m'
local yel=$'\e[1;33m'
local blu=$'\e[1;34m'
local mag=$'\e[1;35m'
local cyn=$'\e[1;36m'
local end=$'\e[0m'
case $2 in
"err")
printf "%s${1}%s" "${red}" "${end}"
exit 1
;;
"warn")
printf "%s${1}%s" "${yel}" "${end}"
;;
"ok")
printf "%s${1}%s" "${grn}" "${end}"
;;
"bold")
printf "\e[1m${1}%s" "${end}"
;;
"info")
printf "%s${1}%s" "${mag}" "${end}"
;;
*)
printf "${1}"
esac
}