cookutils diff cooklinux @ rev 637

cross: tar J or --xz is to filter the archive through xz
author Christophe Lincoln <pankso@slitaz.org>
date Thu Feb 13 19:45:44 2014 +0100 (2014-02-13)
parents
children 3ad4223f8687
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cooklinux	Thu Feb 13 19:45:44 2014 +0100
     1.3 @@ -0,0 +1,233 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Simple utility to compile from scratch a custom Linux kernel on SliTaz.
     1.7 +# No patch, aufs and co, keep it simple. The goal is to let users build
     1.8 +# a custom and optimized kernel in a few commands
     1.9 +#
    1.10 +# Copyright (C) 2014 SliTaz GNU/Linux - BSD License
    1.11 +#
    1.12 +# Author: Christophe Lincoln <pankso@slitaz.org>
    1.13 +#
    1.14 +. /lib/libtaz.sh
    1.15 +. /etc/slitaz/slitaz.conf
    1.16 +
    1.17 +version="$1"
    1.18 +cookdir="/home/slitaz/src"
    1.19 +srcurl="https://www.kernel.org/pub/linux/kernel"
    1.20 +
    1.21 +check_root
    1.22 +
    1.23 +# Help and usage
    1.24 +usage() {
    1.25 +	cat << EOT
    1.26 +
    1.27 +SliTaz Linux Kernel cooker
    1.28 +
    1.29 +$(boldify "Usage:") $(basename $0) [version] [--options]
    1.30 +
    1.31 +$(boldify "Options:")
    1.32 +  --clean        Remove most generated files but keep the config
    1.33 +  --mrproper     Remove all generated files + config + backup files
    1.34 +  --defconfig    New config with default from ARCH supplied defconfig
    1.35 +  --tazconfig    New config using current SliTaz /proc/config.gz
    1.36 +  --localmod     Update config removing all unloaded modules
    1.37 +  --config       Update current config with a text based front-end
    1.38 +  --menuconfig   Update current config with a menu based program
    1.39 +  --xconfig      Update current config with a QT based front-end
    1.40 +  --gconfig      Update current config with a GTK based front-end
    1.41 +  --bzImage      Build the compressed kernel image
    1.42 +  --modules      Build all kernel modules
    1.43 +
    1.44 +$(boldify "Examples:")
    1.45 +  $(basename $0) 3.8.3 --defconfig --menuconfig --bzImage
    1.46 +  $(basename $0) 3.2.14 --tazconfig --bzImage --modules
    1.47 +
    1.48 +EOT
    1.49 +}
    1.50 +
    1.51 +# Check and install a packages
    1.52 +check_pkg() {
    1.53 +	if [ ! -f "$PKGS_DB/installed/$1/receipt" ]; then
    1.54 +		echo -n "Installing package:" && colorize 34 " $1"
    1.55 +		tazpkg -gi $1 2>/dev/null >/dev/null
    1.56 +	fi
    1.57 +}
    1.58 +
    1.59 +#
    1.60 +# Commands/help - Support 3.x 2.6 and 2.4 kernel's.
    1.61 +#
    1.62 +case "$1" in
    1.63 +	3.*) wgeturl="${srcurl}/v3.0/" ;;
    1.64 +	2.6.*) wgeturl="${srcurl}/v2.6/" ;;
    1.65 +	2.4.*) wgeturl="${srcurl}/v2.4/" ;;
    1.66 +	-h|-u|help|usage|"")
    1.67 +		usage && exit 0 ;;
    1.68 +esac
    1.69 +
    1.70 +# Sanity check
    1.71 +[ ! "$wgeturl" ] && echo "Unable to set download url" && exit 0
    1.72 +
    1.73 +#
    1.74 +# Build start
    1.75 +#
    1.76 +
    1.77 +echo -n "Building Linux kernel:" && colorize 32 " $version"
    1.78 +echo -n "Source directory:" && colorize 30 " $cookdir"
    1.79 +
    1.80 +# Install needed packages to compile.
    1.81 +for pkg in slitaz-toolchain perl xz lzma patch tar bc
    1.82 +do
    1.83 +	check_pkg $pkg
    1.84 +done
    1.85 +
    1.86 +# Get the source and extract tarball.
    1.87 +mkdir -p $cookdir && cd $cookdir || exit 1
    1.88 +if [ ! -f "linux-$version.tar.xz" ]; then
    1.89 +	echo "Downloading Linux kernel source..."
    1.90 +	wget -c --no-check-certificate ${wgeturl}linux-$version.tar.xz
    1.91 +fi
    1.92 +if [ ! -d "linux-$version" ]; then
    1.93 +	echo "Extracting: linux-$version.tar.xz"
    1.94 +	unxz -c linux-$version.tar.xz | tar xf -
    1.95 +fi
    1.96 +
    1.97 +# Clean-up and get or update config
    1.98 +cd linux-$version
    1.99 +
   1.100 +if [ "$clean" ]; then
   1.101 +	make clean
   1.102 +	rm -rf slitaz
   1.103 +fi
   1.104 +
   1.105 +if [ "$mrproper" ]; then
   1.106 +	make mrproper
   1.107 +	rm -rf slitaz
   1.108 +fi
   1.109 +
   1.110 +# Get SliTaz current config.
   1.111 +if [ "$tazconfig" ]; then
   1.112 +	echo "Using current SliTaz config: /proc/config.gz"
   1.113 +	zcat /proc/config.gz > .config
   1.114 +	yes '' | make oldconfig
   1.115 +fi
   1.116 +
   1.117 +# Create a new default config.
   1.118 +if [ "$defconfig" ]; then
   1.119 +	make defconfig
   1.120 +fi
   1.121 +
   1.122 +# Update config and wipe out unloaded modules.
   1.123 +if [ "$localmod" ]; then
   1.124 +	make localmodconfig
   1.125 +fi
   1.126 +
   1.127 +#
   1.128 +# Configurators text/ncurses/Qt/GTK
   1.129 +#
   1.130 +
   1.131 +if [ "$config" ]; then
   1.132 +	echo "Starting Text mode configuration tool..."
   1.133 +	make config
   1.134 +fi
   1.135 +
   1.136 +if [ "$menuconfig" ]; then
   1.137 +	echo "Starting Ncurses configuration tool..."
   1.138 +	check_pkg ncurses-dev
   1.139 +	make menuconfig
   1.140 +fi
   1.141 +
   1.142 +if [ "$xconfig" ]; then
   1.143 +	echo "Starting QT configuration tool..."
   1.144 +	check_pkg qt-4
   1.145 +	make xconfig
   1.146 +fi
   1.147 +
   1.148 +if [ "$gconfig" ]; then
   1.149 +	echo "Starting GTK+ configuration tool..."
   1.150 +	check_pkg gtk+-dev
   1.151 +	check_pkg libglade-dev
   1.152 +	make gconfig
   1.153 +fi
   1.154 +
   1.155 +if [ "$bzImage" ]; then
   1.156 +	echo "Building bzImage..."
   1.157 +	make bzImage || exit 1
   1.158 +	mkdir -p slitaz/linux-custom-$version/fs/boot
   1.159 +	cp -f arch/x86/boot/bzImage \
   1.160 +		slitaz/linux-custom-$version/fs/boot/vmlinuz-$version
   1.161 +fi
   1.162 +		
   1.163 +if [ "$modules" ]; then
   1.164 +	echo "Building modules..."
   1.165 +	make modules || exit 1
   1.166 +	make INSTALL_MOD_PATH=slitaz/linux-custom-$version/fs modules_install
   1.167 +	rm -f slitaz/linux-custom-$version/fs/lib/modules/$version/build
   1.168 +	rm -f slitaz/linux-custom-$version/fs/lib/modules/$version/source
   1.169 +fi
   1.170 +
   1.171 +#
   1.172 +# Packaging
   1.173 +#
   1.174 +
   1.175 +if [ -d "slitaz/linux-custom-$version/fs" ]; then
   1.176 +	echo "Packing Linux..."
   1.177 +	cd slitaz
   1.178 +else
   1.179 +	echo -n "Packing Linux:" && colorize 31 " not yet build"
   1.180 +	exit 0
   1.181 +fi
   1.182 +
   1.183 +# Receipt.
   1.184 +echo "Creating the receipt..."
   1.185 +cat > linux-custom-$version/receipt << EOF
   1.186 +# SliTaz package receipt.
   1.187 +
   1.188 +PACKAGE="linux-custom"
   1.189 +VERSION="$version"
   1.190 +CATEGORY="base-system"
   1.191 +SHORT_DESC="The Linux kernel and modules."
   1.192 +MAINTAINER="devel@slitaz.org"
   1.193 +WEB_SITE="http://www.kernel.org/"
   1.194 +
   1.195 +DEPENDS="kmod"
   1.196 +
   1.197 +## Pre and post install commands for Tazpkg.
   1.198 +post_install()
   1.199 +{
   1.200 +    echo "Processing post-install commands..."
   1.201 +    depmod -a \$VERSION-custom
   1.202 +    echo "Check your GRUB menu.lst to boot your new kernel"
   1.203 +}
   1.204 +
   1.205 +EOF
   1.206 +
   1.207 +## Pre and post install commands for Tazpkg/Spk.
   1.208 +#post_install()
   1.209 +#{
   1.210 +    #echo "Processing post-install commands..."
   1.211 +    #chroot "\$1/" depmod -a \$VERSION
   1.212 +    ## GRUB stuff.
   1.213 +    #if [ -f "\$1/boot/grub/menu.lst" ]; then
   1.214 +    	#root_dev=\$(cat $1/boot/grub/menu.lst | grep root= | sed 's/.*root=\([^ ]*\).*/\1/' | head -n 1)
   1.215 +		#grub_dev=\$(cat $1/boot/grub/menu.lst | grep "root (" | head -n 1)
   1.216 +		## Add new kernel entry in case of upgrade for installed system.
   1.217 +		#if ! grep -q vmlinuz-\$VERSION \$1/boot/grub/menu.lst; then
   1.218 +    		#cat >> \$1/boot/grub/menu.lst << EOT
   1.219 +
   1.220 +#title SliTaz GNU/Linux (Kernel \$VERSION)
   1.221 +#\$grub_dev
   1.222 +#kernel /boot/vmlinuz-\$VERSION root=\$root_dev
   1.223 +#EOT
   1.224 +		#fi
   1.225 +#}
   1.226 +
   1.227 +# Pack it.
   1.228 +tazpkg pack linux-custom-$version
   1.229 +
   1.230 +# Install the new kernel.
   1.231 +if [ "$install" ]; then
   1.232 +	cd $cookdir/linux-$version/slitaz
   1.233 +	tazpkg -i linux-custom-$version.tazpkg --forced
   1.234 +fi
   1.235 +
   1.236 +exit 0