Skip to content

Instantly share code, notes, and snippets.

@indeedwatson
Created April 25, 2018 18:46
Show Gist options
  • Save indeedwatson/738dabd1f0cd0c22859d2d3cae6cdea1 to your computer and use it in GitHub Desktop.
Save indeedwatson/738dabd1f0cd0c22859d2d3cae6cdea1 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$(id -u)" -ne 0 ]; then
printf "In order to change the drivers, launch this script with SUDO!"
fi
troubleshoot()
{
printf "\\nContents of %s" "$xorg"
printf "\\n - %s" "$(ls "$xorg")"
printf "\\nCurrent kernel Params"
printf "\\n - %s" "$(cat /proc/cmdline)"
printf "\\nContents of %s" "$blacklist"
printf "\\n - %s\\n" "$(ls "$blacklist")"
}
blacklist_handler()
{
# blacklist 1st entry
if [ ! -f "$blacklist"/blacklist."$1".conf ] ; then
printf "\\nCreating %s/blacklist.%s.conf..." "$blacklist" "$1"
cp ./blacklist/blacklist."$1".conf "$blacklist"/blacklist."$1".conf
fi
# remove other blacklists
if [ -f "$blacklist"/blacklist."$2".conf ] ; then
printf "\\nDeleting %s/blacklist.%s.conf..." "$blacklist" "$2"
rm "$blacklist"/blacklist."$2".conf
fi
if [ -f "$blacklist"/blacklist."$3".conf ] ; then
printf "\\nDeleting %s/blaclist.%s.conf..." "$blacklist" "$3"
rm "$blacklist"/blacklist."$3".conf
fi
}
kernel_params_handler()
{
printf "\\nEnabling %s support..." "$1"
sed -i "s/$1.si_support=0/$1.si_support=1/" ./default/grub
printf "\\nDisabling %s support..." "$2"
sed -i "s/$2.si_support=1/$2.si_support=0/" ./default/grub
}
xorg_handler()
{
if [ ! -f "$xorg"/20-"$1".conf ] ; then
printf "\\n%s/20-%s.conf" "$xorg" "$1"
printf "\\nCreating %s/20-$1.conf..." "$xorg" "$1"
cp ./xorg/20-"$1".conf "$xorg"/20-"$1".conf
fi
if [ -f "$xorg"/20-"$2".conf ] ; then
printf "\\nDeleting %s/20-%s.conf..." "$xorg" "$2"
rm "$xorg"/20-"$2".conf
fi
if [ -f "$xorg"/20-"$3".conf ] ; then
printf "\\nDeleting %s/20-%s.conf..." "$xorg" "$3"
rm "$xorg"/20-"$3".conf
fi
}
change_driver()
{
if [ "$(/usr/bin/id -u)" -ne 0 ] ; then
echo "You must run as sudo to continue"
sudo "$0" "$@"
else
mkinitcpio -p linux &&
grub-mkconfig -o /boot/grub/grub.cfg
printf "%b" "\\nDone! New driver: \\e[1;34m%s\\e[0m\\n" "$new_driver"
fi
}
#cd /etc/
current_driver=$(lspci -nnk | grep -i vga -A3 | grep 'in use' | \
grep -Po '(\w+)$')
blacklist="./modprobe.d"
xorg="./X11/xorg.conf.d"
new_driver="0"
while [ $new_driver = 0 ]
do
printf "%b" "\\n\\e[1;34m=> Current driver: %s\\e[0m\\n" "$current_driver"
read -p "
To implement a new driver press:
[I]ntel
[A]mdgpu
[R]adeon
[T]roubleshoot
[Q]uit
" -n 1 -r
case "$REPLY" in
i*) new_driver=intel && printf "\\nIntel selected";;
a*) new_driver=amdgpu && printf "\\nAMDGPU selected";;
r*) new_driver=radeon && printf "\\nRadeon selected";;
t*) troubleshoot;;
q*) printf "\\nExiting...\\n" && exit;;
*)
printf "\\nThat's not a correct option.\\n"
esac
done
if [ $new_driver = "intel" ] ; then
blacklist_handler vfio amdgpu radeon
xorg_handler modesetting radeon amdgpu
#change_driver
elif [ $new_driver = "amdgpu" ]
then
blacklist_handler radeon amdgpu vfio
kernel_params_handler amdgpu radeon
xorg_handler amdgpu radeon.conf modesetting
#change_driver
elif [ $new_driver = "radeon" ] ; then
blacklist_handler amdgpu radeon vfio
kernel_params_handler radeon amdgpu
xorg_handler radeon modesetting amdgpu
#change_driver
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment