Os espertos que tenham piedade de mim pois certamente terá um modo muito mais bonito e eficaz pra obter o mesmo resultado.
Quem tiver paciência pra me dar uma mãozinha pra melhorar esse scrip seja bem vindo!
Paulo
Atualizações:
20/07 - substituido o lynx
26/07 + verifica de conexão
- Código: Selecionar todos
#!/bin/sh
# https://www.dropbox.com/s/7sqojrtgfpax955/updatekernel.sh
##check connection
if ! [ "$(ping -c 1 kernel.ubuntu.com)" ]; then echo "\n\tConnect and try again.\n"; exit ; fi
##check install wget html2text
for n in wget html2text; do if ! [ "$(which $n)" ]; then sudo apt-get install -y $n ; fi ; done
http="http://kernel.ubuntu.com/~kernel-ppa/mainline/"
folderversion=$(wget -q -O- $http | html2text | grep DIR | cut -d " " -f 2 | grep -v rc | tail -n 1)
LinkLastVersion=${http}${folderversion}
LastKernelAvaliable=$(echo $folderversion | cut -d "-" -f1 | tr -d v )
#if is a first major revision (es.: 3.10) add ".0" (es.: 3.10.0)
if [ -z $(echo $LastKernelAvaliable | cut -d "." -f3) ] ; then LastKernelAvaliable=${LastKernelAvaliable}".0"; fi
LastKernelInstalled=$(ls /boot/ | grep img | cut -d "-" -f2 | sort -V | tail -n 1)
if [ $LastKernelInstalled = $LastKernelAvaliable ]
then echo "\n\n\t Your kernel is updated: " $LastKernelInstalled "\n\n"
exit
else echo "\n\n\t Your Kernel is: " $LastKernelInstalled "\n\t Kernel Avaliable: " $LastKernelAvaliable "\n\n"
sleep 2 ; read -p "Press Enter to install the last version, or abort by pressing CTRL+C" nothing
fi
#arch
arch=`uname -m`
if [ $arch = i686 ] || [ $arch = i386 ]; then myarch="i386"; elif [ $arch = "x86_64" ]; then myarch="amd64"; else echo "Unsupported Architecture"; fi
#### list links to download
listdebs=$( wget -q -O- $LinkLastVersion | html2text -width 200 | tr [:blank:] + | cut -d "+" -f 5 | egrep 'all.deb|'$myarch'.deb')
linkdebs=$(for deb in $listdebs; do echo $LinkLastVersion$deb; done)
#### download, install and remove folder download
DownloadFolder=/tmp/kernel_$LastKernelAvaliable ; mkdir -p $DownloadFolder ; cd $DownloadFolder
wget $( echo "$linkdebs" )
sudo dpkg -i *.deb
sudo rm -rf $DownloadFolder
### Remove old kernel
OldVersion=$(ls /boot/ | grep img | cut -d "-" -f2,3 | sort -V | tail -n2 | head -n1)
ifremove="Press Enter to remove the old kernel $OldVersion, or abort by pressing CTRL+C"
echo "/n/n" ; read -p "$ifremove" nothing
sleep 3 ; echo "/n/n"
read -p "Are you sure? $ifremove" nothing
sudo apt-get remove $OldVersion