mirror of
https://github.com/keylase/nvidia-patch.git
synced 2024-08-30 18:32:50 +00:00
Merge pull request #23 from Snawoot/shellcheck
* Fixes bug: message 'Something went wrong. Check nvidia driver' never displayed because $? always zero due to pipe containing last head which always succeeds. * Fix: https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing * Fix: https://www.shellcheck.net/wiki/SC2181 -- Check exit code directly with * Introduces strict mode of BASH operation
This commit is contained in:
commit
4805641d8b
38
patch.sh
38
patch.sh
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
backup_path="/opt/nvidia/libnvidia-encode-backup"
|
backup_path="/opt/nvidia/libnvidia-encode-backup"
|
||||||
silent_flag=''
|
silent_flag=''
|
||||||
rollback_flag=''
|
rollback_flag=''
|
||||||
@ -68,18 +70,15 @@ declare -A object_list=(
|
|||||||
["415.25"]='libnvcuvid.so'
|
["415.25"]='libnvcuvid.so'
|
||||||
)
|
)
|
||||||
|
|
||||||
driver_version=$(/usr/bin/nvidia-smi --query-gpu=driver_version --format=csv,noheader,nounits | head -n 1)
|
|
||||||
if [[ ! $? -eq 0 ]]; then
|
if ! driver_version=$(/usr/bin/nvidia-smi --query-gpu=driver_version --format=csv,noheader,nounits | head -n 1) ; then
|
||||||
echo 'Something went wrong. Check nvidia driver'
|
echo 'Something went wrong. Check nvidia driver'
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Detected nvidia driver version: $driver_version"
|
echo "Detected nvidia driver version: $driver_version"
|
||||||
|
|
||||||
patch="${patch_list[$driver_version]}"
|
if [[ ! -v "patch_list[$driver_version]" || ! -v "object_list[$driver_version]" ]]; then
|
||||||
object="${object_list[$driver_version]}"
|
|
||||||
|
|
||||||
if [[ ( ! "$patch" ) || ( ! "$object" ) ]]; then
|
|
||||||
echo "Patch for this ($driver_version) nvidia driver not found." 1>&2
|
echo "Patch for this ($driver_version) nvidia driver not found." 1>&2
|
||||||
echo "Available patches for: " 1>&2
|
echo "Available patches for: " 1>&2
|
||||||
for drv in "${!patch_list[@]}"; do
|
for drv in "${!patch_list[@]}"; do
|
||||||
@ -88,26 +87,29 @@ if [[ ( ! "$patch" ) || ( ! "$object" ) ]]; then
|
|||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
patch="${patch_list[$driver_version]}"
|
||||||
|
object="${object_list[$driver_version]}"
|
||||||
|
|
||||||
if [[ $rollback_flag ]]; then
|
if [[ $rollback_flag ]]; then
|
||||||
if [[ -f $backup_path/"$object".$driver_version ]]; then
|
if [[ -f "$backup_path/$object.$driver_version" ]]; then
|
||||||
cp -p $backup_path/"$object".$driver_version \
|
cp -p "$backup_path/$object.$driver_version" \
|
||||||
$driver_dir/"$object".$driver_version
|
"$driver_dir/$object.$driver_version"
|
||||||
echo "Restore from backup $object.$driver_version"
|
echo "Restore from backup $object.$driver_version"
|
||||||
else
|
else
|
||||||
echo "Backup not found. Try to patch first."
|
echo "Backup not found. Try to patch first."
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ ! -f $backup_path/"$object".$driver_version ]]; then
|
if [[ ! -f "$backup_path/$object.$driver_version" ]]; then
|
||||||
echo "Attention! Backup not found. Copy current libnvidia-encode to backup."
|
echo "Attention! Backup not found. Copy current $object to backup."
|
||||||
mkdir -p $backup_path
|
mkdir -p "$backup_path"
|
||||||
cp -p $driver_dir/"$object".$driver_version \
|
cp -p "$driver_dir/$object.$driver_version" \
|
||||||
$backup_path/"$object".$driver_version
|
"$backup_path/$object.$driver_version"
|
||||||
fi
|
fi
|
||||||
sha1sum $backup_path/"$object".$driver_version
|
sha1sum "$backup_path/$object.$driver_version"
|
||||||
sed "$patch" $backup_path/"$object".$driver_version > \
|
sed "$patch" "$backup_path/$object.$driver_version" > \
|
||||||
$driver_dir/"$object".$driver_version
|
"$driver_dir/$object.$driver_version"
|
||||||
sha1sum $driver_dir/"$object".$driver_version
|
sha1sum "$driver_dir/$object.$driver_version"
|
||||||
ldconfig
|
ldconfig
|
||||||
echo "Patched!"
|
echo "Patched!"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user