From b2e1f9cc7123184f882ecd1c75ee438ed2698c76 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Mon, 26 Oct 2020 23:27:09 -0400 Subject: [PATCH] Improve apt handling (#708) * Unify apt/apt-get logic The previous logic was buggy in that it tried to use `apt` in the `apt-get` branch after deciding that `apt` was unavailable... * Prefer apt-get over apt apt does not have a stable cli and using it from scripts yields annoying messages * Improve English for missing apt-get & apt case * Fix apt-get/apt fallback behavior for $ patterns If there's a `$` in the apt install pattern, it will not fail if it selects a thing and decides it isn't interested in installing it. * Fix spelling of libssl --- src/Misc/layoutbin/installdependencies.sh | 106 +++++++++++----------- 1 file changed, 52 insertions(+), 54 deletions(-) diff --git a/src/Misc/layoutbin/installdependencies.sh b/src/Misc/layoutbin/installdependencies.sh index 786714925..d771afcfb 100755 --- a/src/Misc/layoutbin/installdependencies.sh +++ b/src/Misc/layoutbin/installdependencies.sh @@ -49,70 +49,68 @@ then cat /etc/debian_version echo "------------------------------" - # prefer apt over apt-get - command -v apt + # prefer apt-get over apt + command -v apt-get if [ $? -eq 0 ] then - apt update && apt install -y liblttng-ust0 libkrb5-3 zlib1g - if [ $? -ne 0 ] - then - echo "'apt' failed with exit code '$?'" - print_errormessage - exit 1 - fi - - # libissl version prefer: libssl1.1 -> libssl1.0.2 -> libssl1.0.0 - apt install -y libssl1.1$ || apt install -y libssl1.0.2$ || apt install -y libssl1.0.0$ - if [ $? -ne 0 ] - then - echo "'apt' failed with exit code '$?'" - print_errormessage - exit 1 - fi - - # libicu version prefer: libicu66 -> libicu63 -> libicu60 -> libicu57 -> libicu55 -> libicu52 - apt install -y libicu66 || apt install -y libicu63 || apt install -y libicu60 || apt install -y libicu57 || apt install -y libicu55 || apt install -y libicu52 - if [ $? -ne 0 ] - then - echo "'apt' failed with exit code '$?'" - print_errormessage - exit 1 - fi + apt_get=apt-get else - command -v apt-get + command -v apt if [ $? -eq 0 ] then - apt-get update && apt-get install -y liblttng-ust0 libkrb5-3 zlib1g - if [ $? -ne 0 ] - then - echo "'apt-get' failed with exit code '$?'" - print_errormessage - exit 1 - fi - - # libissl version prefer: libssl1.1 -> libssl1.0.2 -> libssl1.0.0 - apt-get install -y libssl1.1$ || apt-get install -y libssl1.0.2$ || apt install -y libssl1.0.0$ - if [ $? -ne 0 ] - then - echo "'apt-get' failed with exit code '$?'" - print_errormessage - exit 1 - fi - - # libicu version prefer: libicu66 -> libicu63 -> libicu60 -> libicu57 -> libicu55 -> libicu52 - apt-get install -y libicu66 || apt-get install -y libicu63 || apt-get install -y libicu60 || apt install -y libicu57 || apt install -y libicu55 || apt install -y libicu52 - if [ $? -ne 0 ] - then - echo "'apt-get' failed with exit code '$?'" - print_errormessage - exit 1 - fi + apt_get=apt else - echo "Can not find 'apt' or 'apt-get'" + echo "Found neither 'apt-get' nor 'apt'" print_errormessage exit 1 fi fi + + $apt_get update && $apt_get install -y liblttng-ust0 libkrb5-3 zlib1g + if [ $? -ne 0 ] + then + echo "'$apt_get' failed with exit code '$?'" + print_errormessage + exit 1 + fi + + apt_get_with_fallbacks() { + $apt_get install -y $1 + fail=$? + if [ $fail -eq 0 ] + then + if [ "${1#"${1%?}"}" = '$' ]; then + dpkg -l "${1%?}" > /dev/null 2> /dev/null + fail=$? + fi + fi + if [ $fail -ne 0 ] + then + shift + if [ -n "$1" ] + then + apt_get_with_fallbacks "$@" + fi + fi + } + + # libssl version prefer: libssl1.1 -> libssl1.0.2 -> libssl1.0.0 + apt_get_with_fallbacks libssl1.1$ libssl1.0.2$ libssl1.0.0$ + if [ $? -ne 0 ] + then + echo "'$apt_get' failed with exit code '$?'" + print_errormessage + exit 1 + fi + + # libicu version prefer: libicu66 -> libicu63 -> libicu60 -> libicu57 -> libicu55 -> libicu52 + apt_get_with_fallbacks libicu66 libicu63 libicu60 libicu57 libicu55 libicu52 + if [ $? -ne 0 ] + then + echo "'$apt_get' failed with exit code '$?'" + print_errormessage + exit 1 + fi elif [ -e /etc/redhat-release ] then echo "The current OS is Fedora based"