Add using default kernel config from overlay.

master
Mike Hiretsky 15 years ago
parent 0fce43a4d9
commit 20cdf5cfd8

@ -2,14 +2,15 @@
source /etc/make.conf
progname=cl-kernel
OVERLAY_DIRECTORY="/usr/local/portage/layman/calculate"
KERNEL_CONFIG_DIR="${OVERLAY_DIRECTORY}/profiles/kernel"
SHORTOPTS="k:c:t:n:v:e:rh"
LONGOPTS="help,no-install,kerneldir:,kernel-config:,make-tarball:,kernel-name:,kernel-version:,kernel-extraversion:,remove-splash,no-clean,menuconfig"
SHORTOPTS="k:c:t:n:v:e:rho"
LONGOPTS="help,no-install,kerneldir:,kernel-config:,make-tarball:,kernel-name:,kernel-version:,kernel-extraversion:,remove-splash,no-clean,menuconfig,use-own-config"
print_help() {
cat <<'EOF'
Usage: cl-kernel [options] [DESTINATION]
Usage: cl-kernel [options] [-c FILE|-o] [DESTINATION]
Make kernel.
@ -24,6 +25,7 @@ Options:
-e, --extraversion VER Specify extraversion for kernel
-v, --kernel-version VER Specify version for kernel
-r, --remove-splash Remove splash images from initramfs.
-o, --use-own-config Use config from kernel directory.
--no-clean Do not run make clean before compilation
--menuconfig Run menuconfig after oldconfig
@ -46,7 +48,8 @@ parse_kernel_version() {
KV_MINOR=${BASH_REMATCH[2]}
KV_PATCH=${BASH_REMATCH[3]}
[[ -z $1 ]] && KV_TYPE=${BASH_REMATCH[4]} || KV_TYPE=$1
KERNEL_VERSION=${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_TYPE}
OKV=${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}
KERNEL_VERSION=${OKV}${KV_TYPE}
else
echo "Wrong kernel version: ${KERNEL_VERSION}"
exit 0
@ -54,70 +57,92 @@ parse_kernel_version() {
}
warning() {
echo "Warning:"$1 1>&2
echo "Warning: "$1 1>&2
}
die() {
echo 1>&2
echo "Error:"$1 1>&2
echo "Error: "$1 1>&2
exit 1
}
set_kernel_version() {
sed -ri "s/^VERSION = .*$/VERSION = $KV_MAJOR/" ${KERNEL_DIR}/Makefile
sed -ri "s/^PATCHLEVEL = .*$/PATCHLEVEL = $KV_MINOR/" ${KERNEL_DIR}/Makefile
sed -ri "s/^SUBLEVEL = .*$/SUBLEVEL = $KV_PATCH/" ${KERNEL_DIR}/Makefile
sed -ri "s/^EXTRAVERSION = .*$/EXTRAVERSION = $KV_TYPE/" ${KERNEL_DIR}/Makefile
sed -ri "s/^VERSION = .*$/VERSION = $KV_MAJOR/" \
${KERNEL_DIR}/Makefile
sed -ri "s/^PATCHLEVEL = .*$/PATCHLEVEL = $KV_MINOR/" \
${KERNEL_DIR}/Makefile
sed -ri "s/^SUBLEVEL = .*$/SUBLEVEL = $KV_PATCH/" \
${KERNEL_DIR}/Makefile
sed -ri "s/^EXTRAVERSION = .*$/EXTRAVERSION = $KV_TYPE/" \
${KERNEL_DIR}/Makefile
}
initramfs_unpack() {
mkdir -p tmp/initramfs || die "Catn't create temporary directory for initramfs"
mkdir -p tmp/initramfs ||
die "Catn't create temporary directory for initramfs"
pushd tmp/initramfs >/dev/null
# unpack initramfs
archcmd="gzip"
lzma -dc ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} &>/dev/null && archcmd="lzma"
${archcmd} -dc ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} | cpio -di &>/dev/null || die "Cann't unpack initramfs"
arcmd="gzip"
# check may be initramfs packed by lzma
lzma -dc ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} \
&>/dev/null && arcmd="lzma"
${arcmd} -dc ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} |
cpio -di &>/dev/null || die "Cann't unpack initramfs"
# remove old initramfs
rm ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} || warning "Cann't remove old initramfs"
rm ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} ||
warning "Cann't remove old initramfs"
}
initramfs_clean() {
# remove sound moudles
find -name sound -exec rm -rf {} \; &>/dev/null
# remove splash images if need
[[ ${REMOVE_SPLASH} == 'true' ]] && rm etc/splash/tty1/images/* >/dev/null
[[ ${REMOVE_SPLASH} == 'true' ]] &&
rm etc/splash/tty1/images/* >/dev/null
}
initramfs_pack() {
# pack new initramfs
find * | cpio -o --quiet -H newc | gzip -9 >${BOOT_DIR}/initramfs-${KERNEL_NAME}-${KERNEL_VERSION} ||
die "Cann't pack initramfs"
find * | cpio -o --quiet -H newc |
gzip -9 >${BOOT_DIR}/initramfs-${KERNEL_NAME}-${KERNEL_VERSION} ||
die "Cann't pack initramfs"
popd &>/dev/null
rm -rf tmp/initramfs || warning "Cann't remove temporary directory with contents of initramfs"
rm -rf tmp/initramfs ||
warning "Cann't remove temporary directory contenting initramfs"
}
rename_kernel_systemmap() {
# rename kernel
mv ${BOOT_DIR}/kernel-${KERNEL_NAME}-*-${KERNEL_VERSION} ${BOOT_DIR}/linux-${KERNEL_NAME}-${KERNEL_VERSION} || die "Cann't rename kernel"
mv ${BOOT_DIR}/kernel-${KERNEL_NAME}-*-${KERNEL_VERSION} \
${BOOT_DIR}/linux-${KERNEL_NAME}-${KERNEL_VERSION} ||
die "Cann't rename kernel"
# change System.map
[[ -e ${BOOT_DIR}/System.map-${KERNEL_NAME}-${KERNEL_VERSION} ]] &&
mv ${BOOT_DIR}/System.map-${KERNEL_NAME}-${KERNEL_VERSION} ${BOOT_DIR}/System.map-${KERNEL_NAME}-${KERNEL_VERSION}.old
mv ${BOOT_DIR}/System.map-${KERNEL_NAME}-*-${KERNEL_VERSION} ${BOOT_DIR}/System.map-${KERNEL_NAME}-${KERNEL_VERSION} || die "Cann't rename System.map"
mv ${BOOT_DIR}/System.map-${KERNEL_NAME}-${KERNEL_VERSION} \
${BOOT_DIR}/System.map-${KERNEL_NAME}-${KERNEL_VERSION}.old
mv ${BOOT_DIR}/System.map-${KERNEL_NAME}-*-${KERNEL_VERSION} \
${BOOT_DIR}/System.map-${KERNEL_NAME}-${KERNEL_VERSION} ||
die "Cann't rename System.map"
}
install_kernel() {
# change kernel
rm -f ${BOOT_DIR}/vmlinuz.old
[[ -e ${BOOT_DIR}/vmlinuz ]] && mv ${BOOT_DIR}/vmlinuz ${BOOT_DIR}/vmlinuz.old
[[ -e ${BOOT_DIR}/vmlinuz ]] &&
mv ${BOOT_DIR}/vmlinuz ${BOOT_DIR}/vmlinuz.old
ln -sf linux-${KERNEL_NAME}-${KERNEL_VERSION} ${BOOT_DIR}/vmlinuz
# change initramfs
[[ -e ${BOOT_DIR}/initrd ]] && mv ${BOOT_DIR}/initrd ${BOOT_DIR}/initrd.old
[[ -e ${BOOT_DIR}/initrd-install ]] && mv ${BOOT_DIR}/initrd-install ${BOOT_DIR}/initrd-install.old
mv ${BOOT_DIR}/initramfs-${KERNEL_NAME}-${KERNEL_VERSION} ${BOOT_DIR}/initrd
[[ -e ${BOOT_DIR}/initrd ]] &&
mv ${BOOT_DIR}/initrd ${BOOT_DIR}/initrd.old
[[ -e ${BOOT_DIR}/initrd-install ]] &&
mv ${BOOT_DIR}/initrd-install ${BOOT_DIR}/initrd-install.old
mv ${BOOT_DIR}/initramfs-${KERNEL_NAME}-${KERNEL_VERSION} \
${BOOT_DIR}/initrd
cp ${BOOT_DIR}/initrd ${BOOT_DIR}/initrd-install
# copy config
[[ -e ${BOOT_DIR}/config-${KERNEL_NAME}-${KERNEL_VERSION} ]] && \
mv ${BOOT_DIR}/config-${KERNEL_NAME}-${KERNEL_VERSION} ${BOOT_DIR}/config-${KERNEL_NAME}-${KERNEL_VERSION}.old
mv ${BOOT_DIR}/config-${KERNEL_NAME}-${KERNEL_VERSION} \
${BOOT_DIR}/config-${KERNEL_NAME}-${KERNEL_VERSION}.old
cp ${KERNEL_CONFIG} ${BOOT_DIR}/config-${KERNEL_NAME}-${KERNEL_VERSION}
# set new current kernel
if [[ ${KERNEL_DIR} != '/usr/src/linux' ]]
@ -125,36 +150,34 @@ install_kernel() {
# if source place in /usr/src
if [[ ${KERNEL_DIR} =~ ^/usr/src/([^/]+)$ ]]
then
rm /usr/src/linux && ln -sf ${BASH_REMATCH[1]} /usr/src/linux
rm /usr/src/linux &&
ln -sf ${BASH_REMATCH[1]} /usr/src/linux
else
# is specifed absolutly path
if [[ ${KERNEL_DIR:0:1} == '/' ]]
then
rm /usr/src/linux && ln -sf ${KERNEL_DIR} /usr/src/linux
rm /usr/src/linux &&
ln -sf ${KERNEL_DIR} /usr/src/linux
fi
fi
fi
}
make_tarball() {
# remove symlink for tarball
find lib -type l -delete || warning "Cann't delete symbolic links"
tar cjf ${KERNEL_TARBALL} boot lib || die "Cann't create kernel tarbal"
# remove symlink for tarball
find lib -type l -delete ||
warning "Cann't delete symbolic links"
tar cjf ${KERNEL_TARBALL} boot lib ||
die "Cann't create kernel tarbal"
}
OPTS=$(getopt -o $SHORTOPTS --long $LONGOPTS -n "$progname" -- "$@")
if [ $? -ne 0 ]; then
echo "'$progname --help' for more information" 1>&2
exit 1
fi
eval set -- "$OPTS"
KERNEL_DIR=
KERNEL_DIR=/usr/src/linux
KERNEL_CONFIG=
USE_OWN_CONFIG=false
KERNEL_TARBALL=
KERNEL_NAME=calculate
SYSTEMNAME=$(sed -nr '/^system/ s/^[^=]+=(.*)$/\1/p' \
/etc/calculate/calculate.ini)
KERNEL_NAME=${SYSTEMNAME}
KERNEL_VERSION=
DESTINATION=
KERNEL_EXTRAVERSION=
@ -164,6 +187,14 @@ NO_INSTALL=false
NOCLEAN=""
MENUCONFIG=""
OPTS=$(getopt -o $SHORTOPTS --long $LONGOPTS -n "$progname" -- "$@")
if [ $? -ne 0 ]; then
echo "'$progname --help' for more information" 1>&2
exit 1
fi
eval set -- "$OPTS"
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
@ -178,11 +209,19 @@ while [ $# -gt 0 ]; do
NOCLEAN="--no-clean"
shift
;;
-o|--use-own-config)
[[ -n $KERNEL_CONFIG ]] &&
die "Option '$1' cannot be used in conjunction with '--kernel-config'"
USE_OWN_CONFIG=true
shift
;;
-k|--kerneldir)
KERNEL_DIR=$2
shift 2
;;
-c|--kernel-config)
[[ $USE_OWN_CONFIG == "true" ]] &&
die "Option '$1' cannot be used in conjunction with '--use-own-config'"
KERNEL_CONFIG=$2
shift 2
;;
@ -219,22 +258,26 @@ while [ $# -gt 0 ]; do
DESTINATION=$1
shift
else
echo "Error: unknown second option: $1" 1>&2
exit 1
die "unknown second option: $1"
fi
;;
esac
done
[[ -z ${KERNEL_DIR} ]] && KERNEL_DIR="/usr/src/linux"
[[ -e ${KERNEL_DIR}/Makefile ]] || die "Wrong kernel sources directory: ${KERNEL_DIR}"
[[ -z ${KERNEL_CONFIG} ]] && KERNEL_CONFIG="${KERNEL_DIR}/.config.bak"
# check kernel directory
[[ -e ${KERNEL_DIR}/Makefile ]] ||
die "Wrong kernel sources directory: ${KERNEL_DIR}"
[[ -z ${DESTINATION} ]] && DESTINATION="/"
# if kernel_version not defined get it from Makefile of sources
[[ -z ${KERNEL_VERSION} ]] && \
KERNEL_VERSION=`grep -e ^VERSION -e ^PATCHLEVEL -e ^SUBLEVEL -e ^EXTRAVERSION \
KERNEL_VERSION=`grep \
-e ^VERSION -e ^PATCHLEVEL -e ^SUBLEVEL -e ^EXTRAVERSION \
${KERNEL_DIR}/Makefile \
| sed -rn "{N;N;N;s/PATCHLEVEL = |SUBLEVEL = /./g;s/EXTRAVERSION = |VERSION = |\n//g;p}"`
| sed -rn "{N;N;N;s/PATCHLEVEL = |SUBLEVEL = /./g;
s/EXTRAVERSION = |VERSION = |\n//g;p}"`
MODULE_INS_PATH=${DESTINATION}
mkdir -p ${DESTINATION}
# tarball should be created in empty directory
@ -249,8 +292,10 @@ if [[ -n ${KERNEL_EXTRAVERSION} ]] && [[ ${KERNEL_EXTRAVERSION:0:1} != [.-] ]]
then
if [[ ${KERNEL_EXTRAVERSION:0:1} == [0-9] ]]
then
# dot before number
KERNEL_EXTRAVERSION=.${KERNEL_EXTRAVERSION}
else
# else - minus
KERNEL_EXTRAVERSION=-${KERNEL_EXTRAVERSION}
fi
fi
@ -258,16 +303,38 @@ fi
parse_kernel_version ${KERNEL_EXTRAVERSION}
set_kernel_version
# select kernel config (in kernel dir, own config or overlay kernel config)
# .config.bak used instead .config, because genkernel copy specified kernel
# config to "kernel directory/.config"
if [[ ${USE_OWN_CONFIG} != "false" ]] ||
[[ $( readlink -f ${KERNEL_CONFIG} ) == \
$( readlink -f "${KERNEL_DIR}/.config" ) ]]
then
KERNEL_CONFIG="${KERNEL_DIR}/.config.bak"
[[ -e ${KERNEL_DIR}/.config ]] &&
cp ${KERNEL_DIR}/.config ${KERNEL_CONFIG} ||
die "Not found .config in ${KERNEL_DIR}"
fi
[[ -z ${KERNEL_CONFIG} ]] &&
KERNEL_CONFIG="${KERNEL_CONFIG_DIR}/config-${SYSTEMNAME}-${ARCH}-${OKV}"
[[ -e ${KERNEL_CONFIG} ]] ||
die "Kernel config not found in ${KERNEL_CONFIG}"
mkdir -p ${BOOT_DIR}
# run generating kernel
genkernel --splash=tty1 --unionfs --all-ramdisk-modules --disklabel --slowusb --kerneldir=${KERNEL_DIR} --module-prefix=${MODULE_INS_PATH} --makeopts=${MAKEOPTS} ${NOCLEAN} ${MENUCONFIG} --no-save-config --kernel-config=${KERNEL_CONFIG} --kernname=${KERNEL_NAME} --bootdir=${BOOT_DIR} all
[[ $? -ne 0 ]] && die "kernel was not builded"
genkernel --splash=tty1 --unionfs --all-ramdisk-modules --disklabel \
--slowusb --kerneldir=${KERNEL_DIR} \
--module-prefix=${MODULE_INS_PATH} --makeopts=${MAKEOPTS} \
${NOCLEAN} ${MENUCONFIG} --no-save-config \
--kernel-config=${KERNEL_CONFIG} --kernname=${KERNEL_NAME} \
--bootdir=${BOOT_DIR} all || die "kernel was not builded"
pushd ${DESTINATION} &>/dev/null
initramfs_unpack
initramfs_clean
initramfs_pack
rename_kernel_systemmap
# if specified tarball then make archive else install kernel
[[ -n ${KERNEL_TARBALL} ]] && make_tarball || install_kernel

Loading…
Cancel
Save