source: branches/stable/mindi/distributions/debian/FindDistroFailsafe @ 1062

Last change on this file since 1062 was 1062, checked in by andree, 13 years ago

Add script for finding distribution specific FAILSAFE kernel and add
hooks for calling it to mindi.
(Merge Debian enhancement into mainstream.)

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1# /usr/lib/mindi/DebFindFailsafe
2#
3# DebFindFailsafe - Find correct FAILSAFE kernel to use on Debian systems.
4#
5# Approach:
6# - get architecture
7# - get kernel version (e.g. '2.6' or '2.4') of running kernel
8# - find matching latest generic kernel using list of virtual candiates
9#
10# Caveats:
11# - candiates lists need to be maintained manually; not too much overhead
12# - the kernel relases don't have to match, i.e. a 2.6.12 could be running and
13#   a 2.6.15 might get selected as failsafe; probably ok
14#
15# Changelog:
16# 28Jan06AL: - initial version
17# 12Feb06AL: - removed 'FATAL ERROR' from error messages
18#            - check for status of kernel package, not dpkg (silly glitch)
19#            - tell users to install kernel package when not found
20#            - turned from independent script into snippet that is sourced by mindi
21#              (prefixed all variables with 'EXT_' as external name space)
22#            - use Die for better error reporting (possible through previous step)
23#
24
25
26# Define candiate lists for virtual kernel packages
27EXT_virt_kernel_pkg_cand_amd64_26="linux-image-2.6-amd64"
28EXT_virt_kernel_pkg_cand_i386_24="kernel-image-2.4-386"
29EXT_virt_kernel_pkg_cand_i386_26="linux-image-2.6-486 kernel-image-2.6-386 linux-image-386" # Sarge Etch/Sid Breezy
30EXT_virt_kernel_pkg_cand_ia64_24="kernel-image-2.4-itanium"
31EXT_virt_kernel_pkg_cand_ia64_26="linux-image-2.6-itanium kernel-image-2.6-itanium"
32
33####################################################
34# +++ No maintainable parts beyond this point. +++ #
35####################################################
36
37
38# Get architecure of system
39EXT_system_architecture=`dpkg --print-architecture 2> /dev/null`
40if [ $? -ne 0 ]; then
41    Die "Failed to determine system architecture. Terminating."
42fi
43
44# Get version of running kernel
45EXT_kernel_version=`uname -r 2> /dev/null | cut -c1-3 2> /dev/null`
46if [ $? -ne 0 ]; then
47    Die "Failed to get version of running kernel. Terminating."
48fi
49
50# Get virtual kernel package candiates corresponding to architecture and kernel version
51case "$EXT_system_architecture" in
52    "amd64")
53        case "$EXT_kernel_version" in
54            "2.6")
55                EXT_virt_kernel_pkg_cand=$EXT_virt_kernel_pkg_cand_amd64_26 ;;
56            *)
57                Die "Kernel version $EXT_kernel_version not supported on architecture $EXT_system_architecture. Terminating." ;;
58        esac;;
59    "i386")
60        case "$EXT_kernel_version" in
61            "2.4")
62                EXT_virt_kernel_pkg_cand=$EXT_virt_kernel_pkg_cand_i386_24 ;;
63            "2.6")
64                EXT_virt_kernel_pkg_cand=$EXT_virt_kernel_pkg_cand_i386_26 ;;
65            *)
66                Die "Kernel version $EXT_kernel_version not supported on architecture $EXT_system_architecture. Terminating." ;;
67        esac;;
68    "ia64")
69        case "$EXT_kernel_version" in
70            "2.4")
71                EXT_virt_kernel_pkg_cand=$EXT_virt_kernel_pkg_cand_ia64_24 ;;
72            "2.6")
73                EXT_virt_kernel_pkg_cand=$EXT_virt_kernel_pkg_cand_ia64_26 ;;
74            *)
75                Die "Kernel version $EXT_kernel_version not supported on architecture $EXT_system_architecture. Terminating." ;;
76        esac;;
77    *)
78        Die "Architecture $EXT_system_architecture not supported. Terminating." ;;
79esac
80
81# Determine kernel package from virtual candidates
82for EXT_cand in $EXT_virt_kernel_pkg_cand; do
83    EXT_kernel_package=`dpkg --print-avail $EXT_cand 2>/dev/null | grep "^Depends: " | cut -d" " -f2`
84    [ -n "$EXT_kernel_package" ] && break
85done
86if [ -z "$EXT_kernel_package" ]; then
87    Die "Failed to get real kernel package for virtual kernel package candiate(s) $EXT_virt_kernel_pkg_cand. Terminating."
88fi
89
90# Verify that kernel package is installed
91# (This is what users that don't have a suitable kernel to be used as failsafe will see.)
92if [ `dpkg --status $EXT_kernel_package 2>/dev/null | grep -c "Status: install ok installed"` -ne 1 ]; then
93    Die "Debian kernel package $EXT_kernel_package not installed. Please install (one of): $EXT_virt_kernel_pkg_cand. Terminating."
94fi
95
96# Get path to kernel image
97EXT_kernel_image=`dpkg -L "$EXT_kernel_package" 2> /dev/null | grep -m 1 vmlinuz`
98if [ -z "$EXT_kernel_image" ]; then
99    Die "Failed to get path to kernel image from package $EXT_kernel_package. Terminating."
100else
101    # Export kernel version
102    export FAILSAFE_KBIN="$EXT_kernel_image"
103    export FAILSAFE_KVER="`echo $EXT_kernel_image | cut -d- -f2-`"
104fi
Note: See TracBrowser for help on using the repository browser.