updateKernel 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. baseUrl="https://kernel.ubuntu.com/~kernel-ppa/mainline/"
  3. # read the current kernel version
  4. currentVersion=$(uname -r | grep -oP [0-9.]+-[0-9]+)
  5. echo "The currently used kernel version is $currentVersion."
  6. # get all version folders, remove the duplicates and move the latest to top
  7. versions="$(curl -s $baseUrl | grep -E v[0-9]+\\.[0-9]+\(\\.[0-9]+\)?\/ -o | sort -u -t . -k1.2,1nr -k2,2nr -k3,3nr)"
  8. # store the first item in a variable
  9. read latest <<< $versions
  10. # find all .deb files for amd64 or all and filter out the ones which contain the current version
  11. amd64Packages="$(curl -s $baseUrl$latest | grep -P linux.+?_\(amd64\|all\).deb -o | sort -u | grep -P \(generic\|all\) | grep -v $currentVersion)"
  12. # create a temp folder, download the deb files and install them
  13. if [ ! -z "$amd64Packages" ]; then
  14. # let the user confirm the installation
  15. shouldInstall="y"
  16. read -p "New kernel found: ${latest/v/}. Shall I install it? (Y/n)? " shouldInstall
  17. if [ "$shouldInstall" = "n" ]; then
  18. echo "New kernel $latest was not installed."
  19. exit
  20. fi
  21. targetDir="/tmp/updateKernel/$latest"
  22. mkdir -p $targetDir
  23. cd $targetDir
  24. for package in $amd64Packages; do
  25. wget $baseUrl$latest$package
  26. done;
  27. sudo dpkg -i *.deb
  28. else
  29. echo "No new kernel version found."
  30. fi