Skip to content

Commit

Permalink
beesh: Add generic extraction functio bee_extract_do
Browse files Browse the repository at this point in the history
  • Loading branch information
mariux committed Feb 28, 2013
1 parent 56270a9 commit c1c65da
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/beesh.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,39 @@ function bee_extract_do_tar0() {
bee_extract_do_tar "${@}" --strip-components "${BEE_EXTRACT_STRIP}"
}

function get_or_guess_mimetype() {
local file="${1}"
local mimetype=""

if ! mimetype=$(file --mime --brief "${file}" 2>/dev/null) ; then
if [ "${file: -4}" = ".zip" ] ; then
mimetype="application/zip"
fi
fi

echo ${mimetype%%;*}
}

function bee_extract_do() {
local file="${1}"
local dest="${2}"
local mode="${3}"
local mimetype=""

shift 3

mimetype=$(get_or_guess_mimetype "${file}")

if [ "${mimetype}" = "application/zip" ] ; then
print_error "zip extraction not yet implemented"
fi

if [ "${mode}" = "primary" ] ; then
bee_extract_do_tar0 "${file}" "${dest}"
else
bee_extract_do_tar "${file}" "${dest}"
fi
}

function bee_extract() {
local bee_S
Expand All @@ -397,11 +430,11 @@ function bee_extract() {
unset bee_S[0]

print_info " -> extracting main source ${s} .."
bee_extract_do_tar0 "${s}" "${S}"
bee_extract_do "${s}" "${S}" "primary"

for s in ${bee_S[@]} ; do
print_info " -> extracting additional source ${s} .."
bee_extract_do_tar "${s}" "${S}"
bee_extract_do "${s}" "${S}" "secondary"
done

print_info " -> all sources extracted to: ${S} .."
Expand Down

0 comments on commit c1c65da

Please sign in to comment.