update-kernel/update_kernel_modules_cetus.sh
2009-10-17 11:31:49 +03:00

169 lines
5.7 KiB
Bash
Executable File

#!/bin/bash
# Copyright (C) 2004 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2005-2008 Anatoly Kitaykin <cetus@newmail.ru>
# Copyright (C) 2008-2009 Vladimir V. Kamarzin <vvk@altlinux.org>
# Copyright (C) 2008-2009 Michael Shigorin <mike@altlinux.org>
# Copyright (C) 2008 Konstantin Baev <kipruss@altlinux.org>
#
# Update kernel with modules
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
. shell-error
show_help()
{
cat <<EOF
Usage: $PROG [options]
Valid options are:
-f, --force force kernel upgrade
-t, --type install kernel with specified flavour (ovz-smp, std-def, etc)
-r, --release install kernel with specified release (alt10, alt22, etc)
-h, --help show this text and exit
EOF
exit 1
}
#parse command line options
TEMP=`getopt -n $PROG -o f,t:,r:,h -l force,type:,release:,help -- "$@"` || show_help
eval set -- "$TEMP"
while :; do
case "$1" in
--) shift; break
;;
-f|--force) force=1
;;
-t|--type) shift ; kernel_flavour="$1"
;;
-r|--release) shift ; release="$1"
;;
-h|--help) show_help
esac
shift
done
###################################################################
# update kernel
# get list of all available kernel packages
KERNEL_PKGS="$(apt-cache pkgnames kernel-image)"
# set kernel flavour. if not defined with -t option, use current
current_kernel_flavour="$(uname -r | cut -d "-" -f2,3)"
kernel_flavour="${kernel_flavour:-$current_kernel_flavour}"
# check that we have at least one kernel with defined kernel_flavour
num_available_kernels="$(echo "$KERNEL_PKGS" | grep -c "$kernel_flavour")"
[ "$num_available_kernels" != 0 ] || fatal "There are no available kernels with kernel flavour $kernel_flavour"
# check that we have at least one kernel with defined kernel package release
[ -z "$release" ] || {
num_available_kernels="$(echo "$KERNEL_PKGS" | grep -c "$release")"
[ "$num_available_kernels" != 0 ] || fatal "There are no available kernels with package release $release"
}
# define how we must select available packages with needed flavour/release
[ -z "$release" ] && pgkgrep="kernel-image-$kernel_flavour#" || pgkgrep="kernel-image-$kernel_flavour#.*$release$"
# get the maximum available kernel package version
kmaxver=
while read version
do
comparever="$(rpmevrcmp "$kmaxver" "$version")"
[ "$comparever" -lt 0 ] && kmaxver="$version" ||:
done < <(echo "$KERNEL_PKGS" | grep "$pgkgrep" | sed -e "s,^kernel-image-$kernel_flavour#,,g")
# ask user
echo -n "Try to install new kernel kernel-image-$kernel_flavour-$kmaxver and update its modules [y]/n? "
[ "$force" = 1 ] && echo "yes" || {
read
case "$REPLY" in
n|no|N|No|NO|0) exit 0
;;
*)
;;
esac
}
# is there kernel-image-$kernel_flavour already installed or not?
# needed for proper modules selection
rpm -q kernel-image-"$kernel_flavour" &>/dev/null && modules_kernel_flavour="$kernel_flavour" \
|| modules_kernel_flavour="$current_kernel_flavour"
# use sudo(1) if running as unprivileged user
[ "$UID" = "0" ] && SUDO= || SUDO=sudo
$SUDO apt-get install -y "kernel-image-$kernel_flavour#$kmaxver" \
|| fatal "failed to install kernel-image-$kernel_flavour-$kmaxver"
###################################################################
# update modules
# strip serial/epoch before installing modules
kmaxver=${kmaxver##*:}
# latest kernel package name
LATESTKERNEL="kernel-image-$kernel_flavour-$kmaxver"
# "version-kernel_flavour-release" for latest kernel package
newkernel_ver_flav_rel="$(rpm -q $LATESTKERNEL --queryformat "%{VERSION}-$kernel_flavour-%{RELEASE}")" \
|| fatal "Cannot get newkernel_ver_flav_rel. Please report \`bash -x sisyphus-mirror' output to bugzilla"
message "Updating modules for kernel: $newkernel_ver_flav_rel"
# get list of all available modules
ALLMODULES="$(apt-cache pkgnames kernel-modules | grep $kernel_flavour | sed -e "s,^kernel-modules-\(.*\)-$kernel_flavour.*,\1,g"| sed -e "s,-[[:digit:]]\.[[:digit:]]\.[[:digit:]].*,,g" | sort -u)"
for module in $ALLMODULES; do
module_pkgname=kernel-modules-$module
if rpm -q $module_pkgname-"$modules_kernel_flavour" &>/dev/null; then
message "$module_pkgname is installed, trying to update..."
$SUDO apt-get install -y "$module_pkgname-$newkernel_ver_flav_rel"
fi
done
# try to run x11setupdrv, x11presetdrv
# if might need that (e.g. for nvidia_glx updates)
# NB: x11setupdrv seems deprecated in Sisyphus as of Oct 2009
X11SETUPDRV=/usr/bin/x11setupdrv
X11PRESETDRV=/usr/sbin/x11presetdrv
XORG=/usr/bin/Xorg
[ ! -x "$XORG" ] || \
case "$ALLMODULES" in
*drm*|*fglrx*|*nvidia*)
[ -x "$X11SETUPDRV" ] \
&& $SUDO "$X11SETUPDRV"
[ -x "$X11PRESETDRV" ] \
&& $SUDO "$X11PRESETDRV" \
|| message "You might need to run x11presetdrv, video drivers updated but it's missing"
$SUDO ldconfig
;;
esac
###################################################################
# update headers
for package in kernel-headers kernel-headers-modules; do
if rpm -q $package-"$kernel_flavour" &>/dev/null; then
message "$package is installed, trying to update..."
$SUDO apt-get install -y "$package-$kernel_flavour"
fi
done