ezbuild/libraries/filesystem

115 lines
3.4 KiB
Plaintext
Raw Normal View History

2012-01-02 12:40:32 +01:00
#!/bin/bash
2012-01-03 11:29:52 +01:00
# Copyright 2010-2012, Asio Software Technologies
2012-01-02 12:40:32 +01:00
# Distributed under the terms of the GNU General Public License v3
2012-01-03 14:48:00 +01:00
#-------------------------------------------------------------------------------
# Completely removes log files
#-------------------------------------------------------------------------------
function cleanLogs() {
rm -rf ${LOGFILE} &> /dev/null
}
#-------------------------------------------------------------------------------
# Completely removes temp directory
#-------------------------------------------------------------------------------
function cleanTemp() {
rm -rf ${TEMPDIR} &> /dev/null
}
#-------------------------------------------------------------------------------
# Downloads files into specified or current directory
# Parameters: %url% %directory%
#-------------------------------------------------------------------------------
function download() {
local DEST FILENAME RESULT URL
DEST="${2}"
FILENAME="${1##*/}"
URL="${1}"
if isSet DEST; then
DEST="${DEST}/${FILENAME}"
else
DEST="./${FILENAME}"
fi
2012-01-02 23:38:22 +01:00
logMessage "Downloading ${URL} to ${DEST}" "DEBUG"
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)}'
RESULT=${PIPESTATUS[0]}
echo -ne "\b\b\b\b"
2012-01-02 23:01:22 +01:00
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() {
local OUTPUT RESULT
OUTPUT=$(install -d "${@}" 2>&1)
RESULT=${?}
if [ ${RESULT} -ne 0 ]; then
2012-01-02 12:40:32 +01:00
logOutput "${OUTPUT}"
fi
return ${RESULT}
}
#-------------------------------------------------------------------------------
# Creates a symbolic link between to files in specified target directory
# Parameters: %source% %target%
#-------------------------------------------------------------------------------
function makeLink() {
local DESTDIR OUTPUT RESULT
DESTDIR="${2%/*}"
2012-01-02 12:40:32 +01:00
[[ ! -d ${DESTDIR} ]] && makeDirectory "${DESTDIR}"
OUTPUT=$(ln -sfn "${1}" "${2}" 2>&1)
RESULT=${?}
2012-01-02 23:01:22 +01:00
if [ ${RESULT} -ne 0 ]; then
2012-01-02 12:40:32 +01:00
logOutput "${OUTPUT}"
fi
return ${RESULT}
}
2012-01-03 10:32:12 +01:00
#-------------------------------------------------------------------------------
# Extracts any tar based archive into specified directory
# Parameters: %tarball% %destination%
#-------------------------------------------------------------------------------
function unpack() {
local DST EXT OUTPUT RESULT SRC
SRC="${1}"
DST="${2}"
EXT=$(toLower "${SRC##*.}")
if [ ! -d ${DST} ]; then
makeDirectory ${DST} || return 1
fi
case "${EXT}" in
bz2)
if [ -e /usr/bin/pbzip2 ]; then
OUTPUT=$(pbzip2 -dc "${SRC}" 2>&1 | tar xpf - -C "${DST}" 2>&1)
else
OUTPUT=$(tar xjpf "${SRC}" -C "${DST}" 2>&1)
fi
RESULT=${?}
;;
gz|xz|z)
OUTPUT=$(tar xpf "${SRC}" -C "${DST}" 2>&1)
RESULT=${?}
;;
*)
OUTPUT="Unrecognized source compression for ${SRC}"
RESULT=1
;;
esac
if [ ${RESULT} -ne 0 ]; then
logOutput "${OUTPUT}"
fi
return ${RESULT}
}