-
Notifications
You must be signed in to change notification settings - Fork 2
/
installkernel
executable file
·871 lines (727 loc) · 20.9 KB
/
installkernel
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
#!/bin/sh
##
## installkernel - Script for installing Linux kernel.
## Copyright 2004-2012 by Michal Nazarewicz (mina86/AT/mina86.com)
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
## This is part of Tiny Applications Collection
## -> http://tinyapps.sourceforge.net/
##
##
## Basic initialization
##
set -e
USER="$(id -un)"
ARG0="${0##*/}"
LOWER_CHARS=abcdefghijklmnopqrstuvwxyz-
UPPER_CHARS=ABCDEFGHIJKLMNOPQRSTUVWXYZ_
trap "" USR1 USR2
##
## Converts string to integer
##
toInt () {
# shellcheck disable=SC2003
expr 0"$(expr "X$1" : 'X[[:space:]]*\([0-9]*\)')" + 0 2>/dev/null || true
}
##
## Version & lockfile
##
if [ -z "$INSIDE_INSTALLKERNEL" ]; then
echo 'installkernel v17.0 (c) 2004-2012 by Michal Nazarewicz'
echo
# Lockfile check
IK_LOCK=/tmp/installkernel-lockfile
if [ -d /var/lock ] && [ -w /var/lock ]; then
IK_LOCK=/var/lock/installkernel-lck
fi
ERR=
ln -s $$ "$IK_LOCK" >/dev/null 2>&1 || ERR=y
PID=$(readlink "$IK_LOCK")
if [ -n "$ERR" ] || [ "$PID" -ne $$ ]; then
cat <<EOF
$ARG0: seems like another instance of installkernel is running
$ARG0: with pid $PID, make sure there is only one instance and
$ARG0: remove $IK_LOCK if that is the case.
EOF
exit 4
fi
unset ERR PID
export IK_LOCK
fi
##
## Help
##
usage () {
cat<<END
usage: installkernel [<options>] [<switches>]
[<version> [<image> [<systemmap> [<prefix>]]]]
<options> are:
-h --help Display this screen and exits
-V --version Display vesion and exits
-a --arch=<arch> Set ARCH variable to <arch> or \$ARCH if '-' [auto]
--kversion=<ver> Same as <version>
--image=<image> Same as <image>
--map=<systemmap> Same as <systemmap>
--bootdir=<dir> Same as <prefix>
--cd[=<dir>] Change directory to <dir> (/usr/src/linux if ommited)
-o --out[=<dir>] Build kernel in <dir> (/usr/src/linux-build if ommited)
--su Trt to became root (implies --user=<current-user>)
-u --user=<user> Runs everything not requiring SU privilages as <user>
-nu --no-user Synonym of --user=
--nice=<nice> Adjust priority by <nice> (but never lower)
--nice=!<nice> Set pririty to <nice> (but never lower) [10]
--no-nice Synonym of --nice=0
-j --jobs=<jobs> Pass -j<jobs> to make [auto]
-- This option causes all options not starting with a
dash to be interpreted as long (if at least 3-char
long) or short (if no more then 2-char long) options
<switches> are:
--dry-run Only display what would be done [no]
--print-commands Print commands [no]
-v --verbose Become more verbose [no]
-vv Become even more verbose [no]
--color Use colors [auto]
-r<hook>
--run-<hook> Run given hook, event or set of hooks [yes]
-c --clean Run 'make clean' before compilation [no]
-C --config Run 'make (x|g|menu|)config' to configure [no]
-C --config=<cfg> Specify a type of config to run [auto]
--*config Synonym of --config=*config
-d --make-dep Run 'make dep' [**]
-O --overwrite Overwrite the kernel image [no]
-A --all Synonym of all of the below
-i --compile-image Run 'make bzImage' to compile image [no]
-I --install-image Copy kernel to bootdir and update symlinks [*]
-t --tidy-image Remove old images [no]
--image Synonym of the three above
-m --compile-modules Run 'make modules' [no]
-M --install-modules Run 'make modules_install' [no]
-T --tidy-modules Remove old modules [no]
--modules Synonym of the three above
--compile Synonym of --compile-image --compile-modules
--install Synonym of --install-image --install-modules
--tidy Synonym of --tidy-image --tidy-modules
[*] yes if only <version> <image> <systemmap> and <bootdir> where given.
[**] yes if compiling image and <version> is 2.4.x.
Negated by prefixing switch with 'no-' (long option) or 'n' (short option).
<version> kernel version [auto]
<image> path to kernel image [arch/\$ARCH/boot/bzImage]
<systemmap> path to System.map file [System.map]
<prefix> directory where to install the kernal image [/boot]
END
}
##
## Printing helpers
##
error () {
__EC=$1
shift
echo "${0##*/}: $*" >&2
INSTALLKERNEL_EXITED=$__EC
exit "$__EC"
}
msg () {
if [ -n "$USE_ANSI" ] && [ -n "$1" ]
then printf ' \33[%sm%-7s %s\33[0m\n' "$1" "$2" "$3"
else printf ' %-7s %s\n' "$2" "$3"
fi
}
##
## Signals etc
##
sig_handler () {
msg 31 SIG "Got SIG$1; terminating..."
error 5 "Got SIG$1; terminating..."
}
for E in HUP INT QUIT ILL ABRT FPE SEGV PIPE ALRM TERM TSTP; do
# shellcheck disable=SC2064
trap "sig_handler $E" $E
done
unset E
exit_function () {
__EC=$?
rm -f -- "$IK_LOCK"
if [ $__EC -ne 0 ] && [ "X$INSTALLKERNEL_EXITED" != "X$__EC" ]; then
msg 31 ERR "Comand's exit code: $__EC"
error $__EC "Comand's exit code: $__EC"
fi
return 0
}
trap exit_function 0
##
## Prints header
##
if [ -z "$COLUMNS" ]; then
COLS=$(toInt "$(stty -a | sed -ne 's/^.*columns[[:space:]][[:space:]]*\([0-9][0-9]*\).*$/\1/p')")
if [ "$COLS" -gt 30 ]; then
COLUMNS=$COLS
export COLUMNS
fi
unset COLS
fi
header () {
__TITLE="$*"
if [ -n "$USE_ANSI" ]
then printf "\33[32m=== \33[1m%s\33[0;32m " "$__TITLE"
else printf "=== %s " "$__TITLE"
fi
__LOOP=$(( ${COLUMNS:-80} - ${#__TITLE} - 29))
__STR=
while [ $__LOOP -gt 0 ]; do
__STR="$__STR="
__LOOP=$(( __LOOP - 1 ))
done
date +"$__STR [%y/%m/%d %H:%M:%S] ==="
if [ -n "$USE_ANSI" ]; then printf '\33[0m'; fi
unset __TITLE __STR __LOOP
}
##
## Runs command
##
run () {
__AS=
__SILENT=
__DUMMY=
__FORCE=
__INPUT=
__OUTPUT=
# Arguments
while expr "X$1" : X- >/dev/null 2>&1; do
__ARG="${1#-}"; shift;
while [ -n "$__ARG" ]; do
case "$__ARG" in
u*) __AS="$RUNAS";;
s*) __SILENT=yes ;;
f*) __FORCE=yes ;;
d*) __DUMMY=yes ;;
i*) __INPUT="$1" ; shift;;
o*) __OUTPUT="$1"; shift;;
esac
__ARG="${__ARG#?}"
done
done
# Dry run
if [ -n "$DRY_RUN$PRINT_COMMANDS" ] && [ -z "$__SILENT" ]; then
if [ -n "$__AS" ]; then __MSG="[as $__AS] "; else __MSG=; fi
__END=
if [ -n "$__INPUT" ]; then __END="<$__INPUT "; fi
if [ -n "$__OUTPUT" ]; then __END="$__END>$__OUTPUT"; fi
msg '36' RUN "$__MSG$(printf "'%s' " "$@")$__END"
fi
# Don't run really
if [ -n "$DRY_RUN" ] && [ -z "$__FORCE" ]; then return 0; fi
if [ -n "$__DUMMY" ]; then return 0; fi
# cd cannot be run throught su or nice
if [ "X$1" = Xcd ]; then
"$@"
return $?
fi
# Run as
if [ -n "$__AS" ] && [ "X$__AS" != "X$USER" ]; then
__ARGS=
while [ $# -ne 0 ]; do
__ARGS="$__ARGS '$(echo "$1" | sed -e "s/'/'\\\\''/")'"
shift
done
set -- su "$__AS" -c "$__ARGS"
unset __ARGS
fi
# Run
if [ -z "$__INPUT$__OUTPUT" ]; then "$@"
elif [ -z "$__INPUT" ]; then "$@" |>"$__OUTPUT"
elif [ -z "$__OUTPUT" ]; then "$@" <"$__INPUT"
else "$@" <"$__INPUT" |>"$__OUTPUT"
fi
}
##
## Runs /etc/installekrnel.d/hook-handler scripts
##
if [ -x /etc/installkernel.d/hook-handler ]; then
run_hook () {
case "$RUN_HOOKS" in
*:"$1":*)
__HOOK=$1
shift
run "$@" /etc/installkernel.d/hook-handler "$__HOOK"
unset __HOOK
esac
}
else
run_hook () {
true
}
fi
##
## Prints header, run_hook and run on condition
##
r () {
if [ "X$1" = X-u ]; then __USR=-u; shift; else __USR=; fi
# shellcheck disable=SC2086
if eval [ -z \"\$$1\" ]; then return 0; fi
__NAME=$(echo "$1" | tr $UPPER_CHARS $LOWER_CHARS)
header "$2"
shift 2
run_hook "pre-$__NAME" $__USR
run $__USR "$@"
run_hook "post-$__NAME" $__USR
unset __NAME __USR
}
##
## Reads kernel version number
##
update_ver () {
if [ -z "$VER" ]; then
VER=${KBUILD_OUTPUT:-.}/include/config/kernel.release
if [ -e "$VER" ]; then
read VER <"$VER"
msg '37;1' VER "$VER"
else
error 2 "$VER: file does not exist"
fi
fi
}
##
## Set hooks
##
# set_run_hooks <value> [ <prefix> [ <hook> ] ]
set_run_hooks () {
if [ X"$3" = Xhooks ] || [ -z "$3" ]; then set -- "$1" "$2"; fi
if [ $# -eq 2 ] && [ -z "$2" ]; then set -- "$1"; fi
if [ $# -eq 1 ] && [ -z "$1" ]; then set --; fi
# Remove all
if [ $# -eq 0 ]; then
RUN_HOOKS=:
export RUN_HOOKS
return 0
fi
# Add all
if [ $# -eq 1 ]; then
RUN_HOOKS=:
set -- clean config make-dep compile-image
set -- "$@" install-image tidy-image compile-modules
set -- "$@" install-modules tidy-modules work
while [ $# -gt 0 ]; do
RUN_HOOKS="${RUN_HOOKS}pre-$1:post-$1:"
shift
done
export RUN_HOOKS
return 0
fi
# Prepare arguments for later processing
if [ $# -eq 2 ]; then
__PRE="$2"
set -- "$1"
for __EV in clean config make-dep compile-image \
install-image tidy-image compile-modules install-modules \
tidy-modules work; do
set -- "$1" "$__PRE-$__EV"
done
unset __EV
elif [ -n "$2" ]; then
set -- "$1" "$2-$3"
else
set -- "$1" "pre-$3" "post-$3"
fi
if [ -n "$1" ]; then
# Add
shift
while [ $# -gt 0 ]; do
case "$RUN_HOOKS" in
*:$1:*) ;;
*) RUN_HOOKS="$RUN_HOOKS$1:"
esac
shift
done
else
# Remove
shift
while [ $# -gt 0 ]; do
case "$RUN_HOOKS" in
*:$1:*) RUN_HOOKS=${RUN_HOOKS%:$1:*}:${RUN_HOOKS#*:$1:}
esac
shift
done
fi
export RUN_HOOKS
}
if [ -z "$INSIDE_INSTALLKERNEL" ]; then
##
## Init default options
##
if [ -z "$INSTALL_PATH" ]; then
INSTALL_PATH=/boot
export INSTALL_PATH
fi
SU=; NICE=!10; __ARCH="$ARCH"; DASHDASH=
VER=; BUILD=; IMG_PATH=; MAP_PATH=; RUNAS=; ARCH=; JOBS=auto
KBUILD_OUTPUT=
export VER BUILD IMG_PATH MAP_PATH RUNAS ARCH KBUILD_OUTPUT
DRY_RUN=; PRINT_COMMANDS=; VERBOSE=; REALLY_VERBOSE=;
if [ -t 1 ]; then USE_ANSI=y; else USE_ANSI=; fi
export DRY_RUN PRINT_COMMANDS VERBOSE USE_ANSI
CLEAN=; COMPILE_IMAGE=; COMPILE_MODULES=; INSTALL_IMAGE=;
INSTALL_MODULES=; TIDY_IMAGE=; TIDY_MODULES=;
CONFIG=; MAKE_DEP=auto; OVERWRITE_IMAGE=; MAKE_FLAGS=;
export CLEAN COMPILE_IMAGE COMPILE_MODULES INSTALL_IMAGE
export INSTALL_MODULES TIDY_IMAGE TIDY_MODULES
export CONFIG MAKE_DEP OVERWRITE_IMAGE MAKE_FLAGS
set_run_hooks y
##
## Parse arguments
##
ADD_ARGS=0
NUMARGS=$#
for ARG; do
PARAM=
# Dash dash at work?
if [ -n "$DASHDASH" ]; then
case "$ARG" in
-*) : ;;
?|n?|vv) ARG=-$ARG ;;
*) ARG=--$ARG ;;
esac
fi
## Options
case "$ARG" in
--help|-h) usage; exit 0;;
--version|-V) exit 0;;
--arch=*) ARCH="${ARG#--arch=}";;
-a*) ARCH="${ARG#-a}"; ;;
--kversion=*) VER="${ARG#--kversion=}"; ;;
--image=*) IMG_PATH="${ARG#--image=}"; ;;
--map=*) MAP_PATH="${ARG#--map=}"; ;;
--bootdir=*) INSTALL_PATH="${ARG#--bootdir=}" ;;
--cd=*) CD="${ARG#--cd=}";;
--cd) CD=/usr/src/linux;;
-o|--out) KBUILD_OUTPUT=/usr/src/linux-build;;
-o?*) KBUILD_OUTPUT="${ARG#-o}" ;;
--out=*) KBUILD_OUTPUT="${ARG#--out=}";;
--config=no) CONFIG=;;
--no-config) CONFIG=;;
--noconfig) CONFIG=;;
--config) [ -n "$CONFIG" ] || CONFIG=auto;;
--config=auto) CONFIG=auto;;
--config=*config) CONFIG="${ARG#--config=}";;
--config=*) CONFIG="${ARG#--config=}config";;
--*config) CONFIG="${ARG#--}";;
--su) SU=y; RUNAS="$USER";;
--user=*) RUNAS="${ARG#--user=}";;
-u*) RUNAS="${ARG#-u}";;
-nu|--no-user) RUNAS=;;
--nice=*) NICE="${ARG#--nice=}";;
--no-nice) NICE=0;;
-j?*) JOBS=${ARG#-j};;
--jobs=*) JOBS=${ARG#--jobs=};;
--) DASHDASH=y;;
-r*) VALUE=y; PARAM="--run-${ARG#-r}";;
-nr*) VALUE=; PARAM="--run-${ARG#-nr}";;
-n?) VALUE=: PARAM="-${ARG#-n}";;
--no-*) VALUE=; PARAM="--${ARG#--no-}";;
--*) VALUE=y; PARAM="--${ARG#--}";;
-*) VALUE=y; PARAM="$ARG";;
*)
if [ $ADD_ARGS -eq 0 ]; then VER="$ARG"
elif [ $ADD_ARGS -eq 1 ]; then IMG_PATH="$ARG"
elif [ $ADD_ARGS -eq 2 ]; then MAP_PATH="$ARG"
elif [ $ADD_ARGS -eq 3 ]; then INSTALL_PATH="$ARG"
else error 1 unknown option: "$ARG"
fi
ADD_ARGS=$(( ADD_ARGS + 1 ))
esac
## Switches
if [ -z "$PARAM" ]; then continue; fi
HOOK=
case "$PARAM" in
--dry-run) DRY_RUN=$VALUE ;;
-v|--verbose) VERBOSE=$VALUE ;
if [ -n "$VALUE" ]; then PRINT_COMMANDS=y; fi;;
-vv) REALLY_VERBOSE=$VALUE;
if [ -n "$VALUE" ]; then VERBOSE=y; PRINT_COMMANDS=y; fi;;
--print-commands) PRINT_COMMANDS=$VALUE;;
--color) USE_ANSI=$VALUE;;
-c|--clean) CLEAN=$VALUE ;;
-d|--make-dep) MAKE_DEP=$VALUE ;;
-O|--overwrite) OVERWRITE_IMAGE=$VALUE;;
-i|--compile-image) COMPILE_IMAGE=$VALUE ;;
-I|--install-image) INSTALL_IMAGE=$VALUE ;;
-t|--tidy-image) TIDY_IMAGE=$VALUE ;;
--image) COMPILE_IMAGE=$VALUE ;
INSTALL_IMAGE=$VALUE ; TIDY_IMAGE=$VALUE;;
-m|--compile-modules) COMPILE_MODULES=$VALUE;;
-M|--install-modules) INSTALL_MODULES=$VALUE;;
-T|--tidy-modules) TIDY_MODULES=$VALUE ;;
--modules) COMPILE_MODULES=$VALUE;
INSTALL_MODULES=$VALUE; TIDY_MODULES=$VALUE;;
--compile) COMPILE_IMAGE=$VALUE; COMPILE_MODULES=$VALUE;;
--install) INSTALL_IMAGE=$VALUE; INSTALL_MODULES=$VALUE;;
--tidy) TIDY_IMAGE=$VALUE ; TIDY_MODULES=$VALUE ;;
-A|--all)
COMPILE_IMAGE=$VALUE ; COMPILE_MODULES=$VALUE
INSTALL_IMAGE=$VALUE ; INSTALL_MODULES=$VALUE
TIDY_IMAGE=$VALUE ; TIDY_MODULES=$VALUE
;;
--run-*) HOOK="${PARAM#--run-}";;
*) error 1 unknown option: "$ARG"
esac
## Hooks
if [ -z "$HOOK" ]; then continue; fi
case "$HOOK" in
pre-) PRE='pre' ; HOOK="${HOOK#pre-}" ;;
post-) PRE='post'; HOOK="${HOOK#post-}";;
*) PRE=
esac
case "$HOOK" in
hooks|clean|config|make-dep|compile-image|install-image|tidy-image|compile-modules|install-modules|tidy-modules|work)
set_run_hooks "$VALUE" "$PRE" "$HOOK" ;;
*) error 1 unknown event: "$HOOK";;
esac
done
## 'make install' run
if [ "$NUMARGS" -eq 4 ] && [ "$ADD_ARGS" -eq 4 ]; then
INSTALL_IMAGE=y
fi
## --jobs
if [ x"$JOBS" = xauto ]; then
JOBS=$(grep -c ^processor /proc/cpuinfo)
fi
if [ -n "$JOBS" ] && [ "$JOBS" -gt 1 ] 2>/dev/null; then
MAKE_FLAGS="$MAKE_FLAGS -j$JOBS"
fi
unset ARG PARAM HOOK VALUE JOBS
##
## Print header
##
header Starting
INSIDE_INSTALLKERNEL=y
export INSIDE_INSTALLKERNEL
if [ -n "$REALLY_VERBOSE" ]; then
VERBOSE=y
MAKE_FLAGS="$MAKE_FLAGS v=1"
fi
if [ -n "$VERBOSE" ]; then V=v; VOPT=-v; fi
##
## Calculate nice
##
if [ X"${NICE#!}" != X"$NICE" ]; then
NICE=$(( $(toInt "${NICE#!}") - $(nice) ))
else
NICE=$(toInt "$NICE")
fi
if [ "$NICE" -gt 0 ]; then
msg '37;1' NICE "$NICE"
if [ -n "$VERBOSE" ]; then renice "+$NICE" -p $$
else renice "$NICE" -p $$ >/dev/null 2>&1; fi
fi
unset NICE
##
## Set ARCH
##
if [ X"$ARCH" = X- ]; then
ARCH="$__ARCH"
fi
unset __ARCH
if [ -z "$ARCH" ]; then
ARCH=$(uname -m)
case $ARCH in
i?86) ARCH=i386 ; ;;
sun4u) ARCH=sparc64; ;;
arm*|sa110) ARCH=arm ; ;;
s390x) ARCH=s390 ; ;;
parisc64) ARCH=parisc ; ;;
esac
msg '37;1' ARCH "$ARCH"
fi
##
## Change directory
##
if [ -n "$CD" ]; then
run -f cd "$CD"
fi
unset CD
##
## Become root ?
##
if [ -n "$SU" ] && [ "$(id -u)" -ne 0 ]; then
msg '37;1' SU "Becoming super user"
unset SU
if [ -n "$DRY_RUN" ]; then
echo Here you would be asked for root password.
else
case "$0" in
/*) ARGS="$0";;
*/*) ARGS="$PWD/$0";;
*) ARGS=$(which "$0" 2>/dev/null)
esac
set -- "/bin/sh" "$ARGS" "$@"
ARGS=
while [ $# -ne 0 ]; do
ARGS="$ARGS '$(echo "$1" | sed -e "s/'/'\\\\''/")'"
shift
done
# exec was here before but it caused the lock file to
# stall if user provided invalid password
su -c "$ARGS"
exit $?
fi
fi
unset SU
else
if [ -n "$VERBOSE" ]; then V=v; VOPT=-v; fi
fi
unset VERBOSE REALLY_VERBOSE
run_hook pre-work
##
## Make dep?
##
if [ "X$MAKE_DEP" = Xauto ]; then
MAKE_DEP=
if [ -n "$COMPILE_IMAGE" ]; then
case "$VER" in 2.4.*)
MAKE_DEP=y
esac
fi
fi
##
## Check config type
##
if [ "X$CONFIG" = Xauto ]; then
if [ -n "$DISPLAY" ]; then
if [ -n "$(which qtconfig 2>/dev/null)" ]; then
CONFIG=xconfig
elif [ -n "$(which gtk-config 2>/dev/null)" ]; then
CONFIG=gconfig
fi
fi
if [ "X$CONFIG" = Xauto ]; then
CONFIG=config
for DIR in /usr/lib /usr/local/lib /lib; do
for LIB in curses.a curses.so ncurses.a ncurses.so; do
if [ -f "$DIR/lib$LIB" ] || [ -f "${DIR}64/lib$LIB" ]; then
CONFIG=menuconfig
break 2
fi
done
done
fi
fi
##
## make *
##
r -u CLEAN 'Cleaning source tree' make $MAKE_FLAGS clean
r -u CONFIG 'Configuring the kernel' make $MAKE_FLAGS "$CONFIG"
r -u MAKE_DEP 'Updating dependencies' make $MAKE_FLAGS dep
r -u COMPILE_IMAGE 'Compiling bzImage' make $MAKE_FLAGS bzImage
r -u COMPILE_MODULES 'Compiling modules' make $MAKE_FLAGS modules
r INSTALL_MODULES 'Installing modules' make $MAKE_FLAGS modules_install
##
## Removing old images
##
if [ -n "$TIDY_IMAGE" ]; then
header Removing old image
run_hook pre-tidy-image
# shellcheck disable=SC1001
if [ -z "$OVERWRITE_IMAGE" ]; then T=\~; else T=; fi
for FILE in bzImage System.map config; do
msg '37;1' READLNK "$FILE$T"
run -d readlink "$INSTALL_PATH/$FILE$T"
LNK=$(readlink "$INSTALL_PATH/$FILE$T" || true)
if [ -f "$INSTALL_PATH/$LNK" ]; then
msg '37;1' RM "$LNK"
run rm -f$V -- "$INSTALL_PATH/$LNK"
fi
done
run_hook post-tidy-image
fi
##
## Removing old modules
##
read_version_from_link() {
msg '37;1' READLNK "$1"
run -d readlink "$INSTALL_PATH/$1"
set -- "$(readlink "$INSTALL_PATH/$1" 2>/dev/null)"
set -- "${1#*-}"
set -- "${1%-\#*}"
echo "$1"
}
if [ -n "$TIDY_MODULES" ]; then
header Removing old modules
run_hook pre-tidy-modules
update_ver
OVER=$(read_version_from_link bzImage)
OOVER=$(read_version_from_link bzImage~)
if [ -n "$OVERWRITE_IMAGE" ]; then
tmp=$OVER
OVER=$OOVER
OOVER=$tmp
fi
if [ -n "$OOVER" ] && [ "X$OOVER" != "X$VER" ] && \
[ "X$OOVER" != "X$OVER" ] && [ -d "/lib/modules/$OOVER" ]; then
msg '37;1' RMDIR "/lib/modules/$OOVER"
run rm -r$V -- "/lib/modules/$OOVER"
fi
run_hook post-tidy-modules
fi
##
## Copying image
##
if [ -n "$INSTALL_IMAGE" ]; then
header "Installing kernel image"
run_hook pre-install-image
update_ver
if [ -s "${KBUILD_OUTPUT:-.}/.version" ]; then
run -ud cat "${KBUILD_OUTPUT:-.}/"
BUILD=$(printf %d "$(run -usf cat "${KBUILD_OUTPUT:-.}/.version")")
else
BUILD=1
fi
msg '37;1' BUILD "$BUILD"
FVER="$VER-#$BUILD"
if [ -z "$IMG_PATH" ]; then IMG_PATH=arch/$ARCH/boot/bzImage; fi
if [ -z "$MAP_PATH" ]; then MAP_PATH=System.map; fi
mkdir -p -m u=rwx,g=rx,o=rx "$INSTALL_PATH"
set -- "$INSTALL_PATH/bzImage-$FVER" "$INSTALL_PATH/System.map-$FVER" \
"$INSTALL_PATH/config-$FVER"
while [ "$1" ]; do
if [ -f "$1" ]; then
if [ -f "$1~" ]; then
set -- "$1~" "$@"
continue
fi
run mv -f$V -- "$1" "$1~"
fi
shift
done
set --
msg '37;1' CP bzImage
run cp $VOPT -- "${KBUILD_OUTPUT:-.}/$IMG_PATH" "$INSTALL_PATH/bzImage-$FVER"
msg '37;1' CP System.map
run cp $VOPT -- "${KBUILD_OUTPUT:-.}/$MAP_PATH" "$INSTALL_PATH/System.map-$FVER"
msg '37;1' CP .config
run cp $VOPT -- "${KBUILD_OUTPUT:-.}/.config" "$INSTALL_PATH/config-$FVER"
for FILE in bzImage System.map config; do
msg '37;1' READLNK "$FILE"
run -d readlink "$INSTALL_PATH/$FILE" || true
LNK=$(readlink "$INSTALL_PATH/$FILE" || true)
if [ "X$LNK" != "X$FILE-$FVER" ]; then
msg '37;1' LNK "$FILE"
if [ -z "$OVERWRITE_IMAGE" ]; then
run mv -f$V -- "$INSTALL_PATH/$FILE" "$INSTALL_PATH/$FILE~" || true
fi
run ln -fs$V -- "$FILE-$FVER" "$INSTALL_PATH/$FILE"
fi
done
run_hook post-install-image
fi
run_hook post-work