fai fixes
[hdw-linux/hdw-linux.git] / scripts / Make-KPkg
1 #!/bin/bash
2 #
3 # author: hackbard@hackdaworld.dyndns.org
4 #
5 # create a kernel binary package
6 #
7
8 config=""
9 name=""
10 homedir=$PWD
11
12 while [ "$1" ] ; do
13         case "$1" in
14                 -config)        config=$2       ; shift 2 ;;
15                 -name)          name=$2         ; shift 2 ;;
16                 *)
17                         echo
18                         echo "usage:"
19                         echo
20                         echo "-config <kernel config file>"
21                         echo "-name <kernel name>"
22                         echo
23                         exit 1 ;;
24         esac
25 done
26
27 . ./Config
28
29 if [ "$hdw_arch" != "ia32" ] ; then
30         echo "warning: only ia32 supported by now"
31         echo "hack me ... "
32         exit 1
33 fi
34
35 [ -z "$config" ] && config="./misc/arch/${hdw_arch}/linux.config"
36 [ -z "$name" ] && name="custom-$hdw_arch"
37
38 if [ ! -f $config ] ; then
39         echo "$config doesn't exist, aborting ..."
40         exit 1
41 fi
42
43 kerpkg="`grep '^#\ \[D\]' ./packages/base/linux/linux | awk '{ print $3 }'`"
44 kerver="`grep '^#\ \[V\]' ./packages/base/linux/linux | awk '{ print $3 }'`"
45
46 trg=$homedir/kernel-image-${kerver}_${name}.tar.bz2
47 if [ -f $trg ] ; then
48         echo "image $trg already exists, aborting ..."
49         exit 1
50 fi
51
52 [ ! -f ./download/base/linux/$kerpkg ] && ./scripts/Download -package linux
53
54 # backing up old kernel + modules
55 kerbackup=no
56 if [ -f /boot/vmlinuz_$kerver ] ; then
57         mv /boot/vmlinuz_$kerver /boot/vmlinuz_${kerver}__orig
58         kerbackup=yes
59 fi
60 modbackup=no
61 if [ -d /lib/modules/$kerver ] ; then
62         mv /lib/modules/$kerver /lib/modules/${kerver}__orig
63         modbackup=yes
64 fi
65
66 # build kernel & modules
67 kerarch=${hdw_arch//ia32/i386}
68 cp $config /tmp/linux.config
69 rm -rf /tmp/linux-$kerver
70 tar xfj ./download/base/linux/$kerpkg -C /tmp
71 cd /tmp/linux-$kerver
72 mv ../linux.config .config
73 cd include && ln -sf asm-${kerarch} asm && cd ..
74 yes "" | make oldconfig
75 make bzImage modules modules_install
76 cp arch/$kerarch/boot/bzImage /boot/vmlinuz_$kerver
77 cp .config /boot/kernel-config-$kerver-$name
78
79 # create the package
80 cd /
81 tar --use-compress-program=bzip2 -cf $trg lib/modules/$kerver \
82         boot/vmlinuz_$kerver /boot/kernel-config-$kerver-$name
83
84 cd $homedir
85
86 # restore kernel & modules
87 rm -f /boot/vmlinuz_$kerver
88 [ "$kerbackup" = "yes" ] && \
89         mv /boot/vmlinuz_${kerver}__orig /boot/vmlinuz_$kerver
90 rm -rf /lib/modules/$kerver
91 [ "$modbackup" = "yes" ] && \
92         mv /lib/modules/${kerver}__orig /lib/modules/$kerver
93
94 echo
95 echo "done"
96 echo