cookutils view cooklinux @ rev 671
cook: introduce receipts functions
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Apr 17 23:57:11 2014 +0200 (2014-04-17) |
parents | 3ad4223f8687 |
children | da66e6be1add |
line source
1 #!/bin/sh
2 #
3 # Simple utility to compile from scratch a custom Linux kernel on SliTaz.
4 # No patches, aufs and co, keep it simple. The goal is to let users build
5 # a custom and optimized kernel in a few commands
6 #
7 # Copyright (C) 2014 SliTaz GNU/Linux - BSD License
8 #
9 # Author: Christophe Lincoln <pankso@slitaz.org>
10 #
11 . /lib/libtaz.sh
12 . /etc/slitaz/slitaz.conf
14 version="$1"
15 cookdir="/home/slitaz/src"
16 srcurl="https://www.kernel.org/pub/linux/kernel"
18 check_root
20 # Help and usage
21 usage() {
22 cat << EOT
24 SliTaz Linux Kernel cooker
26 $(boldify "Usage:") $(basename $0) [version] [--options]
28 $(boldify "Options:")
29 --clean Remove various generated files but keep the config
30 --mrproper Remove all generated files + config + backup files
31 --defconfig New config with default from ARCH supplied defconfig
32 --tazconfig New config using current SliTaz /proc/config.gz
33 --localmod Update config removing all unloaded modules
34 --config Update current config with a text based front-end
35 --menuconfig Update current config with a menu based program
36 --xconfig Update current config with a QT based front-end
37 --gconfig Update current config with a GTK based front-end
38 --bzImage Build the compressed kernel image
39 --modules Build all kernel modules
41 $(boldify "Examples:")
42 $(basename $0) 3.8.3 --defconfig --menuconfig --bzImage
43 $(basename $0) 3.2.14 --tazconfig --bzImage --modules
45 EOT
46 }
48 # Check and install a packages
49 check_pkg() {
50 if [ ! -f "$PKGS_DB/installed/$1/receipt" ]; then
51 echo -n "Installing package:" && colorize 34 " $1"
52 tazpkg -gi $1 2>/dev/null >/dev/null
53 fi
54 }
56 #
57 # Commands/help - Support 3.x 2.6 and 2.4 kernels.
58 #
59 case "$1" in
60 3.*) wgeturl="${srcurl}/v3.0/" ;;
61 2.6.*) wgeturl="${srcurl}/v2.6/" ;;
62 2.4.*) wgeturl="${srcurl}/v2.4/" ;;
63 -h|-u|help|usage|"")
64 usage && exit 0 ;;
65 esac
67 # Sanity check
68 [ ! "$wgeturl" ] && echo "Unable to set download url" && exit 0
70 #
71 # Build start
72 #
74 echo -n "Building Linux kernel:" && colorize 32 " $version"
75 echo -n "Source directory:" && colorize 30 " $cookdir"
77 # Install needed packages to compile.
78 for pkg in slitaz-toolchain perl xz lzma patch tar bc
79 do
80 check_pkg $pkg
81 done
83 # Get the source and extract tarball.
84 mkdir -p $cookdir && cd $cookdir || exit 1
85 if [ ! -f "linux-$version.tar.xz" ]; then
86 echo "Downloading Linux kernel source..."
87 wget -c --no-check-certificate ${wgeturl}linux-$version.tar.xz
88 fi
89 if [ ! -d "linux-$version" ]; then
90 echo "Extracting: linux-$version.tar.xz"
91 unxz -c linux-$version.tar.xz | tar xf -
92 fi
94 # Clean-up and get or update config
95 cd linux-$version
97 if [ "$clean" ]; then
98 make clean
99 rm -rf slitaz
100 fi
102 if [ "$mrproper" ]; then
103 make mrproper
104 rm -rf slitaz
105 fi
107 # Get SliTaz current config.
108 if [ "$tazconfig" ]; then
109 echo "Using current SliTaz config: /proc/config.gz"
110 zcat /proc/config.gz > .config
111 yes '' | make oldconfig
112 fi
114 # Create a new default config.
115 if [ "$defconfig" ]; then
116 make defconfig
117 fi
119 # Update config and wipe out unloaded modules.
120 if [ "$localmod" ]; then
121 make localmodconfig
122 fi
124 #
125 # Configurators text/ncurses/Qt/GTK
126 #
128 if [ "$config" ]; then
129 echo "Starting Text mode configuration tool..."
130 make config
131 fi
133 if [ "$menuconfig" ]; then
134 echo "Starting Ncurses configuration tool..."
135 check_pkg ncurses-dev
136 make menuconfig
137 fi
139 if [ "$xconfig" ]; then
140 echo "Starting QT configuration tool..."
141 check_pkg qt-4
142 make xconfig
143 fi
145 if [ "$gconfig" ]; then
146 echo "Starting GTK+ configuration tool..."
147 check_pkg gtk+-dev
148 check_pkg libglade-dev
149 make gconfig
150 fi
152 if [ "$bzImage" ]; then
153 echo "Building bzImage..."
154 make bzImage || exit 1
155 mkdir -p slitaz/linux-custom-$version/fs/boot
156 cp -f arch/x86/boot/bzImage \
157 slitaz/linux-custom-$version/fs/boot/vmlinuz-$version
158 fi
160 if [ "$modules" ]; then
161 echo "Building modules..."
162 make modules || exit 1
163 make INSTALL_MOD_PATH=slitaz/linux-custom-$version/fs modules_install
164 rm -f slitaz/linux-custom-$version/fs/lib/modules/$version/build
165 rm -f slitaz/linux-custom-$version/fs/lib/modules/$version/source
166 fi
168 #
169 # Packaging
170 #
172 if [ -d "slitaz/linux-custom-$version/fs" ]; then
173 echo "Packing Linux..."
174 cd slitaz
175 else
176 echo -n "Packing Linux:" && colorize 31 " not yet built"
177 exit 0
178 fi
180 # Receipt.
181 echo "Creating the receipt..."
182 cat > linux-custom-$version/receipt << EOF
183 # SliTaz package receipt.
185 PACKAGE="linux-custom"
186 VERSION="$version"
187 CATEGORY="base-system"
188 SHORT_DESC="The Linux kernel and modules."
189 MAINTAINER="devel@slitaz.org"
190 WEB_SITE="http://www.kernel.org/"
192 DEPENDS="kmod"
194 ## Pre and post install commands for Tazpkg.
195 post_install()
196 {
197 echo "Processing post-install commands..."
198 depmod -a \$VERSION-custom
199 echo "Check your GRUB menu.lst to boot your new kernel"
200 }
202 EOF
204 ## Pre and post install commands for Tazpkg/Spk.
205 #post_install()
206 #{
207 #echo "Processing post-install commands..."
208 #chroot "\$1/" depmod -a \$VERSION
209 ## GRUB stuff.
210 #if [ -f "\$1/boot/grub/menu.lst" ]; then
211 #root_dev=\$(cat $1/boot/grub/menu.lst | grep root= | sed 's/.*root=\([^ ]*\).*/\1/' | head -n 1)
212 #grub_dev=\$(cat $1/boot/grub/menu.lst | grep "root (" | head -n 1)
213 ## Add new kernel entry in case of upgrade for installed system.
214 #if ! grep -q vmlinuz-\$VERSION \$1/boot/grub/menu.lst; then
215 #cat >> \$1/boot/grub/menu.lst << EOT
217 #title SliTaz GNU/Linux (Kernel \$VERSION)
218 #\$grub_dev
219 #kernel /boot/vmlinuz-\$VERSION root=\$root_dev
220 #EOT
221 #fi
222 #}
224 # Pack it.
225 tazpkg pack linux-custom-$version
227 # Install the new kernel.
228 if [ "$install" ]; then
229 cd $cookdir/linux-$version/slitaz
230 tazpkg -i linux-custom-$version.tazpkg --forced
231 fi
233 exit 0