From 976635b65f3ae70de96393a0ac1bc955ff827025 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Wed, 17 Oct 2018 15:39:51 +0800 Subject: [PATCH 1/2] More robust unpacking On some system, tar might not be able to automatically uncompress, so do it separately. --- ghcup | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/ghcup b/ghcup index 0ef9a97..aa40642 100755 --- a/ghcup +++ b/ghcup @@ -573,6 +573,41 @@ download() { return $? } +# @FUNCTION: unpack +# @USAGE: +# @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,7 +643,7 @@ install_ghc() { edo 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}" @@ -850,8 +885,9 @@ 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" + 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" From 869f306e359f6341059c8c6f97969de6628b85d9 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Wed, 17 Oct 2018 17:04:39 +0800 Subject: [PATCH 2/2] Move error handling into download() function This also makes the verbosity messages better. --- ghcup | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ghcup b/ghcup index aa40642..be27e84 100755 --- a/ghcup +++ b/ghcup @@ -565,12 +565,10 @@ get_ghc_location() { # @USAGE: # @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 @@ -641,7 +639,7 @@ install_ghc() { ( edo cd "${tmp_dir}" - edo download "${download_url}" + download "${download_url}" unpack "${download_tarball_name}" edo cd "ghc-${myghcver}" @@ -755,7 +753,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 @@ -884,7 +882,7 @@ install_cabal() { ( edo cd "$(mktemp -d)" - edo download "https://downloads.haskell.org/~cabal/cabal-install-${mycabalver}/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" @@ -940,7 +938,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}"