Debian Codegraph @

installkernel

raw
1 #!/bin/sh
2 #
3 # Copyright (C) 1995 - 1998, Ian A. Murdock <[email protected]>
4 # Copyright (C) 1998, 1999, Guy Maor
5 # Copyright (C) 2002, Matthew Wilcox
6 # Copyright (C) 2002, 2004, 2005, 2007, 2009 Clint Adams
7 # Copyright (C) 2009 Manoj Srivasta
8 #
9 # Install the kernel on a Debian Linux system.
10 #
11 # This script is called from /usr/src/linux/arch/i386/boot/install.sh.
12 # If you install it as /sbin/installkernel, you can do a "make install"
13 # from a generic kernel source tree, and the image will be installed to
14 # the proper place for Debian GNU/Linux.
15
16 set -e
17
18 # Parse the command line options. Of course, powerpc has to be all
19 # different, and passes in a fifth argument, just because it is
20 # "special". We ignore the fifth argument, and do not flag is as an
21 # error, which it would be for any arch apart from powerpc
22 if [ $# -eq 3 ] || [ $# -eq 4 ] || [ $# -eq 5 ] ; then
23 img="$2"
24 map="$3"
25 ver="$1"
26 if [ $# -ge 4 ] && [ -n "$4" ] ; then
27 dir="$4"
28 else
29 dir="/boot"
30 fi
31 else
32 echo "Usage: installkernel <version> <image> <System.map> <directory>"
33 exit 1
34 fi
35
36 # Create backups of older versions before installing
37 updatever () {
38 if [ -f "$dir/$1-$ver" ] ; then
39 mv "$dir/$1-$ver" "$dir/$1-$ver.old"
40 fi
41
42 cat "$2" > "$dir/$1-$ver"
43
44 # This section is for backwards compatibility only
45 if test -f "$dir/$1" || test -h "$dir/$1" ; then
46 # The presence of "$dir/$1" is unusual in modern intallations, and
47 # the results are mostly unused. So only recreate them if they
48 # already existed.
49 if test -L "$dir/$1" ; then
50 # If we were using links, continue to use links, updating if
51 # we need to.
52 if [ "$(readlink -f ${dir}/${1})" = "${dir}/${1}-${ver}" ]; then
53 # Yup, we need to change
54 ln -sf "$1-$ver.old" "$dir/$1.old"
55 else
56 mv "$dir/$1" "$dir/$1.old"
57 fi
58 ln -sf "$1-$ver" "$dir/$1"
59 else # No links
60 mv "$dir/$1" "$dir/$1.old"
61 cat "$2" > "$dir/$1"
62 fi
63 fi
64 }
65
66 case "$(basename $img)" in
67 "vmlinux"|"Image")
68 img_dest=vmlinux
69 ;;
70 *)
71 img_dest=vmlinuz
72 ;;
73 esac
74 updatever $img_dest "$img"
75 updatever System.map "$map"
76
77 config=$(dirname "$map")
78 config="${config}/.config"
79 if [ -f "$config" ] ; then
80 updatever config "$config"
81 fi
82
83 # If installing in the usual directory, run the same scripts that hook
84 # into kernel package installation. Also make sure the PATH includes
85 # /usr/sbin and /sbin, just as dpkg would.
86 if [ "$dir" = "/boot" ]; then
87 PATH="$PATH:/usr/sbin:/sbin" \
88 run-parts --verbose --exit-on-error --arg="$ver" --arg="$dir/$img_dest-$ver" \
89 /etc/kernel/postinst.d /usr/share/kernel/postinst.d
90 fi
91
92 exit 0