From 3a8efabbfea7765e4fc913af62bd93884ebeeaa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 15 Sep 2025 11:30:05 +0000 Subject: [PATCH 1/6] refactor installdependencies.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- src/Misc/layoutbin/installdependencies.sh | 138 +++++++--------------- 1 file changed, 44 insertions(+), 94 deletions(-) diff --git a/src/Misc/layoutbin/installdependencies.sh b/src/Misc/layoutbin/installdependencies.sh index 552f30ce2fd..cd8841aa60f 100755 --- a/src/Misc/layoutbin/installdependencies.sh +++ b/src/Misc/layoutbin/installdependencies.sh @@ -1,63 +1,57 @@ #!/bin/bash -user_id=`id -u` +set -e -o pipefail -if [ $user_id -ne 0 ]; then +if [ "$(id -u)" -ne "0" ]; then echo "Need to run with sudo privilege" exit 1 fi -# Determine OS type +# Determine OS type # Debian based OS (Debian, Ubuntu, Linux Mint) has /etc/debian_version # Fedora based OS (Fedora, Red Hat Enterprise Linux, CentOS, Oracle Linux 7) has /etc/redhat-release # SUSE based OS (OpenSUSE, SUSE Enterprise) has ID_LIKE=suse in /etc/os-release -function print_errormessage() +function print_errormessage() { echo "Can't install dotnet core dependencies." echo "You can manually install all required dependencies based on following documentation" echo "https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x" } -function print_rhel6message() +function print_rhel6message() { echo "We did our best effort to install dotnet core dependencies" - echo "However, there are some dependencies which require manual installation" + echo "However, there are some dependencies which require manual installation" echo "You can install all remaining required dependencies based on the following documentation" echo "https://github.com/dotnet/core/blob/master/Documentation/build-and-install-rhel6-prerequisites.md" } -function print_rhel6errormessage() +function print_rhel6errormessage() { echo "We couldn't install dotnet core dependencies" echo "You can manually install all required dependencies based on following documentation" echo "https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x" - echo "In addition, there are some dependencies which require manual installation. Please follow this documentation" + echo "In addition, there are some dependencies which require manual installation. Please follow this documentation" echo "https://github.com/dotnet/core/blob/master/Documentation/build-and-install-rhel6-prerequisites.md" } -if [ -e /etc/os-release ] -then +if [ -e /etc/os-release ]; then echo "--------OS Information--------" cat /etc/os-release echo "------------------------------" - if [ -e /etc/debian_version ] - then + if [ -e /etc/debian_version ]; then echo "The current OS is Debian based" echo "--------Debian Version--------" cat /etc/debian_version echo "------------------------------" - + # prefer apt-get over apt - command -v apt-get - if [ $? -eq 0 ] - then + if command -v apt-get; then apt_get=apt-get else - command -v apt - if [ $? -eq 0 ] - then + if command -v apt; then apt_get=apt else echo "Found neither 'apt-get' nor 'apt'" @@ -66,114 +60,74 @@ then fi fi - $apt_get update && $apt_get install -y libkrb5-3 zlib1g - if [ $? -ne 0 ] - then + if ! "$apt_get" update && "$apt_get" install -y libkrb5-3 zlib1g; 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 + if "$apt_get" install -y "$1"; then + if ! dpkg -l | grep "^ii\s\s$1" &>/dev/null; then fail=$? fi - fi - if [ $fail -ne 0 ] - then + else shift - if [ -n "$1" ] - then + if [ $# -eq 0 ]; then + fail=1 + return $fail + else apt_get_with_fallbacks "$@" fi fi } - apt_get_with_fallbacks liblttng-ust1 liblttng-ust0 - if [ $? -ne 0 ] - then - echo "'$apt_get' failed with exit code '$?'" + if ! apt_get_with_fallbacks liblttng-ust1 liblttng-ust0; then print_errormessage exit 1 fi - apt_get_with_fallbacks libssl1.1$ libssl1.0.2$ libssl1.0.0$ - if [ $? -ne 0 ] - then - echo "'$apt_get' failed with exit code '$?'" + if ! apt_get_with_fallbacks libssl3$ libssl1.1$ libssl1.0.2$ libssl1.0.0$; then print_errormessage exit 1 fi - apt_get_with_fallbacks libicu72 libicu71 libicu70 libicu69 libicu68 libicu67 libicu66 libicu65 libicu63 libicu60 libicu57 libicu55 libicu52 - if [ $? -ne 0 ] - then - echo "'$apt_get' failed with exit code '$?'" + if ! apt_get_with_fallbacks libicu74 libicu73 libicu72 libicu71 libicu70 libicu69 libicu68 libicu67 libicu66 libicu65 libicu63 libicu60 libicu57 libicu55 libicu52; then print_errormessage exit 1 fi - elif [ -e /etc/redhat-release ] - then - echo "The current OS is Fedora based" + elif [ -e /etc/redhat-release ]; then echo "--Fedora/RHEL/CentOS Version--" cat /etc/redhat-release echo "------------------------------" - # use dnf on fedora - # use yum on centos and rhel - if [ -e /etc/fedora-release ] - then - command -v dnf - if [ $? -eq 0 ] - then - dnf install -y lttng-ust openssl-libs krb5-libs zlib libicu - if [ $? -ne 0 ] - then - echo "'dnf' failed with exit code '$?'" - print_errormessage - exit 1 - fi - else - echo "Can not find 'dnf'" - print_errormessage - exit 1 - fi + if command -v dnf; then + dnf=dnf + elif command -v yum; then + dnf=yum else - command -v yum - if [ $? -eq 0 ] - then - yum install -y lttng-ust openssl-libs krb5-libs zlib libicu - if [ $? -ne 0 ] - then - echo "'yum' failed with exit code '$?'" - print_errormessage - exit 1 - fi + if command -v microdnf; then + dnf=microdnf else - echo "Can not find 'yum'" + echo "Found neither 'dnf' nor 'yum'" print_errormessage exit 1 fi fi + + if ! $dnf install -y lttng-ust openssl-libs krb5-libs zlib libicu; then + echo "'dnf' failed with exit code '$?'" + print_errormessage + exit 1 + fi else # we might on OpenSUSE OSTYPE=$(grep ID_LIKE /etc/os-release | cut -f2 -d=) - echo $OSTYPE - echo $OSTYPE | grep "suse" - if [ $? -eq 0 ] - then + echo "$OSTYPE" + if echo "$OSTYPE" | grep "suse"; then echo "The current OS is SUSE based" - command -v zypper - if [ $? -eq 0 ] - then - zypper -n install lttng-ust libopenssl1_1 krb5 zlib libicu60_2 - if [ $? -ne 0 ] - then + if command -v zypper; then + if ! zypper -n install lttng-ust libopenssl1_1 krb5 zlib libicu60_2; then echo "'zypper' failed with exit code '$?'" print_errormessage exit 1 @@ -199,12 +153,8 @@ then # Install known dependencies, as a best effort. # The remaining dependencies are covered by the GitHub doc that will be shown by `print_rhel6message` - command -v yum - if [ $? -eq 0 ] - then - yum install -y openssl krb5-libs zlib - if [ $? -ne 0 ] - then + if command -v yum; then + if ! yum install -y openssl krb5-libs zlib; then echo "'yum' failed with exit code '$?'" print_rhel6errormessage exit 1 From 0c4d07a3104e3c17888b96b2a42c7011287217ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 15 Sep 2025 12:01:20 +0000 Subject: [PATCH 2/6] apply copilot suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- src/Misc/layoutbin/installdependencies.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Misc/layoutbin/installdependencies.sh b/src/Misc/layoutbin/installdependencies.sh index cd8841aa60f..18aa6224032 100755 --- a/src/Misc/layoutbin/installdependencies.sh +++ b/src/Misc/layoutbin/installdependencies.sh @@ -69,7 +69,7 @@ if [ -e /etc/os-release ]; then apt_get_with_fallbacks() { if "$apt_get" install -y "$1"; then if ! dpkg -l | grep "^ii\s\s$1" &>/dev/null; then - fail=$? + fail=1 fi else shift @@ -116,7 +116,8 @@ if [ -e /etc/os-release ]; then fi if ! $dnf install -y lttng-ust openssl-libs krb5-libs zlib libicu; then - echo "'dnf' failed with exit code '$?'" + exit_code=$? + echo "'$dnf' failed with exit code '$exit_code'" print_errormessage exit 1 fi From c9ba2f097b4c0ac5a85b8203f1a48cc5b2e74691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 15 Sep 2025 12:02:49 +0000 Subject: [PATCH 3/6] initialize fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- src/Misc/layoutbin/installdependencies.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Misc/layoutbin/installdependencies.sh b/src/Misc/layoutbin/installdependencies.sh index 18aa6224032..557df7b2a06 100755 --- a/src/Misc/layoutbin/installdependencies.sh +++ b/src/Misc/layoutbin/installdependencies.sh @@ -67,6 +67,7 @@ if [ -e /etc/os-release ]; then fi apt_get_with_fallbacks() { + fail=0 if "$apt_get" install -y "$1"; then if ! dpkg -l | grep "^ii\s\s$1" &>/dev/null; then fail=1 From d407bfecf91bed70ecf655e132996c41f5f739fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 15 Sep 2025 14:09:00 +0200 Subject: [PATCH 4/6] Update src/Misc/layoutbin/installdependencies.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Misc/layoutbin/installdependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misc/layoutbin/installdependencies.sh b/src/Misc/layoutbin/installdependencies.sh index 557df7b2a06..f2a288f9cf0 100755 --- a/src/Misc/layoutbin/installdependencies.sh +++ b/src/Misc/layoutbin/installdependencies.sh @@ -69,7 +69,7 @@ if [ -e /etc/os-release ]; then apt_get_with_fallbacks() { fail=0 if "$apt_get" install -y "$1"; then - if ! dpkg -l | grep "^ii\s\s$1" &>/dev/null; then + if ! dpkg -l | grep "^ii\s\+$1\s" &>/dev/null; then fail=1 fi else From a8b49f953fa7d4a61c64b8ef5e92946f6b0e3a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 15 Sep 2025 14:10:27 +0200 Subject: [PATCH 5/6] Update src/Misc/layoutbin/installdependencies.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Misc/layoutbin/installdependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misc/layoutbin/installdependencies.sh b/src/Misc/layoutbin/installdependencies.sh index f2a288f9cf0..0e6ae529dfd 100755 --- a/src/Misc/layoutbin/installdependencies.sh +++ b/src/Misc/layoutbin/installdependencies.sh @@ -88,7 +88,7 @@ if [ -e /etc/os-release ]; then exit 1 fi - if ! apt_get_with_fallbacks libssl3$ libssl1.1$ libssl1.0.2$ libssl1.0.0$; then + if ! apt_get_with_fallbacks libssl3 libssl1.1 libssl1.0.2 libssl1.0.0; then print_errormessage exit 1 fi From cd3b03e352c5819eeb07c775c44ea956cf9900ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 15 Sep 2025 14:10:48 +0200 Subject: [PATCH 6/6] Update src/Misc/layoutbin/installdependencies.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Misc/layoutbin/installdependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misc/layoutbin/installdependencies.sh b/src/Misc/layoutbin/installdependencies.sh index 0e6ae529dfd..80b1464dee6 100755 --- a/src/Misc/layoutbin/installdependencies.sh +++ b/src/Misc/layoutbin/installdependencies.sh @@ -110,7 +110,7 @@ if [ -e /etc/os-release ]; then if command -v microdnf; then dnf=microdnf else - echo "Found neither 'dnf' nor 'yum'" + echo "Found neither 'dnf', 'yum', nor 'microdnf'" print_errormessage exit 1 fi