update nvidia_installer.sh

This commit is contained in:
MacRimi
2026-04-17 18:35:42 +02:00
parent 415bc439bb
commit 35b7d01d7e
2 changed files with 47 additions and 26 deletions

View File

@@ -532,44 +532,48 @@ download_nvidia_installer() {
"${NVIDIA_BASE_URL}/${version}/NVIDIA-Linux-x86_64-${version}.run" "${NVIDIA_BASE_URL}/${version}/NVIDIA-Linux-x86_64-${version}.run"
"${NVIDIA_BASE_URL}/${version}/NVIDIA-Linux-x86_64-${version}-no-compat32.run" "${NVIDIA_BASE_URL}/${version}/NVIDIA-Linux-x86_64-${version}-no-compat32.run"
) )
# Header line on the real terminal so it stays visible regardless of caller redirects.
printf '\n %s NVIDIA-Linux-x86_64-%s.run\n' \
"$(translate 'Downloading')" "$version" >/dev/tty
local success=false local success=false
local url_index=0 local url_index=0
for url in "${urls[@]}"; do for url in "${urls[@]}"; do
((url_index++)) ((url_index++))
echo "Attempting download from: $url" >> "$LOG_FILE" echo "Attempting download from: $url" >> "$LOG_FILE"
rm -f "$run_file" rm -f "$run_file"
if curl -fL --connect-timeout 30 --max-time 600 "$url" -o "$run_file" >> "$LOG_FILE" 2>&1; then # wget --show-progress writes its progress bar to stderr. We route it to
# /dev/tty explicitly so the user always sees it (same UX as ISO downloads
# in vm_creator.sh). The file contents still go to $run_file.
if wget --no-verbose --show-progress \
--connect-timeout=30 --timeout=600 --tries=1 \
-O "$run_file" "$url" 2>/dev/tty; then
echo "Download completed, verifying file..." >> "$LOG_FILE" echo "Download completed, verifying file..." >> "$LOG_FILE"
if [[ ! -f "$run_file" ]]; then if [[ ! -f "$run_file" ]]; then
echo "ERROR: File not created after download" >> "$LOG_FILE" echo "ERROR: File not created after download" >> "$LOG_FILE"
continue continue
fi fi
local file_size local file_size
file_size=$(stat -c%s "$run_file" 2>/dev/null || stat -f%z "$run_file" 2>/dev/null || echo "0") file_size=$(stat -c%s "$run_file" 2>/dev/null || stat -f%z "$run_file" 2>/dev/null || echo "0")
echo "Downloaded file size: $file_size bytes" >> "$LOG_FILE" echo "Downloaded file size: $file_size bytes" >> "$LOG_FILE"
if [[ $file_size -lt 40000000 ]]; then if [[ $file_size -lt 40000000 ]]; then
echo "ERROR: File too small ($file_size bytes, expected >40MB)" >> "$LOG_FILE" echo "ERROR: File too small ($file_size bytes, expected >40MB)" >> "$LOG_FILE"
head -c 200 "$run_file" >> "$LOG_FILE" 2>&1 head -c 200 "$run_file" >> "$LOG_FILE" 2>&1
rm -f "$run_file" rm -f "$run_file"
continue continue
fi fi
local file_type local file_type
file_type=$(file "$run_file" 2>/dev/null) file_type=$(file "$run_file" 2>/dev/null)
echo "File type: $file_type" >> "$LOG_FILE" echo "File type: $file_type" >> "$LOG_FILE"
if echo "$file_type" | grep -q "executable"; then if echo "$file_type" | grep -q "executable"; then
echo "SUCCESS: Valid executable downloaded" >> "$LOG_FILE" echo "SUCCESS: Valid executable downloaded" >> "$LOG_FILE"
success=true success=true
@@ -580,11 +584,11 @@ download_nvidia_installer() {
rm -f "$run_file" rm -f "$run_file"
fi fi
else else
echo "ERROR: curl failed for $url (exit code: $?)" >> "$LOG_FILE" echo "ERROR: wget failed for $url (exit code: $?)" >> "$LOG_FILE"
rm -f "$run_file" rm -f "$run_file"
fi fi
done done
if ! $success; then if ! $success; then
msg_error "$(translate 'Download failed for all attempted URLs')" >&2 msg_error "$(translate 'Download failed for all attempted URLs')" >&2
msg_error "Version $version may not be available for your architecture" >&2 msg_error "Version $version may not be available for your architecture" >&2
@@ -930,18 +934,20 @@ main() {
stop_and_disable_nvidia_services stop_and_disable_nvidia_services
unload_nvidia_modules unload_nvidia_modules
msg_info "$(translate 'Downloading NVIDIA driver version:') $DRIVER_VERSION" # No msg_info spinner here — it would clash with wget --show-progress,
# which writes its progress bar directly to /dev/tty from inside the
# download function. Stderr from the function is allowed through so
# warnings/errors reach the user.
local installer local installer
installer=$(download_nvidia_installer "$DRIVER_VERSION" 2>>"$LOG_FILE") installer=$(download_nvidia_installer "$DRIVER_VERSION")
local download_result=$? local download_result=$?
if [[ $download_result -ne 0 ]]; then if [[ $download_result -ne 0 ]]; then
msg_error "$(translate 'Failed to download NVIDIA installer')" msg_error "$(translate 'Failed to download NVIDIA installer')"
exit 1 exit 1
fi fi
msg_ok "$(translate 'NVIDIA installer downloaded successfully')" msg_ok "$(translate 'NVIDIA installer downloaded successfully')" | tee -a "$screen_capture"
if [[ -z "$installer" || ! -f "$installer" ]]; then if [[ -z "$installer" || ! -f "$installer" ]]; then
msg_error "$(translate 'Internal error: NVIDIA installer path is empty or file not found.')" msg_error "$(translate 'Internal error: NVIDIA installer path is empty or file not found.')"

View File

@@ -523,26 +523,39 @@ download_nvidia_installer() {
return 1 return 1
fi fi
msg_info "$(translate 'Downloading NVIDIA driver') ${version}..." >&2
local urls=( local urls=(
"${NVIDIA_BASE_URL}/${version}/NVIDIA-Linux-x86_64-${version}.run" "${NVIDIA_BASE_URL}/${version}/NVIDIA-Linux-x86_64-${version}.run"
"${NVIDIA_BASE_URL}/${version}/NVIDIA-Linux-x86_64-${version}-no-compat32.run" "${NVIDIA_BASE_URL}/${version}/NVIDIA-Linux-x86_64-${version}-no-compat32.run"
) )
# Header line on the real terminal so it stays visible regardless of caller redirects.
printf '\n %s NVIDIA-Linux-x86_64-%s.run\n' \
"$(translate 'Downloading')" "$version" >/dev/tty
local success=false local success=false
for url in "${urls[@]}"; do for url in "${urls[@]}"; do
rm -f "$run_file" rm -f "$run_file"
if curl -fL --connect-timeout 30 --max-time 600 "$url" -o "$run_file" >> "$LOG_FILE" 2>&1; then echo "Attempting download from: $url" >> "$LOG_FILE"
[[ ! -f "$run_file" ]] && continue
# wget --show-progress writes its progress bar to stderr. We route it to
# /dev/tty explicitly so the user always sees it (same UX as ISO downloads
# in vm_creator.sh). The file contents still go to $run_file.
if wget --no-verbose --show-progress \
--connect-timeout=30 --timeout=600 --tries=1 \
-O "$run_file" "$url" 2>/dev/tty; then
[[ ! -f "$run_file" ]] && { echo "ERROR: File not created" >> "$LOG_FILE"; continue; }
local file_size file_type local file_size file_type
file_size=$(stat -c%s "$run_file" 2>/dev/null || echo "0") file_size=$(stat -c%s "$run_file" 2>/dev/null || echo "0")
file_type=$(file "$run_file" 2>/dev/null) file_type=$(file "$run_file" 2>/dev/null)
echo "Downloaded file size: $file_size bytes, type: $file_type" >> "$LOG_FILE"
if [[ $file_size -gt 40000000 ]] && echo "$file_type" | grep -q "executable"; then if [[ $file_size -gt 40000000 ]] && echo "$file_type" | grep -q "executable"; then
success=true success=true
break break
fi fi
rm -f "$run_file" rm -f "$run_file"
else
echo "ERROR: wget failed for $url (exit: $?)" >> "$LOG_FILE"
rm -f "$run_file"
fi fi
done done
@@ -874,9 +887,11 @@ main() {
ensure_repos_and_headers ensure_repos_and_headers
# Download installer once — shared between LXC and host updates # Download installer once — shared between LXC and host updates.
# No 2>>"$LOG_FILE" redirect: we want msg_warn/msg_error from the function to
# reach the user's terminal, and wget's progress bar goes to /dev/tty directly.
local installer local installer
installer=$(download_nvidia_installer "$TARGET_VERSION" 2>>"$LOG_FILE") installer=$(download_nvidia_installer "$TARGET_VERSION")
local download_result=$? local download_result=$?
if [[ $download_result -ne 0 || -z "$installer" || ! -f "$installer" ]]; then if [[ $download_result -ne 0 || -z "$installer" || ! -f "$installer" ]]; then