Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 865 lines (720 sloc) 20.8 KB
#!/bin/sh
##
## installkernel - Script for installing Linux kernel.
## Copyright 2004-2012 by Michal Nazarewicz (mina86/AT/mina86.com)
##
## This program 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 3 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, see <http://www.gnu.org/licenses/>.
##
## This is part of Tiny Applications Collection
## -> http://tinyapps.sourceforge.net/
##
##
## Basic initialization
##
set -e
USER="$(id -un)"
ARG0="${0##*/}"
LOWER_CHARS=abcdefghijklmnopqrstuvwxyz-
UPPER_CHARS=ABCDEFGHIJKLMNOPQRSTUVWXYZ_
trap "" USR1 USR2
##
## Converts string to integer
##
toInt () {
expr 0$(expr "X$1" : 'X[[:space:]]*\([0-9]*\)') + 0 2>/dev/null || true
}
##
## Version & lockfile
##
if [ -z "$INSIDE_INSTALLKERNEL" ]; then
echo 'installkernel v17.0 (c) 2004-2012 by Michal Nazarewicz'
echo
# Lockfile check
IK_LOCK=/tmp/installkernel-lockfile
if [ -d /var/lock ] && [ -w /var/lock ]; then
IK_LOCK=/var/lock/installkernel-lck
fi
ERR=
ln -s $$ "$IK_LOCK" >/dev/null 2>&1 || ERR=y
PID=`readlink "$IK_LOCK"`
if [ -n "$ERR" ] || [ $PID -ne $$ ]; then
cat <<EOF
$ARG0: seems like another instance of installkernel is running
$ARG0: with pid $PID, make sure there is only one instance and
$ARG0: remove $IK_LOCK if that is the case.
EOF
exit 4
fi
unset ERR PID
export IK_LOCK
fi
##
## Help
##
usage () {
cat<<END
usage: installkernel [<options>] [<switches>]
[<version> [<image> [<systemmap> [<prefix>]]]]
<options> are:
-h --help Display this screen and exits
-V --version Display vesion and exits
-a --arch=<arch> Set ARCH variable to <arch> or \$ARCH if '-' [auto]
--kversion=<ver> Same as <version>
--image=<image> Same as <image>
--map=<systemmap> Same as <systemmap>
--bootdir=<dir> Same as <prefix>
--cd[=<dir>] Change directory to <dir> (/usr/src/linux if ommited)
-o --out[=<dir>] Build kernel in <dir> (/usr/src/linux-build if ommited)
--su Trt to became root (implies --user=<current-user>)
-u --user=<user> Runs everything not requiring SU privilages as <user>
-nu --no-user Synonym of --user=
--nice=<nice> Adjust priority by <nice> (but never lower)
--nice=!<nice> Set pririty to <nice> (but never lower) [10]
--no-nice Synonym of --nice=0
-j --jobs=<jobs> Pass -j<jobs> to make [auto]
-- This option causes all options not starting with a
dash to be interpreted as long (if at least 3-char
long) or short (if no more then 2-char long) options
<switches> are:
--dry-run Only display what would be done [no]
--print-commands Print commands [no]
-v --verbose Become more verbose [no]
-vv Become even more verbose [no]
--color Use colors [auto]
-r<hook>
--run-<hook> Run given hook, event or set of hooks [yes]
-c --clean Run 'make clean' before compilation [no]
-C --config Run 'make (x|g|menu|)config' to configure [no]
-C --config=<cfg> Specify a type of config to run [auto]
--*config Synonym of --config=*config
-d --make-dep Run 'make dep' [**]
-O --overwrite Overwrite the kernel image [no]
-A --all Synonym of all of the below
-i --compile-image Run 'make bzImage' to compile image [no]
-I --install-image Copy kernel to bootdir and update symlinks [*]
-t --tidy-image Remove old images [no]
--image Synonym of the three above
-m --compile-modules Run 'make modules' [no]
-M --install-modules Run 'make modules_install' [no]
-T --tidy-modules Remove old modules [no]
--modules Synonym of the three above
--compile Synonym of --compile-image --compile-modules
--install Synonym of --install-image --install-modules
--tidy Synonym of --tidy-image --tidy-modules
[*] yes if only <version> <image> <systemmap> and <bootdir> where given.
[**] yes if compiling image and <version> is 2.4.x.
Negated by prefixing switch with 'no-' (long option) or 'n' (short option).
<version> kernel version [auto]
<image> path to kernel image [arch/\$ARCH/boot/bzImage]
<systemmap> path to System.map file [System.map]
<prefix> directory where to install the kernal image [/boot]
END
}
##
## Printing helpers
##
error () {
__EC="$1"
shift
echo "${0##*/}: $*" >&2
INSTALLKERNEL_EXITED=$__EC
exit $__EC
}
msg () {
if [ -n "$USE_ANSI" ] && [ -n "$1" ]
then printf ' \33[%sm%-7s %s\33[0m\n' "$1" "$2" "$3"
else printf ' %-7s %s\n' "$2" "$3"
fi
}
##
## Signals etc
##
sig_handler () {
msg 31 SIG "Got SIG$1; terminating..."
error 5 "Got SIG$1; terminating..."
}
for E in HUP INT QUIT ILL ABRT FPE SEGV PIPE ALRM TERM TSTP; do
trap "sig_handler $E" $E
done
unset E
exit_function () {
__EC=$?
rm -f -- "$IK_LOCK"
if [ $__EC -ne 0 ] && [ "X$INSTALLKERNEL_EXITED" != "X$__EC" ]; then
msg 31 ERR "Comand's exit code: $__EC"
error $__EC "Comand's exit code: $__EC"
fi
return 0
}
trap exit_function 0
##
## Prints header
##
if [ -z "$COLUMNS" ]; then
COLS=`toInt "$(stty -a | sed -ne 's/^.*columns[[:space:]][[:space:]]*\([0-9][0-9]*\).*$/\1/p')"`
if [ $COLS -gt 30 ]; then
COLUMNS=$COLS
export COLUMNS
fi
unset COLS
fi
header () {
__TITLE="$*"
if [ -n "$USE_ANSI" ]
then printf "\33[32m=== \33[1m%s\33[0;32m " "$__TITLE"
else printf "=== %s " "$__TITLE"
fi
__LOOP=$(( ${COLUMNS-80} - ${#__TITLE} - 29))
__STR=
while [ $__LOOP -gt 0 ]; do
__STR="$__STR="
__LOOP=$(( $__LOOP - 1 ))
done
date +"$__STR [%y/%m/%d %H:%M:%S] ==="
if [ -n "$USE_ANSI" ]; then printf '\33[0m'; fi
unset __TITLE __STR __LOOP
}
##
## Runs command
##
run () {
__AS=
__SILENT=
__DUMMY=
__FORCE=
__INPUT=
__OUTPUT=
# Arguments
while expr "X$1" : X- >/dev/null 2>&1; do
__ARG="${1#-}"; shift;
while [ -n "$__ARG" ]; do
case "$__ARG" in
u*) __AS="$RUNAS";;
s*) __SILENT=yes ;;
f*) __FORCE=yes ;;
d*) __DUMMY=yes ;;
i*) __INPUT="$1" ; shift;;
o*) __OUTPUT="$1"; shift;;
esac
__ARG="${__ARG#?}"
done
done
# Dry run
if [ -n "$DRY_RUN$PRINT_COMMANDS" ] && [ -z "$__SILENT" ]; then
if [ $__AS ]; then __MSG="[as $__AS] "; else __MSG=""; fi
__END=""
if [ -n "$__INPUT" ]; then __END="<$__INPUT "; fi
if [ -n "$__OUTPUT" ]; then __END="$__END>$__OUTPUT"; fi
msg '36' RUN "$__MSG`printf "'%s' " "$@"`$__END"
fi
# Don't run really
if [ -n "$DRY_RUN" ] && [ -z "$__FORCE" ]; then return 0; fi
if [ -n "$__DUMMY" ]; then return 0; fi
# cd cannot be run throught su or nice
if [ "X$1" = Xcd ]; then
"$@"
return $?
fi
# Run as
if [ -n "$__AS" ] && [ "X$__AS" != "X$USER" ]; then
__ARGS=
while [ $# -ne 0 ]; do
__ARGS="$__ARGS '`echo "$1" | sed -e "s/'/'\\\\''/"`'"
shift
done
set -- su "$__AS" -c "$__ARGS"
unset __ARGS
fi
# Run
if [ -z "$__INPUT$__OUTPUT" ]; then "$@"
elif [ -z "$__INPUT" ]; then "$@" |>"$__OUTPUT"
elif [ -z "$__OUTPUT" ]; then "$@" <"$__INPUT"
else "$@" <"$__INPUT" |>"$__OUTPUT"
fi
}
##
## Runs /etc/installekrnel.d/hook-handler scripts
##
if [ -x /etc/installkernel.d/hook-handler ]; then
run_hook () {
case "$RUN_HOOKS" in
*:"$1":*)
__HOOK=$1
shift
run "$@" /etc/installkernel.d/hook-handler "$__HOOK"
unset __HOOK
esac
}
else
run_hook () {
true
}
fi
##
## Prints header, run_hook and run on condition
##
r () {
if [ "X$1" = X-u ]; then __USR=-u; shift; else __USR=; fi
if eval [ -z \"\$$1\" ]; then return 0; fi
__NAME=`echo $1 | tr $UPPER_CHARS $LOWER_CHARS`
header "$2"
shift 2
run_hook pre-$__NAME $__USR
run $__USR "$@"
run_hook post-$__NAME $__USR
unset __NAME __USR
}
##
## Reads kernel version number
##
update_ver () {
if [ -z "$VER" ]; then
VER=${KBUILD_OUTPUT:-.}/include/config/kernel.release
if [ -e "$VER" ]; then
read VER <$VER
msg '37;1' VER "$VER"
else
error 2 "$VER: file does not exist"
fi
fi
}
##
## Set hooks
##
# set_run_hooks <value> [ <prefix> [ <hook> ] ]
set_run_hooks () {
if [ X"$3" = Xhooks ] || [ -z "$3" ]; then set -- "$1" "$2"; fi
if [ $# -eq 2 ] && [ -z "$2" ]; then set -- "$1"; fi
if [ $# -eq 1 ] && [ -z "$1" ]; then set --; fi
# Remove all
if [ $# -eq 0 ]; then
RUN_HOOKS=:
export RUN_HOOKS
return 0
fi
# Add all
if [ $# -eq 1 ]; then
RUN_HOOKS=:
set -- clean config make-dep compile-image
set -- "$@" install-image tidy-image compile-modules
set -- "$@" install-modules tidy-modules work
while [ $# -gt 0 ]; do
RUN_HOOKS="${RUN_HOOKS}pre-$1:post-$1:"
shift
done
export RUN_HOOKS
return 0
fi
# Prepare arguments for later processing
if [ $# -eq 2 ]; then
__PRE="$2"
set -- "$1"
for __EV in clean config make-dep compile-image \
install-image tidy-image compile-modules install-modules \
tidy-modules work; do
set -- "$1" "$__PRE-$__EV"
done
unset __EV
elif [ -n "$2" ]; then
set -- "$1" "$2-$3"
else
set -- "$1" "pre-$3" "post-$3"
fi
if [ -n "$1" ]; then
# Add
shift
while [ $# -gt 0 ]; do
case "$RUN_HOOKS" in
*:$1:*) ;;
*) RUN_HOOKS="$RUN_HOOKS$1:"
esac
shift
done
else
# Remove
shift
while [ $# -gt 0 ]; do
case "$RUN_HOOKS" in
*:$1:*) RUN_HOOKS=${RUN_HOOKS%:$1:*}:${RUN_HOOKS#*:$1:}
esac
shift
done
fi
export RUN_HOOKS
}
if [ -z "$INSIDE_INSTALLKERNEL" ]; then
##
## Init default options
##
if [ -z "$INSTALL_PATH" ]; then
INSTALL_PATH=/boot
export INSTALL_PATH
fi
SU=; NICE=!10; __ARCH="$ARCH"; DASHDASH=
VER=; BUILD=; IMG_PATH=; MAP_PATH=; RUNAS=; ARCH=; JOBS=auto
KBUILD_OUTPUT=
export VER BUILD IMG_PATH MAP_PATH RUNAS ARCH KBUILD_OUTPUT
DRY_RUN=; PRINT_COMMANDS=; VERBOSE=; REALLY_VERBOSE=;
if [ -t 1 ]; then USE_ANSI=y; else USE_ANSI=; fi
export DRY_RUN PRINT_COMMANDS VERBOSE USE_ANSI
CLEAN=; COMPILE_IMAGE=; COMPILE_MODULES=; INSTALL_IMAGE=;
INSTALL_MODULES=; TIDY_IMAGE=; TIDY_MODULES=;
CONFIG=; MAKE_DEP=auto; OVERWRITE_IMAGE=; MAKE_FLAGS=;
export CLEAN COMPILE_IMAGE COMPILE_MODULES INSTALL_IMAGE
export INSTALL_MODULES TIDY_IMAGE TIDY_MODULES
export CONFIG MAKE_DEP OVERWRITE_IMAGE MAKE_FLAGS
set_run_hooks y
##
## Parse arguments
##
ADD_ARGS=0
NUMARGS=$#
for ARG; do
PARAM=
# Dash dash at work?
if [ -n "$DASHDASH" ]; then
case "$ARG" in
-*) : ;;
?|n?|vv) ARG=-$ARG ;;
*) ARG=--$ARG ;;
esac
fi
## Options
case "$ARG" in
--help|-h) usage; exit 0;;
--version|-V) exit 0;;
--arch=*) ARCH="${ARG#--arch=}";;
-a*) ARCH="${ARG#-a}"; ;;
--kversion=*) VER="${ARG#--kversion=}"; ;;
--image=*) IMG_PATH="${ARG#--image=}"; ;;
--map=*) MAP_PATH="${ARG#--map=}"; ;;
--bootdir=*) INSTALL_PATH="${ARG#--bootdir=}" ;;
--cd=*) CD="${ARG#--cd=}";;
--cd) CD=/usr/src/linux;;
-o|--out) KBUILD_OUTPUT=/usr/src/linux-build;;
-o?*) KBUILD_OUTPUT="${ARG#-o}" ;;
--out=*) KBUILD_OUTPUT="${ARG#--out=}";;
--config=no) CONFIG=;;
--no-config) CONFIG=;;
--noconfig) CONFIG=;;
--config) [ -n "$CONFIG" ] || CONFIG=auto;;
--config=auto) CONFIG=auto;;
--config=*config) CONFIG="${ARG#--config=}";;
--config=*) CONFIG="${ARG#--config=}config";;
--*config) CONFIG="${ARG#--}";;
--su) SU=y; RUNAS="$USER";;
--user=*) RUNAS="${ARG#--user=}";;
-u*) RUNAS="${ARG#-u}";;
-nu|--no-user) RUNAS=;;
--nice=*) NICE="${ARG#--nice=}";;
--no-nice) NICE=0;;
-j?*) JOBS=${ARG#-j};;
--jobs=*) JOBS=${ARG#--jobs=};;
--) DASHDASH=y;;
-r*) VALUE=y; PARAM="--run-${ARG#-r}";;
-nr*) VALUE= ; PARAM="--run-${ARG#-nr}";;
-n?) VALUE= : PARAM="-${ARG#-n}";;
--no-*) VALUE= ; PARAM="--${ARG#--no-}";;
--*) VALUE=y; PARAM="--${ARG#--}";;
-*) VALUE=y; PARAM="$ARG";;
*)
if [ $ADD_ARGS -eq 0 ]; then VER="$ARG"
elif [ $ADD_ARGS -eq 1 ]; then IMG_PATH="$ARG"
elif [ $ADD_ARGS -eq 2 ]; then MAP_PATH="$ARG"
elif [ $ADD_ARGS -eq 3 ]; then INSTALL_PATH="$ARG"
else error 1 unknown option: "$ARG"
fi
ADD_ARGS=$(( $ADD_ARGS + 1 ))
esac
## Switches
if [ -z "$PARAM" ]; then continue; fi
HOOK=
case "$PARAM" in
--dry-run) DRY_RUN=$VALUE ;;
-v|--verbose) VERBOSE=$VALUE ;
if [ -n "$VALUE" ]; then PRINT_COMMANDS=y; fi;;
-vv) REALLY_VERBOSE=$VALUE;
if [ -n "$VALUE" ]; then VERBOSE=y; PRINT_COMMANDS=y; fi;;
--print-commands) PRINT_COMMANDS=$VALUE;;
--color) USE_ANSI=$VALUE;;
-c|--clean) CLEAN=$VALUE ;;
-d|--make-dep) MAKE_DEP=$VALUE ;;
-O|--overwrite) OVERWRITE_IMAGE=$VALUE;;
-i|--compile-image) COMPILE_IMAGE=$VALUE ;;
-I|--install-image) INSTALL_IMAGE=$VALUE ;;
-t|--tidy-image) TIDY_IMAGE=$VALUE ;;
--image) COMPILE_IMAGE=$VALUE ;
INSTALL_IMAGE=$VALUE ; TIDY_IMAGE=$VALUE;;
-m|--compile-modules) COMPILE_MODULES=$VALUE;;
-M|--install-modules) INSTALL_MODULES=$VALUE;;
-T|--tidy-modules) TIDY_MODULES=$VALUE ;;
--modules) COMPILE_MODULES=$VALUE;
INSTALL_MODULES=$VALUE; TIDY_MODULES=$VALUE;;
--compile) COMPILE_IMAGE=$VALUE; COMPILE_MODULES=$VALUE;;
--install) INSTALL_IMAGE=$VALUE; INSTALL_MODULES=$VALUE;;
--tidy) TIDY_IMAGE=$VALUE ; TIDY_MODULES=$VALUE ;;
-A|--all)
COMPILE_IMAGE=$VALUE ; COMPILE_MODULES=$VALUE
INSTALL_IMAGE=$VALUE ; INSTALL_MODULES=$VALUE
TIDY_IMAGE=$VALUE ; TIDY_MODULES=$VALUE
;;
--run-*) HOOK="${PARAM#--run-}";;
*) error 1 unknown option: "$ARG"
esac
## Hooks
if [ -z "$HOOK" ]; then continue; fi
case "$HOOK" in
pre-) PRE='pre' ; HOOK="${HOOK#pre-}" ;;
post-) PRE='post'; HOOK="${HOOK#post-}";;
*) PRE=
esac
case "$HOOK" in
hooks|clean|config|make-dep|compile-image|install-image|tidy-image|compile-modules|install-modules|tidy-modules|work)
set_run_hooks "$VALUE" "$PRE" "$HOOK" ;;
*) error 1 unknown event: "$HOOK";;
esac
done
## 'make install' run
if [ $NUMARGS -eq 4 ] && [ $ADD_ARGS -eq 4 ]; then
INSTALL_IMAGE=y
fi
## --jobs
if [ x"$JOBS" = xauto ]; then
JOBS=$(grep -c ^processor /proc/cpuinfo)
fi
if [ -n "$JOBS" ] && [ "$JOBS" -gt 1 ] 2>/dev/null; then
MAKE_FLAGS="$MAKE_FLAGS -j$JOBS"
fi
unset ARG PARAM HOOK VALUE JOBS
##
## Print header
##
header Starting
INSIDE_INSTALLKERNEL=y
export INSIDE_INSTALLKERNEL
if [ -n "$REALLY_VERBOSE" ]; then
VERBOSE=y
MAKE_FLAGS="$MAKE_FLAGS v=1"
fi
if [ -n "$VERBOSE" ]; then V=v; VOPT=-v; fi
##
## Calculate nice
##
if [ X"${NICE#!}" != X"$NICE" ]; then
NICE=$((`toInt "${NICE#!}"` - `nice`))
else
NICE=`toInt "$NICE"`
fi
if [ "$NICE" -gt 0 ]; then
msg '37;1' NICE "$NICE"
if [ -n "$VERBOSE" ]; then renice +$NICE -p $$
else renice $NICE -p $$ >/dev/null 2>&1; fi
fi
unset NICE
##
## Set ARCH
##
if [ X"$ARCH" = X- ]; then
ARCH="$__ARCH"
fi
unset __ARCH
if [ -z "$ARCH" ]; then
ARCH=`uname -m | sed -e 's/i.86/i386/' -e 's/sun4u/sparc64/' \
-e 's/arm.*/arm/' -e 's/sa110/arm/' \
-e 's/s390x/s390/' -e 's/parisc64/parisc/'`
msg '37;1' ARCH "$ARCH"
fi
##
## Change directory
##
if [ -n "$CD" ]; then
run -f cd "$CD"
fi
unset CD
##
## Become root ?
##
if [ -n "$SU" ] && [ "`id -u`" -ne 0 ]; then
msg '37;1' SU "Becoming super user"
unset SU
if [ -n "$DRY_RUN" ]; then
echo Here you would be asked for root password.
else
case "$0" in
/*) ARGS="$0";;
*/*) ARGS="$PWD/$0";;
*) ARGS=$(which "$0" 2>/dev/null)
esac
set -- "/bin/sh" "$ARGS" "$@"
ARGS=
while [ $# -ne 0 ]; do
ARGS="$ARGS '$(echo "$1" | sed -e "s/'/'\\\\''/")'"
shift
done
# exec was here before but it caused the lock file to
# stall if user provided invalid password
su -c "$ARGS"
exit $?
fi
fi
unset SU
else
if [ -n "$VERBOSE" ]; then V=v; VOPT=-v; fi
fi
unset VERBOSE REALLY_VERBOSE
run_hook pre-work
##
## Make dep?
##
if [ "X$MAKE_DEP" = Xauto ]; then
MAKE_DEP=
if [ -n "$COMPILE_IMAGE" ]; then
case "$VER" in 2.4.*)
MAKE_DEP=y
esac
fi
fi
##
## Check config type
##
if [ "X$CONFIG" = Xauto ]; then
if [ -n "$DISPLAY" ]; then
if [ -n "`which qtconfig 2>/dev/null`" ]; then
CONFIG=xconfig
elif [ -n "`which gtk-config 2>/dev/null`" ]; then
CONFIG=gconfig
fi
fi
if [ "X$CONFIG" = Xauto ]; then
CONFIG=config
for DIR in /usr/lib /usr/local/lib /lib; do
for LIB in curses.a curses.so ncurses.a ncurses.so; do
if [ -f "$DIR/lib$LIB" ] || [ -f "${DIR}64/lib$LIB" ]; then
CONFIG=menuconfig
break 2
fi
done
done
fi
fi
##
## make *
##
r -u CLEAN 'Cleaning source tree' make $MAKE_FLAGS clean
r -u CONFIG 'Configuring the kernel' make $MAKE_FLAGS "$CONFIG"
r -u MAKE_DEP 'Updating dependencies' make $MAKE_FLAGS dep
r -u COMPILE_IMAGE 'Compiling bzImage' make $MAKE_FLAGS bzImage
r -u COMPILE_MODULES 'Compiling modules' make $MAKE_FLAGS modules
r INSTALL_MODULES 'Installing modules' make $MAKE_FLAGS modules_install
##
## Removing old images
##
if [ -n "$TIDY_IMAGE" ]; then
header Removing old image
run_hook pre-tidy-image
if [ -z "$OVERWRITE_IMAGE" ]; then T='~'; else T=; fi
for FILE in bzImage System.map config; do
msg '37;1' READLNK "$FILE$T"
run -d readlink "$INSTALL_PATH/$FILE$T"
LNK=`readlink "$INSTALL_PATH/$FILE$T" || true`
if [ -f "$INSTALL_PATH/$LNK" ]; then
msg '37;1' RM "$LNK"
run rm -f$V -- "$INSTALL_PATH/$LNK"
fi
done
run_hook post-tidy-image
fi
##
## Removing old modules
##
read_version_from_link() {
msg '37;1' READLNK "$1"
run -d readlink "$INSTALL_PATH/$1"
set -- "$(readlink "$INSTALL_PATH/$1" 2>/dev/null)"
if [ -z "$1" ]; then
set -- ${1#*-}
set -- ${1%-\#*}
fi
echo "$1"
}
if [ -n "$TIDY_MODULES" ]; then
header Removing old modules
run_hook pre-tidy-modules
update_ver
OVER=$(read_version_from_link bzImage)
OOVER=$(read_version_from_link bzImage~)
if [ -n "$OVERWRITE_IMAGE" ]; then
_=$OVER
OVER=$OOVER
OOVER=$_
fi
if [ -n "$OOVER" ] && [ "X$OOVER" != "X$VER" ] && \
[ "X$OOVER" != "X$OVER" ] && [ -d "/lib/modules/$OOVER" ]; then
msg '37;1' RMDIR "/lib/modules/$OOVER"
run rm -r$V -- "/lib/modules/$OOVER"
fi
run_hook post-tidy-modules
fi
##
## Copying image
##
if [ -n "$INSTALL_IMAGE" ]; then
header "Installing kernel image"
run_hook pre-install-image
update_ver
if [ -s "${KBUILD_OUTPUT:-.}/.version" ]; then
run -ud cat "${KBUILD_OUTPUT:-.}/"
BUILD=$(printf %d $(run -usf cat "${KBUILD_OUTPUT:-.}/.version"))
else
BUILD=1
fi
msg '37;1' BUILD "$BUILD"
FVER="$VER-#$BUILD"
if [ -z "$IMG_PATH" ]; then IMG_PATH=arch/$ARCH/boot/bzImage; fi
if [ -z "$MAP_PATH" ]; then MAP_PATH=System.map; fi
mkdir -p -m u=rwx,g=rx,o=rx "$INSTALL_PATH"
set -- "$INSTALL_PATH/bzImage-$FVER" "$INSTALL_PATH/System.map-$FVER" \
"$INSTALL_PATH/config-$FVER"
while [ "$1" ]; do
if [ -f "$1" ]; then
if [ -f "$1~" ]; then
set -- "$1~" "$@"
continue
fi
run mv -f$V -- "$1" "$1~"
fi
shift
done
set --
msg '37;1' CP bzImage
run cp $VOPT -- "${KBUILD_OUTPUT:-.}/$IMG_PATH" "$INSTALL_PATH/bzImage-$FVER"
msg '37;1' CP System.map
run cp $VOPT -- "${KBUILD_OUTPUT:-.}/$MAP_PATH" "$INSTALL_PATH/System.map-$FVER"
msg '37;1' CP .config
run cp $VOPT -- "${KBUILD_OUTPUT:-.}/.config" "$INSTALL_PATH/config-$FVER"
for FILE in bzImage System.map config; do
msg '37;1' READLNK "$FILE"
run -d readlink "$INSTALL_PATH/$FILE" || true
LNK=$(readlink "$INSTALL_PATH/$FILE" || true)
if [ "X$LNK" != "X$FILE-$FVER" ]; then
msg '37;1' LNK "$FILE"
if [ -z "$OVERWRITE_IMAGE" ]; then
run mv -f$V -- "$INSTALL_PATH/$FILE" "$INSTALL_PATH/$FILE~" || true
fi
run ln -fs$V -- "$FILE-$FVER" "$INSTALL_PATH/$FILE"
fi
done
run_hook post-install-image
fi
run_hook post-work