From 8ca8e6fa4d3a7dc1a40e958cfa4ca62096bfa509 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sun, 30 Nov 2014 20:44:03 -0800 Subject: [PATCH] rustup: factor out installing packages into a function --- src/etc/rustup.sh | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index 8ca2390dda5..311c1c3f15e 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -443,6 +443,18 @@ download_and_extract_package() { fi } +# Wrap all the commands needed to install a package. +install_package() { + install_script="$1" + + sh "${install_script}" "${CFG_INSTALL_FLAGS}" + if [ $? -ne 0 ] + then + rm -Rf "${CFG_TMP_DIR}" + err "failed to install Rust" + fi +} + rm -Rf "${CFG_TMP_DIR}" need_ok "failed to remove temporary installation directory" @@ -459,35 +471,10 @@ if [ -z "${CFG_DISABLE_CARGO}" ]; then "${CARGO_TARBALL_NAME}" fi - -(cd "${CFG_TMP_DIR}" && ${CFG_TAR} xzf "${RUST_TARBALL_NAME}") -if [ $? -ne 0 ] -then - rm -Rf "${CFG_TMP_DIR}" - err "failed to unpack installer" -fi - -sh "${RUST_LOCAL_INSTALL_SCRIPT}" "${CFG_INSTALL_FLAGS}" -if [ $? -ne 0 ] -then - rm -Rf "${CFG_TMP_DIR}" - err "failed to install Rust" -fi +install_package "${RUST_LOCAL_INSTALL_SCRIPT}" if [ -z "${CFG_DISABLE_CARGO}" ]; then - (cd "${CFG_TMP_DIR}" && ${CFG_TAR} xzf "${CARGO_TARBALL_NAME}") - if [ $? -ne 0 ] - then - rm -Rf "${CFG_TMP_DIR}" - err "failed to unpack cargo installer" - fi - - sh "${CARGO_LOCAL_INSTALL_SCRIPT}" "${CFG_INSTALL_FLAGS}" - if [ $? -ne 0 ] - then - rm -Rf "${CFG_TMP_DIR}" - err "failed to install Cargo" - fi + install_package "${CARGO_LOCAL_INSTALL_SCRIPT}" fi rm -Rf "${CFG_TMP_DIR}"