diff --git a/bbr.sh b/bbr.sh index b59b5b8..41d0b9b 100644 --- a/bbr.sh +++ b/bbr.sh @@ -34,13 +34,22 @@ elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then release="centos" fi -if [[ `getconf WORD_BIT` == "32" && `getconf LONG_BIT` == "64" ]]; then - deb_kernel_url="http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.3/linux-image-4.9.3-040903-generic_4.9.3-040903.201701120631_amd64.deb" - deb_kernel_name="linux-image-4.9.3-amd64.deb" -else - deb_kernel_url="http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.3/linux-image-4.9.3-040903-generic_4.9.3-040903.201701120631_i386.deb" - deb_kernel_name="linux-image-4.9.3-i386.deb" -fi +get_latest_version() { + + latest_version=$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/ | awk -F'\"v' '/v[4-9].[0-9].[0-9]/{print $2}' | cut -d/ -f1 | sort -V | tail -1) + + if [[ `getconf WORD_BIT` == "32" && `getconf LONG_BIT` == "64" ]]; then + deb_name=$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${latest_version}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/amd64.deb/{print $2}' | cut -d'<' -f1 | head -1) + deb_kernel_url="http://kernel.ubuntu.com/~kernel-ppa/mainline/v${latest_version}/${deb_name}" + deb_kernel_name="linux-image-${latest_version}-amd64.deb" + else + deb_name=$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${latest_version}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/i386.deb/{print $2}' | cut -d'<' -f1 | head -1) + deb_kernel_url="http://kernel.ubuntu.com/~kernel-ppa/mainline/v${latest_version}/${deb_name}" + deb_kernel_name="linux-image-${latest_version}-i386.deb" + fi + + [ ! -z ${latest_version} ] && return 0 || return 1 +} get_opsy() { [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return @@ -159,13 +168,15 @@ install_bbr() { fi elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then [[ ! -e "/usr/bin/wget" ]] && apt-get -y update && apt-get -y install wget + get_latest_version + [ $? -ne 0 ] && echo -e "${red}Error:${plain} Get latest kernel version failed." && exit 1 wget -c -t3 -T60 -O ${deb_kernel_name} ${deb_kernel_url} if [ $? -ne 0 ]; then echo -e "${red}Error:${plain} Download ${deb_kernel_name} failed, please check it." exit 1 fi dpkg -i ${deb_kernel_name} - rm -f ${deb_kernel_name} + rm -fv ${deb_kernel_name} else echo -e "${red}Error:${plain} OS is not be supported, please change to CentOS/Debian/Ubuntu and try again." exit 1