cookutils view cooklinux @ rev 886

cook: cook_copy_files() and cook_copy_folders(): don't over-copy already copied files/folders keeping hardlinked files/folders at the same time.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Mar 01 18:46:12 2017 +0200 (2017-03-01)
parents 0b59118bbd03
children de8a102a01d9
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-15 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 --localmod Update config removing all unloaded modules
37 --config Update current config with a text based front-end
38 --menuconfig Update current config with a menu based program
39 --xconfig Update current config with a QT based front-end
40 --gconfig Update current config with a GTK based front-end
41 --bzImage Build the compressed kernel image
42 --modules Build all kernel modules
44 $(boldify 'Examples:')
45 $(basename $0) 3.8.3 --defconfig --menuconfig --bzImage
46 $(basename $0) 3.2.14 --tazconfig --bzImage --modules
48 EOT
49 }
52 # Check and install a packages
54 check_pkg() {
55 if [ ! -f "$PKGS_DB/installed/$1/receipt" ]; then
56 echo -n "Installing package:"; colorize 34 " $1"
57 tazpkg -gi $1 2>/dev/null >/dev/null
58 fi
59 }
62 #
63 # Commands/help - Support 4.x, 3.x, 2.6 and 2.4 kernels.
64 #
66 case "$1" in
67 4.*) wgeturl="${srcurl}/v4.x/" ;;
68 3.*) wgeturl="${srcurl}/v3.0/" ;;
69 2.6.*) wgeturl="${srcurl}/v2.6/" ;;
70 2.4.*) wgeturl="${srcurl}/v2.4/" ;;
71 -h|-u|help|usage|"")
72 usage; exit 0 ;;
73 esac
76 # Sanity check
77 if [ -z "$wgeturl" ]; then
78 echo 'Unable to set download url';
79 exit 0
80 fi
83 #
84 # Build start
85 #
87 echo -n 'Building Linux kernel:'; colorize 32 " $version"
88 echo -n 'Source directory:'; colorize 30 " $cookdir"
90 # Install needed packages to compile.
91 for pkg in slitaz-toolchain pkg-config perl xz lzma patch tar bc flex
92 do
93 check_pkg $pkg
94 done
96 # Get the source and extract tarball.
97 mkdir -p $cookdir && cd $cookdir || exit 1
98 if [ ! -f "linux-$version.tar.xz" ]; then
99 echo "Downloading Linux kernel source..."
100 wget -c --no-check-certificate ${wgeturl}linux-$version.tar.xz
101 fi
102 if [ ! -d "linux-$version" ]; then
103 echo "Extracting: linux-$version.tar.xz"
104 unxz -c linux-$version.tar.xz | tar -xf -
105 fi
107 # Clean-up and get or update config
108 cd linux-$version
110 if [ -n "$clean" ]; then
111 make clean
112 rm -rf slitaz
113 fi
115 if [ -n "$mrproper" ]; then
116 make mrproper
117 rm -rf slitaz
118 fi
120 # Get SliTaz current config.
121 if [ -n "$tazconfig" ]; then
122 echo 'Using current SliTaz config: /proc/config.gz'
123 zcat /proc/config.gz > .config
124 yes '' | make oldconfig
125 fi
127 # Create a new default config.
128 if [ -n "$defconfig" ]; then
129 make defconfig
130 fi
132 # Update config and wipe out unloaded modules.
133 if [ -n "$localmod" ]; then
134 make localmodconfig
135 fi
138 #
139 # Configurators text/ncurses/Qt/GTK
140 #
142 if [ -n "$config" ]; then
143 echo 'Starting Text mode configuration tool...'
144 make config
145 fi
147 if [ -n "$menuconfig" ]; then
148 echo 'Starting Ncurses configuration tool...'
149 check_pkg ncurses-dev
150 make menuconfig
151 fi
153 if [ -n "$xconfig" ]; then
154 echo 'Starting Qt configuration tool...'
155 check_pkg Qt4-dev
156 make xconfig
157 fi
159 if [ -n "$gconfig" ]; then
160 echo 'Starting GTK+ configuration tool...'
161 check_pkg gtk+-dev
162 check_pkg libglade-dev
163 make gconfig
164 fi
166 if [ -n "$bzImage" ]; then
167 echo 'Building bzImage...'
168 make bzImage || exit 1
169 mkdir -p slitaz/linux-custom-$version/fs/boot
170 cp -f arch/x86/boot/bzImage \
171 slitaz/linux-custom-$version/fs/boot/vmlinuz-$version
172 fi
174 if [ -n "$modules" ]; then
175 echo 'Building modules...'
176 make modules || exit 1
177 make INSTALL_MOD_PATH=slitaz/linux-custom-$version/fs modules_install
178 rm -f slitaz/linux-custom-$version/fs/lib/modules/$version/build
179 rm -f slitaz/linux-custom-$version/fs/lib/modules/$version/source
180 fi
183 #
184 # Packaging
185 #
187 if [ -d "slitaz/linux-custom-$version/fs" ]; then
188 echo 'Packing Linux...'
189 cd slitaz
190 else
191 echo -n 'Packing Linux:'; colorize 31 ' not yet built'
192 exit 0
193 fi
195 # Receipt.
196 echo 'Creating the receipt...'
197 cat > linux-custom-$version/receipt <<EOF
198 # SliTaz package receipt.
200 PACKAGE="linux-custom"
201 VERSION="$version"
202 CATEGORY="base-system"
203 SHORT_DESC="The Linux kernel and modules."
204 MAINTAINER="devel@slitaz.org"
205 WEB_SITE="http://www.kernel.org/"
207 DEPENDS="kmod"
209 ## Pre and post install commands for Tazpkg.
210 post_install()
211 {
212 echo "Processing post-install commands..."
213 depmod -a \$VERSION-custom
214 echo "Check your GRUB menu.lst to boot your new kernel"
215 }
217 EOF
219 ## Pre and post install commands for Tazpkg/Spk.
220 #post_install()
221 #{
222 #echo "Processing post-install commands..."
223 #chroot "\$1/" depmod -a \$VERSION
224 ## GRUB stuff.
225 #if [ -f "\$1/boot/grub/menu.lst" ]; then
226 #root_dev=\$(cat $1/boot/grub/menu.lst | grep root= | sed 's/.*root=\([^ ]*\).*/\1/' | head -n 1)
227 #grub_dev=\$(cat $1/boot/grub/menu.lst | grep "root (" | head -n 1)
228 ## Add new kernel entry in case of upgrade for installed system.
229 #if ! grep -q vmlinuz-\$VERSION \$1/boot/grub/menu.lst; then
230 #cat >> \$1/boot/grub/menu.lst << EOT
232 #title SliTaz GNU/Linux (Kernel \$VERSION)
233 #\$grub_dev
234 #kernel /boot/vmlinuz-\$VERSION root=\$root_dev
235 #EOT
236 #fi
237 #}
239 # Pack it.
240 tazpkg pack linux-custom-$version
242 # Install the new kernel.
243 if [ -n "$install" ]; then
244 cd $cookdir/linux-$version/slitaz
245 tazpkg -i linux-custom-$version.tazpkg --forced
246 fi
248 exit 0