Skip to content

Commit 4b4277c

Browse files
authored
fix: 🔧 Improve glibc version detection in install.sh (#851)
Enhanced the glibc version detection with multiple fallback methods: - Added dedicated function to check if glibc version is sufficient - Implemented three detection methods (direct library check, ldd, getconf) - Added support for ARM64 architecture by checking additional library paths - Made error messages more informative with dynamic version requirements - Fixed parameter passing to allow setup command to receive arguments These changes improve reliability of installation across different Linux distributions and architectures.
1 parent 82fe212 commit 4b4277c

File tree

1 file changed

+62
-27
lines changed

1 file changed

+62
-27
lines changed

‎bundle/linux/install.sh‎

100755100644
Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,72 @@ is_target_triple_gnu() {
5656
fi
5757
}
5858

59-
# checks that the system has atleast glibc 2.34
60-
check_glibc_version() {
61-
if [ -f /lib64/libc.so.6 ]; then
62-
LIBC_PATH=/lib64/libc.so.6
63-
elif [ -f /lib/libc.so.6 ]; then
64-
LIBC_PATH=/lib/libc.so.6
65-
elif [ -f /usr/lib/x86_64-linux-gnu/libc.so.6 ]; then
66-
LIBC_PATH=/usr/lib/x86_64-linux-gnu/libc.so.6
59+
# Minimum required glibc version
60+
GLIBC_MIN_MAJOR=2
61+
GLIBC_MIN_MINOR=34
62+
63+
# Check if a glibc version meets the minimum requirement
64+
is_glibc_version_sufficient() {
65+
local version="$1"
66+
local major minor
67+
68+
IFS='.' read -r major minor <<EOF
69+
$version
70+
EOF
71+
if [ -z "$minor" ]; then
72+
minor=0
73+
fi
74+
75+
if [ "$major" -gt "$GLIBC_MIN_MAJOR" ] || { [ "$major" -eq "$GLIBC_MIN_MAJOR" ] && [ "$minor" -ge "$GLIBC_MIN_MINOR" ]; }; then
76+
return 0
6777
else
68-
log_error "Could not find glibc."
6978
return 1
7079
fi
80+
}
7181

72-
glibc_version=$("$LIBC_PATH" | sed -n 's/^GNU C Library (.*) stable release version \([0-9]*\)\.\([0-9]*\).*$/\1.\2/p')
73-
74-
if [ -z "$glibc_version" ]; then
75-
log_error "Could not determine glibc version."
76-
return 1
77-
else
78-
IFS='.' read -r major minor << EOF
79-
$glibc_version
80-
EOF
81-
if [ -z "$minor" ]; then
82-
minor=0
82+
# checks that the system has at least glibc 2.34
83+
check_glibc_version() {
84+
# Method 1: Original approach - try common libc.so.6 locations
85+
for LIBC_PATH in /lib64/libc.so.6 /lib/libc.so.6 /usr/lib/x86_64-linux-gnu/libc.so.6 \
86+
/lib/aarch64-linux-gnu/libc.so.6; do
87+
if [ -f "$LIBC_PATH" ]; then
88+
glibc_version=$("$LIBC_PATH" | sed -n 's/^GNU C Library (.*) stable release version \([0-9]*\)\.\([0-9]*\).*$/\1.\2/p')
89+
if [ -n "$glibc_version" ]; then
90+
if is_glibc_version_sufficient "$glibc_version"; then
91+
return 0
92+
else
93+
return 1
94+
fi
95+
fi
8396
fi
84-
if [ "$major" -gt 2 ] || { [ "$major" -eq 2 ] && [ "$minor" -ge 34 ]; }; then
85-
return 0
86-
else
87-
return 1
97+
done
98+
99+
# Method 2: Try ldd --version as a more reliable alternative
100+
if command -v ldd >/dev/null 2>&1; then
101+
glibc_version=$(ldd --version 2>/dev/null | head -n 1 | grep -o '[0-9]\+\.[0-9]\+' | head -n 1)
102+
if [ -n "$glibc_version" ]; then
103+
if is_glibc_version_sufficient "$glibc_version"; then
104+
return 0
105+
else
106+
return 1
107+
fi
88108
fi
89109
fi
110+
111+
# Method 3: Try getconf as a fallback
112+
if command -v getconf >/dev/null 2>&1; then
113+
glibc_version=$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $2}')
114+
if [ -n "$glibc_version" ]; then
115+
if is_glibc_version_sufficient "$glibc_version"; then
116+
return 0
117+
else
118+
return 1
119+
fi
120+
fi
121+
fi
122+
123+
log_error "Could not determine glibc version. This CLI requires glibc $GLIBC_MIN_MAJOR.$GLIBC_MIN_MINOR or newer."
124+
return 1
90125
}
91126

92127
# checks that uname matches the target triple
@@ -96,7 +131,7 @@ if [ "$(uname)" != "$(target_triple_uname)" ]; then
96131
fi
97132

98133
if is_target_triple_gnu && ! check_glibc_version; then
99-
log_error "This release built for a GNU system with glibc 2.34 or newer, try installing the musl version of the CLI."
134+
log_error "This release built for a GNU system with glibc $GLIBC_MIN_MAJOR.$GLIBC_MIN_MINOR or newer, try installing the musl version of the CLI."
100135
exit 1
101136
fi
102137

@@ -105,12 +140,12 @@ if [ -n "${Q_INSTALL_GLOBAL:-}" ]; then
105140
install -m 755 "$SCRIPT_DIR/bin/qterm" /usr/local/bin/
106141

107142
/usr/local/bin/q integrations install dotfiles
108-
/usr/local/bin/q setup --global
143+
/usr/local/bin/q setup --global "$@"
109144
else
110145
mkdir -p "$HOME/.local/bin"
111146

112147
install -m 755 "$SCRIPT_DIR/bin/q" "$HOME/.local/bin/"
113148
install -m 755 "$SCRIPT_DIR/bin/qterm" "$HOME/.local/bin/"
114149

115-
"$HOME/.local/bin/q" setup
150+
"$HOME/.local/bin/q" setup "$@"
116151
fi

0 commit comments

Comments
 (0)