3 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
4 shopt -s inherit_errexit
2>/dev
/null ||
: # ignore fail in bash < 4.4
6 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
8 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
10 # https://wiki.archlinux.org/index.php/Solid_state_drive#Resolving_NCQ_errors
11 # evo-870 doesnt get along well with d16.
12 # Dmesg gives us an ata number we could disable specifically on the command line, but I've had that number change on me between oses, so reenabling ncq
15 if [[ $1 == no-upgrub
]]; then
19 byid
=/dev
/disk
/by-id
/ata-Samsung_SSD_870_QVO_8TB_S5VUNG0N900656V
20 if [[ ! -e $byid ]]; then
21 # not plugged in we assume
32 depth
=$
(cat /sys
/block
/$dev/device
/queue_depth
)
33 if [[ $depth != 0 ]]; then
34 if grep -qF libata.force
=noncq
/proc
/cmdline
; then
35 echo $0: warning
, cant change queue_depth due to globally disabled ncq
37 echo 1 >/sys
/block
/$dev/device
/queue_depth
41 sys
=$
(readlink
/sys
/block
/$dev)
42 ata
=${sys#*/*/*/*/ata}
45 arg
=libata.force
=${ata}.00:noncq
47 if ! grep "^GRUB_CMDLINE_LINUX_DEFAULT=.*[\" ]${arg//./\\.}[\" ]" /etc
/default
/grub
; then
48 sed -ri "s/([\" ])libata.force=[^ ]+ */\1/g;s/^GRUB_CMDLINE_LINUX_DEFAULT=\"(.*)/GRUB_CMDLINE_LINUX_DEFAULT=\"$arg \1/" /etc
/default
/grub
50 echo "$0: warning: grub updated. you may want to reboot"
51 if type -P update-grub2
&>/dev
/null
; then