cookutils view cooklinux @ rev 933
cook: fix commands --clean, --getsrc, --block, --unblock; lighttpd/index.cgi: add rich statistics on main page.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Sun Jun 18 15:13:29 2017 +0300 (2017-06-18) |
parents | 9611369825b9 |
children |
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-17 SliTaz GNU/Linux - BSD License
8 #
9 # Author: Christophe Lincoln <pankso@slitaz.org>
10 #
12 . /lib/libtaz.sh
13 . /etc/slitaz/slitaz.conf
15 version="$1"
16 cookdir='/home/slitaz/src'
17 srcurl='https://www.kernel.org/pub/linux/kernel'
19 check_root
22 # Help and usage
24 usage() {
25 cat <<EOT
27 SliTaz Linux Kernel cooker
29 $(boldify 'Usage:') $(basename $0) [version] [--options]
31 $(boldify 'Options:')
32 --clean Remove various generated files but keep the config
33 --mrproper Remove all generated files + config + backup files
34 --defconfig New config with default from ARCH supplied defconfig
35 --tazconfig New config using current SliTaz /proc/config.gz
36 --allno New minimal config answering no to everything
37 --localmod Update config removing all unloaded modules
38 --config Update current config with a text based front-end
39 --menuconfig Update current config with a menu based program
40 --xconfig Update current config with a QT based front-end
41 --gconfig Update current config with a GTK based front-end
42 --bzImage Build the compressed kernel image
43 --modules Build all kernel modules
45 $(boldify 'Examples:')
46 $(basename $0) 3.8.3 --defconfig --menuconfig --bzImage
47 $(basename $0) 3.2.14 --tazconfig --bzImage --modules
49 EOT
50 }
53 # Check and install a packages
55 check_pkg() {
56 if [ ! -f "$PKGS_DB/installed/$1/receipt" ]; then
57 echo -n "Installing package:"; colorize 34 " $1"
58 tazpkg -gi $1 2>/dev/null >/dev/null
59 fi
60 }
63 #
64 # Commands/help - Support 4.x, 3.x, 2.6 and 2.4 kernels.
65 #
67 case "$1" in
68 4.*) wgeturl="${srcurl}/v4.x/" ;;
69 3.*) wgeturl="${srcurl}/v3.0/" ;;
70 2.6.*) wgeturl="${srcurl}/v2.6/" ;;
71 2.4.*) wgeturl="${srcurl}/v2.4/" ;;
72 -h|-u|help|usage|"")
73 usage; exit 0 ;;
74 esac
77 # Sanity check
78 if [ -z "$wgeturl" ]; then
79 echo 'Unable to set download url';
80 exit 0
81 fi
84 #
85 # Build start
86 #
88 echo -n 'Building Linux kernel:'; colorize 32 " $version"
89 echo -n 'Source directory:'; colorize 30 " $cookdir"
91 # Install needed packages to compile.
92 for pkg in slitaz-toolchain pkg-config perl xz lzma patch tar bc flex
93 do
94 check_pkg ${pkg}
95 done
97 # Get the source and extract tarball.
98 mkdir -p $cookdir && cd $cookdir || exit 1
99 if [ ! -f "linux-$version.tar.xz" ]; then
100 echo "Downloading Linux kernel source..."
101 wget -c --no-check-certificate ${wgeturl}linux-$version.tar.xz
102 fi
103 if [ ! -d "linux-$version" ]; then
104 echo "Extracting: linux-$version.tar.xz"
105 unxz -c linux-$version.tar.xz | tar -xf -
106 fi
108 # Clean-up and get or update config
109 cd linux-$version
111 if [ -n "$clean" ]; then
112 make clean
113 rm -rf slitaz
114 fi
116 if [ -n "$mrproper" ]; then
117 make mrproper
118 rm -rf slitaz
119 fi
121 # Get SliTaz current config.
122 if [ -n "$tazconfig" ]; then
123 echo 'Using current SliTaz config: /proc/config.gz'
124 zcat /proc/config.gz > .config
125 yes '' | make oldconfig
126 fi
128 # Create a new default config.
129 if [ -n "$defconfig" ]; then
130 make defconfig
131 fi
133 # Create a minimal config file.
134 if [ -n "$allno" ]; then
135 make allnoconfig
136 fi
138 # Update config and wipe out unloaded modules.
139 if [ -n "$localmod" ]; then
140 make localmodconfig
141 fi
144 #
145 # Configurators text/ncurses/Qt/GTK
146 #
148 if [ -n "$config" ]; then
149 echo 'Starting Text mode configuration tool...'
150 make config
151 fi
153 if [ -n "$menuconfig" ]; then
154 echo 'Starting Ncurses configuration tool...'
155 check_pkg ncurses-dev
156 make menuconfig
157 fi
159 if [ -n "$xconfig" ]; then
160 echo 'Starting Qt configuration tool...'
161 check_pkg Qt4-dev
162 make xconfig
163 fi
165 if [ -n "$gconfig" ]; then
166 echo 'Starting GTK+ configuration tool...'
167 check_pkg gtk+-dev
168 check_pkg libglade-dev
169 make gconfig
170 fi
172 if [ -n "$bzImage" ]; then
173 echo 'Building bzImage...'
174 make bzImage || exit 1
175 mkdir -p slitaz/linux-custom-$version/fs/boot
176 cp -f arch/x86/boot/bzImage \
177 slitaz/linux-custom-$version/fs/boot/vmlinuz-$version
178 fi
180 if [ -n "$modules" ]; then
181 echo 'Building modules...'
182 make modules || exit 1
183 make INSTALL_MOD_PATH=slitaz/linux-custom-$version/fs modules_install
184 rm -f slitaz/linux-custom-$version/fs/lib/modules/$version/build
185 rm -f slitaz/linux-custom-$version/fs/lib/modules/$version/source
186 fi
189 #
190 # Packaging
191 #
193 if [ -d "slitaz/linux-custom-$version/fs" ]; then
194 echo 'Packing Linux...'
195 cd slitaz
196 else
197 echo -n 'Packing Linux:'; colorize 31 ' not yet built'
198 exit 0
199 fi
201 # Receipt.
202 echo 'Creating the receipt...'
203 cat > linux-custom-$version/receipt <<EOF
204 # SliTaz package receipt.
206 PACKAGE="linux-custom"
207 VERSION="$version"
208 CATEGORY="base-system"
209 SHORT_DESC="The Linux kernel and modules."
210 MAINTAINER="devel@slitaz.org"
211 WEB_SITE="http://www.kernel.org/"
213 DEPENDS="kmod"
215 ## Pre and post install commands for Tazpkg.
216 post_install()
217 {
218 echo "Processing post-install commands..."
219 depmod -a \$VERSION-custom
220 echo "Check your GRUB menu.lst to boot your new kernel"
221 }
223 EOF
225 ## Pre and post install commands for Tazpkg/Spk.
226 #post_install()
227 #{
228 #echo "Processing post-install commands..."
229 #chroot "\$1/" depmod -a \$VERSION
230 ## GRUB stuff.
231 #if [ -f "\$1/boot/grub/menu.lst" ]; then
232 #root_dev=\$(cat $1/boot/grub/menu.lst | grep root= | sed 's/.*root=\([^ ]*\).*/\1/' | head -n 1)
233 #grub_dev=\$(cat $1/boot/grub/menu.lst | grep "root (" | head -n 1)
234 ## Add new kernel entry in case of upgrade for installed system.
235 #if ! grep -q vmlinuz-\$VERSION \$1/boot/grub/menu.lst; then
236 #cat >> \$1/boot/grub/menu.lst << EOT
238 #title SliTaz GNU/Linux (Kernel \$VERSION)
239 #\$grub_dev
240 #kernel /boot/vmlinuz-\$VERSION root=\$root_dev
241 #EOT
242 #fi
243 #}
245 # Pack it.
246 tazpkg pack linux-custom-$version
248 # Install the new kernel.
249 if [ -n "$install" ]; then
250 cd $cookdir/linux-$version/slitaz
251 tazpkg -i linux-custom-$version.tazpkg --forced
252 fi
254 exit 0