mirror of
https://github.com/keylase/nvidia-patch.git
synced 2024-08-30 18:32:50 +00:00
linux: ensure bytes are valid before patching
We use sed to replace original bytes by patched ones, but unfortunately sed doesn't report any errors when this substitution fails. Now, before actually running sed, we check if these bytes that are soon to be replaced, actually exist in the driver file.
This commit is contained in:
parent
100af892c3
commit
84e433fbbe
15
patch-fbc.sh
15
patch-fbc.sh
@ -381,6 +381,20 @@ patch_common () {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensure_bytes_are_valid () {
|
||||||
|
driver_file="$driver_dir/$object.$driver_version"
|
||||||
|
original_bytes=$(awk -F / '$2 { print $2 }' <<< "$patch")
|
||||||
|
patched_bytes=$(awk -F / '$3 { print $3 }' <<< "$patch")
|
||||||
|
if LC_ALL=C grep -qaP "$original_bytes" "$driver_file"; then
|
||||||
|
return 0 # file is ready to be patched
|
||||||
|
fi
|
||||||
|
if LC_ALL=C grep -qaP "$patched_bytes" "$driver_file"; then
|
||||||
|
return 0 # file is likely patched already
|
||||||
|
fi
|
||||||
|
echo "Error: Could not find bytes '$original_bytes' to patch in '$driver_file'."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
rollback () {
|
rollback () {
|
||||||
patch_common
|
patch_common
|
||||||
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
||||||
@ -395,6 +409,7 @@ rollback () {
|
|||||||
|
|
||||||
patch () {
|
patch () {
|
||||||
patch_common
|
patch_common
|
||||||
|
ensure_bytes_are_valid
|
||||||
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
||||||
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version$backup_suffix" | cut -f1 -d\ )"
|
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version$backup_suffix" | cut -f1 -d\ )"
|
||||||
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
|
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
|
||||||
|
15
patch.sh
15
patch.sh
@ -457,6 +457,20 @@ patch_common () {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensure_bytes_are_valid () {
|
||||||
|
driver_file="$driver_dir/$object.$driver_version"
|
||||||
|
original_bytes=$(awk -F / '$2 { print $2 }' <<< "$patch")
|
||||||
|
patched_bytes=$(awk -F / '$3 { print $3 }' <<< "$patch")
|
||||||
|
if LC_ALL=C grep -qaP "$original_bytes" "$driver_file"; then
|
||||||
|
return 0 # file is ready to be patched
|
||||||
|
fi
|
||||||
|
if LC_ALL=C grep -qaP "$patched_bytes" "$driver_file"; then
|
||||||
|
return 0 # file is likely patched already
|
||||||
|
fi
|
||||||
|
echo "Error: Could not find bytes '$original_bytes' to patch in '$driver_file'."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
rollback () {
|
rollback () {
|
||||||
patch_common
|
patch_common
|
||||||
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
||||||
@ -471,6 +485,7 @@ rollback () {
|
|||||||
|
|
||||||
patch () {
|
patch () {
|
||||||
patch_common
|
patch_common
|
||||||
|
ensure_bytes_are_valid
|
||||||
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
||||||
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version$backup_suffix" | cut -f1 -d\ )"
|
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version$backup_suffix" | cut -f1 -d\ )"
|
||||||
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
|
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
|
||||||
|
Loading…
Reference in New Issue
Block a user