2012-01-02 12:40:32 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# Copyright 2010-2011, Asio Software Technologies
|
|
|
|
# Distributed under the terms of the GNU General Public License v3
|
|
|
|
|
|
|
|
|
2012-01-02 15:06:52 +01:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Downloads files into specified or current directory
|
|
|
|
# Parameters: %url% %directory%
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
function download() {
|
|
|
|
local DEST="${2}"
|
|
|
|
local FILENAME="${1##*/}"
|
|
|
|
local URL="${1}"
|
|
|
|
if isSet DEST; then
|
|
|
|
local DEST="${DEST}/${FILENAME}"
|
|
|
|
else
|
|
|
|
local DEST="./${FILENAME}"
|
|
|
|
fi
|
|
|
|
echo -ne " ${STAR_GREEN} ${FILENAME}: "
|
|
|
|
wget --progress=dot -c -t ${FETCHTRIES} -T ${FETCHTIMEOUT} -O "${DEST}" \
|
|
|
|
${URL} 2>&1 | grep --line-buffered "%" | sed -u -e "s/[\.\,]//g" | \
|
|
|
|
awk '{printf("\b\b\b\b%4s", $2)}'
|
|
|
|
local RESULT=${PIPESTATUS[0]}
|
|
|
|
echo -ne "\b\b\b\b"
|
|
|
|
if [[ ${RESULT} -ne 0 ]]; then
|
|
|
|
logOutput "Unable to download ${URL}! Exit code: ${RESULT}"
|
|
|
|
echo -e "${COLOR_RED}${COLOR_BOLD}ERROR${COLOR_WHITE}${COLOR_NORMAL}"
|
|
|
|
else
|
|
|
|
echo -e "${COLOR_GREEN}${COLOR_BOLD}DONE${COLOR_WHITE}${COLOR_NORMAL}"
|
|
|
|
fi
|
|
|
|
return ${RESULT}
|
|
|
|
}
|
|
|
|
|
2012-01-02 12:40:32 +01:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Creates all components of the specified directories
|
|
|
|
# Parameters: %directory%
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
function makeDirectory() {
|
2012-01-02 13:06:07 +01:00
|
|
|
local OUTPUT=$(install -d "${@}" 2>&1)
|
|
|
|
local RESULT=${?}
|
2012-01-02 12:40:32 +01:00
|
|
|
if [[ ${RESULT} -ne 0 ]]; then
|
|
|
|
logOutput "${OUTPUT}"
|
|
|
|
fi
|
|
|
|
return ${RESULT}
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Creates a symbolic link between to files in specified target directory
|
|
|
|
# Parameters: %source% %target%
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
function makeLink() {
|
2012-01-02 13:06:07 +01:00
|
|
|
local DESTDIR="${2%/*}"
|
2012-01-02 12:40:32 +01:00
|
|
|
[[ ! -d ${DESTDIR} ]] && makeDirectory "${DESTDIR}"
|
2012-01-02 13:06:07 +01:00
|
|
|
local OUTPUT=$(ln -sfn "${1}" "${2}" 2>&1)
|
|
|
|
local RESULT=${?}
|
2012-01-02 12:40:32 +01:00
|
|
|
if [[ ${RESULT} -ne 0 ]]; then
|
|
|
|
logOutput "${OUTPUT}"
|
|
|
|
fi
|
|
|
|
return ${RESULT}
|
|
|
|
}
|