#!/usr/bin/env bash

# update
apt -y update
apt -y upgrade
apt -y dist-upgrade

# 5.2 mainline kernel
cd /tmp
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.2-rc6/linux-headers-5.2.0-050200rc6_5.2.0-050200rc6.201906222033_all.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.2-rc6/linux-headers-5.2.0-050200rc6-generic_5.2.0-050200rc6.201906222033_amd64.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.2-rc6/linux-image-unsigned-5.2.0-050200rc6-generic_5.2.0-050200rc6.201906222033_amd64.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.2-rc6/linux-modules-5.2.0-050200rc6-generic_5.2.0-050200rc6.201906222033_amd64.deb
dpkg -i *.deb
rm -rf /tmp/*.deb

# display
mkdir /etc/X11/xorg.conf.d

cat <<EOT >> /etc/X11/xorg.conf.d/10-intel.conf
Section "Device"
  Identifier "Intel Graphics"
  Driver "intel"
  Option "AccelMethod" "sna"
  Option "TearFree" "true"
  Option "DRI" "3"
EndSection
EOT

cat <<EOT >> /etc/X11/xorg.conf.d/20-monitor.conf
# intel
Section "Monitor"
  Identifier "DSI1"
  Option "Rotate" "right"
EndSection

# modeline
Section "Monitor"
  Identifier "DSI-1"
  Option "Rotate" "right"
EndSection
EOT

cat <<EOT >> /etc/X11/xorg.conf.d/30-touchpad.conf
Section "InputClass"
  Identifier "AMR-4630-XXX-0- 0-1023 USB KEYBOARD Mouse"
  Option "AccelSpeed" "1"
  Option "ScrollMethod" "button"
  Option "ScrollButton" "22"
  Option "MiddleEmulation" "on"
EndSection
EOT

# increase console font
sed -i 's/FONTSIZE="8x16"/FONTSIZE="16x32"/' /etc/default/console-setup