From e3cf26f48628c39e55aa7c47bc38aef9be234742 Mon Sep 17 00:00:00 2001 From: David Parrish Date: Wed, 9 Feb 2022 09:15:10 -0500 Subject: [PATCH] Apply shellcheck all current shellcheck suggestions --- install.sh | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/install.sh b/install.sh index 669c703c1..094232172 100755 --- a/install.sh +++ b/install.sh @@ -8,7 +8,7 @@ check_exists() { if check_exists gmake; then make=gmake else - make=make + make="make" fi sha256_verify () @@ -76,20 +76,20 @@ deps_install () deb_deps_check () { - apt-cache policy ${deb_deps[@]} | grep "Installed.*none" + apt-cache policy "${deb_deps[@]}" | grep "Installed.*none" } deb_deps_install () { - deb_deps=( ${@} ) + deb_deps=( "${@}" ) if deb_deps_check; then clear echo " sudo password required to run : - \`apt-get install ${deb_deps[@]}\` + \`apt-get install " "${deb_deps[@]}" "\` " - if ! sudo apt-get install ${deb_deps[@]}; then + if ! sudo apt-get install "${deb_deps[@]}"; then return 1 fi fi @@ -97,8 +97,8 @@ deb_deps_install () dar_deps_install () { - dar_deps=( ${@} ) - if ! brew install ${dar_deps[@]}; then + dar_deps=( "${@}" ) + if ! brew install "${dar_deps[@]}"; then return 1 fi echo " @@ -114,7 +114,7 @@ dar_deps_install () check_skip_build () { if [[ ${reinstall} == false ]] && [[ -d "$1" ]]; then - read -p "Directory ${1} exists. Remove and recreate? (y/n) " q + read -r -p "Directory ${1} exists. Remove and recreate? (y/n) " q if [[ "${q}" =~ Y|y ]]; then rm -rf "./${1}" mkdir -p "./${1}" @@ -145,7 +145,7 @@ dep_get () { pkg_name="$1" pkg_hash="$2" pkg_url="$3" - pushd cache + pushd cache || return 1 if [ ! -f "${pkg_name}" ] || ! sha256_verify "${pkg_hash}" "${pkg_name}"; then http_get "${pkg_url}/${pkg_name}" "${pkg_name}" fi @@ -153,7 +153,7 @@ dep_get () return 1 fi tar -xzf "${pkg_name}" -C ../ - popd + popd || return 1 } # add '--disable-docs' to libffi ./configure so makeinfo isn't needed @@ -218,7 +218,7 @@ libffi_install () if ! dep_get "${libffi_lib_tar}" "${libffi_lib_sha}" "${libffi_url}"; then return 1 fi - pushd "${libffi_version}" + pushd "${libffi_version}" || return 1 if ! libffi_patch_disable_docs; then return 1 fi @@ -227,7 +227,7 @@ libffi_install () else return 1 fi - popd + popd || return 1 } libsecp256k1_build() @@ -260,13 +260,13 @@ libsecp256k1_install() if ! dep_get "${secp256k1_lib_tar}.tar.gz" "${secp256k1_lib_sha}" "${secp256k1_lib_url}"; then return 1 fi - pushd "secp256k1-${secp256k1_lib_tar}" + pushd "secp256k1-${secp256k1_lib_tar}" || return 1 if libsecp256k1_build; then $make install else return 1 fi - popd + popd || return 1 } libsodium_build () @@ -298,13 +298,13 @@ libsodium_install () if ! dep_get "${sodium_lib_tar}" "${sodium_lib_sha}" "${sodium_url}"; then return 1 fi - pushd "${sodium_version}" + pushd "${sodium_version}" || return 1 if libsodium_build; then $make install else return 1 fi - popd + popd || return 1 } joinmarket_install () @@ -315,7 +315,7 @@ joinmarket_install () reqs+=( 'gui.txt' ) fi - for req in ${reqs[@]}; do + for req in "${reqs[@]}"; do pip install -r "requirements/${req}" || return 1 done @@ -324,7 +324,7 @@ joinmarket_install () echo "Installing XDG desktop entry" cp -f "$(dirname "$0")/docs/images/joinmarket_logo.png" \ ~/.local/share/icons/ - cat "$(dirname "$0")/joinmarket-qt.desktop" | \ + < "$(dirname "$0")/joinmarket-qt.desktop"\ sed "s/\\\$JMHOME/$(dirname "$(realpath "$0")" | sed 's/\//\\\//g')/" > \ ~/.local/share/applications/joinmarket-qt.desktop fi @@ -336,7 +336,7 @@ parse_flags () while :; do case $1 in --develop) - develop_build='1' + # Currently this flag does nothing. ;; --disable-os-deps-check) use_os_deps_check='0' @@ -371,7 +371,7 @@ parse_flags () ;; *) echo " -Usage: "${0}" [options] +Usage: ${0} [options] Options: @@ -389,7 +389,7 @@ Options: done if [[ ${with_qt} == '' ]]; then - read -p " + read -r -p " INFO: Joinmarket-Qt for GUI Taker and Tumbler modes is available. Install Qt dependencies (~160mb) ? [y|n] : " if [[ ${REPLY} =~ y|Y ]]; then @@ -434,20 +434,18 @@ main () { jm_source="$PWD" jm_root="${jm_source}/jmvenv" - jm_deps="${jm_source}/deps" export PKG_CONFIG_PATH="${jm_root}/lib/pkgconfig:${PKG_CONFIG_PATH}" export LD_LIBRARY_PATH="${jm_root}/lib:${LD_LIBRARY_PATH}" export C_INCLUDE_PATH="${jm_root}/include:${C_INCLUDE_PATH}" export MAKEFLAGS='-j' # flags - develop_build='' python='python3' use_os_deps_check='1' use_secp_check='1' with_qt='' reinstall='false' - if ! parse_flags ${@}; then + if ! parse_flags "${@}"; then return 1 fi @@ -462,9 +460,10 @@ main () echo "Joinmarket virtualenv could not be setup. Exiting." return 1 fi + # shellcheck disable=SC1091 source "${jm_root}/bin/activate" mkdir -p "deps/cache" - pushd deps + pushd deps || return 1 if ! libsecp256k1_install; then echo "libsecp256k1 was not built. Exiting." return 1 @@ -477,7 +476,7 @@ main () echo "Libsodium was not built. Exiting." return 1 fi - popd + popd || return 1 if ! joinmarket_install; then echo "Joinmarket was not installed. Exiting." deactivate @@ -491,4 +490,4 @@ main () from this directory, to activate virtualenv." } -main ${@} +main "${@}"