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