guix-install.sh: Introduce 'die' utility function.

* etc/guix-install.sh (die): New function.
(chk_sys_arch): Use it.
(guix_get_bin_list, guix_get_bin, sys_create_store): Likewise.
This commit is contained in:
Maxim Cournoyer 2022-10-06 21:48:20 -04:00
parent 6a2e303d3a
commit 231e5f29ae
No known key found for this signature in database
GPG key ID: 1260E46482E63562

View file

@ -99,6 +99,12 @@ _flush()
done done
} }
die()
{
_err "${ERR}$*"
exit 1
}
# Return true if user answered yes, false otherwise. It defaults to "yes" # Return true if user answered yes, false otherwise. It defaults to "yes"
# when a single newline character is input. # when a single newline character is input.
# $1: The prompt question. # $1: The prompt question.
@ -230,8 +236,7 @@ chk_sys_arch()
local arch=powerpc64le local arch=powerpc64le
;; ;;
*) *)
_err "${ERR}Unsupported CPU type: ${arch}" die "Unsupported CPU type: ${arch}"
exit 1
esac esac
case "$os" in case "$os" in
@ -239,8 +244,7 @@ chk_sys_arch()
local os=linux local os=linux
;; ;;
*) *)
_err "${ERR}Your operation system (${os}) is not supported." die "Your operation system (${os}) is not supported."
exit 1
esac esac
ARCH_OS="${arch}-${os}" ARCH_OS="${arch}-${os}"
@ -295,8 +299,7 @@ guix_get_bin_list()
if [[ "${#bin_ver_ls}" -ne "0" ]]; then if [[ "${#bin_ver_ls}" -ne "0" ]]; then
_msg "${PAS}Release for your system: ${default_ver}" _msg "${PAS}Release for your system: ${default_ver}"
else else
_err "${ERR}Could not obtain list of Guix releases." die "Could not obtain list of Guix releases."
exit 1
fi fi
# Use default to download according to the list and local ARCH_OS. # Use default to download according to the list and local ARCH_OS.
@ -321,8 +324,7 @@ guix_get_bin()
"${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"; then "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"; then
_msg "${PAS}download completed." _msg "${PAS}download completed."
else else
_err "${ERR}could not download ${url}/${bin_ver}.tar.xz." die "could not download ${url}/${bin_ver}.tar.xz."
exit 1
fi fi
pushd "${dl_path}" >/dev/null pushd "${dl_path}" >/dev/null
@ -330,8 +332,7 @@ guix_get_bin()
_msg "${PAS}Signature is valid." _msg "${PAS}Signature is valid."
popd >/dev/null popd >/dev/null
else else
_err "${ERR}could not verify the signature." die "could not verify the signature."
exit 1
fi fi
} }
@ -343,8 +344,7 @@ sys_create_store()
_debug "--- [ ${FUNCNAME[0]} ] ---" _debug "--- [ ${FUNCNAME[0]} ] ---"
if [[ -e "/var/guix" || -e "/gnu" ]]; then if [[ -e "/var/guix" || -e "/gnu" ]]; then
_err "${ERR}A previous Guix installation was found. Refusing to overwrite." die "A previous Guix installation was found. Refusing to overwrite."
exit 1
fi fi
cd "$tmp_path" cd "$tmp_path"