#!/bin/env bash

if ! [ -x "$(command -v lsb_release)" ]; then
  echo 'This does not look like a Ubuntu System!' >&2
  exit 1
fi

if ! [ "$(lsb_release -r -s)" == "12.04" ]; then
  echo 'This is Script is designed for Ubuntu 12.04!\n Press enter to continue or CTRL+C to stop!'
  read
fi

echo "Creating apt preference file..."
sudo cat > /etc/apt/preferences.d/intel-removal <<EOF
Package: *
Pin: release a=quantal*
Pin-Priority: 1001
Package: *
Pin: origin download.01.org
Pin-Priority: -100
EOF

echo "Running apt-get dist-upgrade..."
sudo apt-get dist-upgrade

echo "Running apt-get purge..."
sudo apt-get purge i915-3.6-3.5-dkms intel-linux-graphics-installer

echo "Cleaning up..."
sudo rm /etc/apt/preferences.d/intel-removal
sudo rm /etc/apt/sources.list.d/intellinuxgraphics.list*
sudo apt-get update

echo "Please reboot and check for errors!"
