mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Adding in extract file logic.
This commit is contained in:
parent
7a684e7266
commit
c82dda45d9
1 changed files with 60 additions and 0 deletions
|
@ -109,6 +109,48 @@ download_file() {
|
||||||
return "${rcode}"
|
return "${rcode}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#--- FUNCTION ----------------------------------------------------------------
|
||||||
|
# NAME: extract_file
|
||||||
|
# DESCRIPTION: Extracts a file into a location. Attempts to determine which
|
||||||
|
# tool to use by checking file extention.
|
||||||
|
# PARAMETERS: $1 = file to extract
|
||||||
|
# $2 = location to extract file into
|
||||||
|
# $3 = extention
|
||||||
|
# RETURNS: Return code of the tool used to extract the file
|
||||||
|
# 2 = Failed to determine which tool to use
|
||||||
|
# 3 = Failed to find tool in path
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
extract_file() {
|
||||||
|
local file
|
||||||
|
local dir
|
||||||
|
local ext
|
||||||
|
local rcode
|
||||||
|
|
||||||
|
file="${1}"
|
||||||
|
dir="${2}"
|
||||||
|
ext="${3}"
|
||||||
|
|
||||||
|
case "${ext}" in
|
||||||
|
"zip" ) if command -v unzip >/dev/null 2>&1; then
|
||||||
|
unzip "${file}" -d "${dir}"
|
||||||
|
rcode="${?}"
|
||||||
|
else
|
||||||
|
rcode="3"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"tar.gz" ) if command -v tar >/dev/null 2>&1; then
|
||||||
|
tar -xf "${file}" -C "${dir}"
|
||||||
|
rcode="${?}"
|
||||||
|
else
|
||||||
|
rcode="3"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
* ) rcode="2";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return "${rcode}"
|
||||||
|
}
|
||||||
|
|
||||||
#--- FUNCTION ----------------------------------------------------------------
|
#--- FUNCTION ----------------------------------------------------------------
|
||||||
# NAME: main
|
# NAME: main
|
||||||
# DESCRIPTION: Put it all together in a logical way
|
# DESCRIPTION: Put it all together in a logical way
|
||||||
|
@ -183,6 +225,24 @@ main() {
|
||||||
else
|
else
|
||||||
echo "== Return code of download tool returned an unexpected value of ${download_file_rcode}"
|
echo "== Return code of download tool returned an unexpected value of ${download_file_rcode}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
extract_file "${tmpdir}/${croc_file}" "${tmpdir}/" "${croc_dl_ext}"
|
||||||
|
extract_file_rcode="${?}"
|
||||||
|
if [[ "${extract_file_rcode}" == "0" ]]; then
|
||||||
|
echo "== Extracted ${croc_file} to ${tmpdir}/"
|
||||||
|
elif [[ "${extract_file_rcode}" == "1" ]]; then
|
||||||
|
echo "== Failed to extract ${croc_file}"
|
||||||
|
exit 1
|
||||||
|
elif [[ "${extract_file_rcode}" == "2" ]]; then
|
||||||
|
echo "== Failed to determine which extraction tool to use"
|
||||||
|
exit 1
|
||||||
|
elif [[ "${extract_file_rcode}" == "3" ]]; then
|
||||||
|
echo "== Failed to find extraction tool in path"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "== Unknown error returned from extraction attempt"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue