Added command line options to rebuild-kernel.sh
[systemrescuecd.git] / buildscripts / rebuild-kernel.sh
1 #!/bin/bash
2
3 PROG="${0}"
4 ISODIR=/worksrc/isofiles
5 REPOSRC=/worksrc/sysresccd-src
6 REPOBIN=/worksrc/sysresccd-bin
7 CATALYSTDIR=/var/tmp/catalyst
8
9 usage()
10 {
11         cat <<EOF
12 Usage: ${PROG} [options] <imagename>
13
14 Build the distribution kernel (and other things?)
15
16 imagename: rescue64 | altker32 | altker64
17
18 Options:
19  -h|--help         Display this screen and exit
20  -i ISODIR         Directory containing the iso file to rebuild ($ISODIR)
21                      <isodir>/systemrescuecd-<arch>-current.iso
22  -r REPOSRC        Location of git systemrescuecd repo ($REPOSRC)
23  -b REPOBIN        ? ($REPOBIN)
24  -m CATALYSTDIR    Set catalyst's output directory ($CATALYSTDIR)
25
26 Distributed under the GNU Public License version 2 - http://www.sysresccd.org
27 EOF
28 }
29
30 while getopts "i:r:b:c:" Option
31 do
32         case $Option in
33                 i ) ISODIR="$OPTARG";;
34                 r ) REPOSRC="$OPTARG";;
35                 b ) REPOBIN="$OPTARG";;
36                 c ) CATALYSTDIR="$OPTARG";;
37                 * ) usage; exit 1;;  # Default, handles -h
38         esac
39 done
40 shift $(($OPTIND - 1))
41
42 IMAGENAME="$1"
43 case ${IMAGENAME} in
44         rescue64)
45                 KERTYPE=std
46                 ARCH=amd64
47                 BASEARCH=x86
48                 LIBDIR=lib64
49                 ;;
50         altker32)
51                 KERTYPE=alt
52                 ARCH=i386
53                 BASEARCH=x86
54                 LIBDIR=lib
55                 ;;
56         altker64)
57                 KERTYPE=alt
58                 ARCH=amd64
59                 BASEARCH=x86
60                 LIBDIR=lib64
61                 ;;
62         *)
63                 usage
64                 exit 1
65                 ;;
66 esac
67 VERSION=$(cat ${REPOSRC}/overlay-squashfs-${BASEARCH}/root/version)
68
69 SPEC=$(cat ${REPOSRC}/mainfiles/sysresccd-stage2-${IMAGENAME}.spec \
70     | sed "s!VERSION_STAMP!${VERSION}-${KERTYPE}!" \
71     | sed "s!ISODIR!${ISODIR}!" \
72     | sed "s!REPOSRC!${REPOSRC}!" \
73     | sed "s!REPOBIN!${REPOBIN}!" \
74     )
75 (cd ${REPOSRC}/mainfiles ; nice catalyst -a -f <(echo "$SPEC") )
76
77 targetdir="${REPOBIN}/overlay-squashfs-x86/${LIBDIR}/modules"
78 rootkernel=$(ls -d ${CATALYSTDIR}/builds/default/livecd-stage2-${ARCH}-*-${KERTYPE}/isolinux)
79 rootmodule=$(ls -d ${CATALYSTDIR}/tmp/default/livecd-stage2-${ARCH}-*-${KERTYPE}/${LIBDIR}/modules)
80 kerversion=$(ls ${rootmodule})
81
82 echo "rootkernel=[${rootkernel}]"
83 echo "rootmodule=[${rootmodule}]"
84 echo "kerversion=[${rootmodule}]"
85
86 echo "cp ${rootkernel}/${IMAGENAME}* ${REPOBIN}/kernels-x86/"
87 cp ${rootkernel}/${IMAGENAME}* ${REPOBIN}/kernels-x86/
88
89 echo "(cd ${rootmodule} ; tar cfj ${targetdir}/${kerversion}.tar.bz2 ${kerversion})"
90 (cd ${rootmodule} ; tar cfj ${targetdir}/${kerversion}.tar.bz2 ${kerversion})