Merge branch 'PR/more-robust-unpacking'

This commit is contained in:
Julian Ospald 2018-10-17 21:05:33 +08:00
commit 316fde7522
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28

52
ghcup
View File

@ -565,14 +565,47 @@ get_ghc_location() {
# @USAGE: <url>
# @DESCRIPTION:
# Downloads the given url as a file into the current directory.
# @RETURN: status code from the downloader
download() {
[ -z "$1" ] && die "Internal error: no argument given to download"
# shellcheck disable=SC2086
${DOWNLOADER} ${DOWNLOADER_OPTS} "$1"
return $?
edo ${DOWNLOADER} ${DOWNLOADER_OPTS} "$1"
}
# @FUNCTION: unpack
# @USAGE: <tarball>
# @DESCRIPTION:
# Uncompresses and unpacks the given tarball if needed by discovering the
# file extension.
unpack() {
[ -z "$1" ] && die "Internal error: no argument given to unpack"
filename=$1
file_ext=${filename##*.}
# this is for portability, since not all
# distros have tar with compression detection
# capability
case "${file_ext}" in
xz)
debug_message "xz -cd \"${filename}\" | tar -xf -"
( xz -cd "${filename}" | tar -xf - ; ) || die "unpacking failed!"
;;
gz)
debug_message "gzip -cd \"${filename}\" | tar -xf -"
( gzip -cd "${filename}" | tar -xf - ; ) || die "unpacking failed!"
;;
tar)
edo tar -xf "${filename}"
;;
*)
die "Unknown file extension: \"${file_ext}\""
esac
unset filename file_ext
}
############################
@ -608,9 +641,9 @@ install_ghc() {
(
edo cd "${tmp_dir}"
edo download "${download_url}"
download "${download_url}"
edo tar -xf ghc-*-linux.tar.xz
unpack "${download_tarball_name}"
edo cd "ghc-${myghcver}"
debug_message "Installing GHC into ${inst_location}"
@ -730,7 +763,7 @@ self_update() {
(
edo cd "$(mktemp -d)"
edo download "${SCRIPT_UPDATE_URL}"
download "${SCRIPT_UPDATE_URL}"
edo chmod +x ghcup
edo mv -f ghcup "${target_location}"/ghcup
@ -859,9 +892,10 @@ install_cabal() {
(
edo cd "$(mktemp -d)"
edo download "https://downloads.haskell.org/~cabal/cabal-install-${mycabalver}/cabal-install-${mycabalver}-${myarch}-unknown-linux.tar.gz"
edo tar -xzf "cabal-install-${mycabalver}-${myarch}-unknown-linux.tar.gz"
download "https://downloads.haskell.org/~cabal/cabal-install-${mycabalver}/cabal-install-${mycabalver}-${myarch}-unknown-linux.tar.gz"
unpack "cabal-install-${mycabalver}-${myarch}-unknown-linux.tar.gz"
edo mv -f cabal "${inst_location}"/cabal
rm "cabal-install-${mycabalver}-${myarch}-unknown-linux.tar.gz"
) || die "Failed to install cabal-install"
status_message "Successfully installed cabal-install into"
@ -914,7 +948,7 @@ compile_ghc() {
(
edo cd "${tmp_dir}"
edo download "${download_url}"
download "${download_url}"
edo tar -xf ghc-*-src.tar.xz
edo cd "ghc-${myghcver}"