Advertisement
big_bum

KMP Ubuntu

Oct 31st, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.96 KB | None | 0 0
  1. #!/bin/bash
  2. # © Stefanescu Cristian 2014
  3. # This bash script checks the last kernel version available from Ubuntu mainline PPA
  4. # and downloads the debs so you can install them easier.
  5. # It's a stupid description and I'll probably change it in the near future.
  6.  
  7.  
  8. ARCH=`uname -m`; if [[ $ARCH == "x86_64" ]]; then ARCH="amd64"; else ARCH="i386"; fi
  9. URL="http://kernel.ubuntu.com/~kernel-ppa/mainline"
  10. TEMP="/tmp/mainline.html"
  11. STRIP="/tmp/mainline.strip"
  12. SORTED="/tmp/mainline.sort"
  13. KVPAGE="/tmp/kver.html"
  14.  
  15. # download and save the mainpage to a temporary location
  16. echo "Downloading URL"
  17. wget "$URL" -O "$TEMP" > /dev/null 2>&1
  18.  
  19. # get rid of html tags, print the first column and sort it in reverse
  20. sed 's/<[^>]\+>/ /g' -i "$TEMP"; awk '{print $1}' "$TEMP" > "$STRIP"; sort -rV "$STRIP" > "$SORTED"
  21.  
  22. # stable or rc?
  23. # grep for rc if the user wants an rc version, exclude rc from searching if the user wants a stable version
  24. # store the lines in an array, but no more then 10 kernel versions
  25. # You can set the number of kernel versions in head -n10, but since we want the latest kernel, only 10 versions are fine
  26. read -p "Do you want to install a stable version? [Y/n]
  27. " kver
  28. if [[ $kver == [Yy] || $kver == "" ]]; then
  29.     ver_arr=( $(grep -v "rc" "$SORTED" | head -n10 | awk '{for (f = 1; f <= NF; f++) { a[NR, f] = $f } } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) { for (r = 1; r <= NR; r++) { printf a[r, f] (r==NR ? RS : FS) } } }') )
  30. else
  31.     ver_arr=( $(grep "rc" "$SORTED" | head -n10 | awk '{for (f = 1; f <= NF; f++) { a[NR, f] = $f } } NF > nf { nf = NF } END { for (f = 1; f <= nf; f++) { for (r = 1; r <= NR; r++) { printf a[r, f] (r==NR ? RS : FS) } } }') )
  32. fi
  33. # the following code depends on the previous answer, because we use the same array for each case (stable/rc)
  34. # present the array in a friendly way so we can choose a number for a kernel version, if we don't want the latest kernel
  35. echo "Select the version you want to install (Default is the latest, [0])"
  36. for i in $(seq 0 $((${#ver_arr[@]} - 1))); do
  37.     line="${ver_arr[$i]}"
  38.     echo "[$i]. ${line}"
  39. done
  40.  
  41. read -p "Enter the number correpsonding to the kernel version you want installed
  42. " v
  43. if [[ $v == "" ]]; then
  44.     ver_id=$(echo ${ver_arr[0]} | awk '{ print $NF }')
  45. else ver_id=$(echo ${ver_arr[$v]} | awk '{ print $NF }')
  46. fi
  47.  
  48. # get the kernel's version page, so we can build the download links from the html
  49. # save it as $KVPAGE
  50. # grep through $KVPAGE for a generic or a lowlatency kernel
  51. # grep for the headers
  52. wget "$URL/$ver_id" -O "$KVPAGE" > /dev/null 2>&1
  53.  
  54. read -p "Do you want a lowlatency kernel? [N/y]
  55. " latency
  56. if [[ $latency == [Yy] ]]; then
  57.     KERNEL=`grep -E "href.*image.*$ARCH.*latency.*deb" $KVPAGE | sed 's/<[^>]\+>/ /g' | awk '{print $1}'`
  58. else KERNEL=`grep -E "href.*image.*$ARCH.*generic.*deb" $KVPAGE | sed 's/<[^>]\+>/ /g' | awk '{print $1}'`
  59. fi
  60.  
  61. read -p "Download headers? [Y/n]
  62. " headers
  63. if [[ $headers == [Yy] || $headers == "" ]] && [[ $latency == [Yy] ]]; then
  64.     HEADERS=`grep -E "href.*headers.*$ARCH.*latency.*deb" $KVPAGE | sed 's/<[^>]\+>/ /g' | awk '{print $1}'`
  65. else HEADERS=`grep -E "href.*headers.*$ARCH.*generic.*deb" $KVPAGE | sed 's/<[^>]\+>/ /g' | awk '{print $1}'`
  66. fi
  67.  
  68. echo "Downloading the files"
  69. cd /tmp
  70. wget -c "$URL"/"$ver_id"/"$KERNEL" --progress=bar:force 2>&1 | tail -f -n +6
  71. if [[ $headers == [Yy] || $headers == "" ]]; then
  72.     HEADERS_ALL=`grep -E "href.*headers.*all.*deb" $KVPAGE | sed 's/<[^>]\+>/ /g' | awk '{print $1}'`
  73.     wget -c "$URL"/"$ver_id"/"$HEADERS" --progress=bar:force 2>&1 | tail -f -n +6
  74.     wget -c "$URL"/"$ver_id"/"$HEADERS_ALL" --progress=bar:force 2>&1 | tail -f -n +6
  75. fi
  76.  
  77. read -p "Install the mthrf0cker? [Y/n]
  78. " install
  79. if [[ $install == [Yy] || $install == "" ]]; then
  80.     sudo dpkg -i $KERNEL
  81.     if [[ $headers == [Yy] || $headers == "" ]]; then
  82.         sudo dpkg -i $HEADERS_ALL $HEADERS
  83.     fi
  84. fi
  85.  
  86. read -p "Delete the *.deb files? [Y/n]
  87. " deb
  88. if [[ $deb == [Yy] || $deb == "" ]]; then
  89.     rm -v $KERNEL
  90.     if [[ -e $HEADERS ]]; then
  91.         rm -v $HEADERS_ALL $HEADERS
  92.     fi
  93. fi
  94.  
  95. #cleanup
  96. rm $TEMP $STRIP $SORTED $KVPAGE
  97. unset ver_arr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement