initial commit: 1.5.0
[systemrescuecd.git] / buildscripts / recreate-iso.sh
1 #!/bin/sh
2
3 VERSION="1.5.0"
4 EXTRAVER=""
5 VOLNAME="sysrcd-1.5.0" 
6 ISODIR=/worksrc/isofiles
7 TEMPDIR=/worksrc/catalyst/isotemp
8 REPOSRC=/worksrc/sysresccd-src
9 REPOBIN=/worksrc/sysresccd-bin
10
11 # ==================================================================
12 # ==================================================================
13
14 usage()
15 {
16         echo "Usage: $0 <arch> <options>"
17         echo "  arch = x86 | amd64 | sparc"
18 }
19
20 if [ "$1" = "x86" ] || [ "$1" = "amd64" ] || [ "$1" = "sparc" ]
21 then
22         CURARCH="$1"
23 else
24         usage
25         exit 1
26 fi
27
28 # ========= copy files from the temp iso image ================================
29 CURFILE="${ISODIR}/systemrescuecd-${CURARCH}-current.iso"
30 MYDATE=$(date +%Y%m%d-%Hh%M)
31 DESTDIR=/home/sysresccdiso
32 mkdir -p ${DESTDIR}
33
34 if [ ! -f "${CURFILE}"  ]
35 then
36         echo "Cannot find \"${CURFILE}\". Failed"
37         exit 1
38 fi
39
40 umount /mnt/cdrom 2>/dev/null
41 if ! mount -o loop,ro ${CURFILE} /mnt/cdrom
42 then
43         echo "Cannot mount ${CURFILE}"
44         exit 1
45 fi
46
47 if [ ! -f /mnt/cdrom/image.squashfs ]
48 then
49         echo "Cannot find a valid file in the ISO"
50         exit 1
51 fi
52
53 [ -d ${TEMPDIR} ] && rm -rf ${TEMPDIR} 
54 mkdir -p ${TEMPDIR}
55 cp /mnt/cdrom/isolinux/rescuecd* ${REPOBIN}/kernels-x86/
56 cp /mnt/cdrom/image.squashfs ${TEMPDIR}/sysrcd.dat
57 ( cd ${TEMPDIR} ; md5sum sysrcd.dat > sysrcd.md5 ; chmod 644 sysrcd.* ) 
58 umount /mnt/cdrom
59
60 # ========= copy files from overlays ===========================================
61 rsync -ax ${REPOBIN}/overlay-iso-x86/ "${TEMPDIR}/"
62 rsync -ax ${REPOSRC}/overlay-iso-x86/isolinux/ "${TEMPDIR}/isolinux/"
63 rsync -ax ${REPOBIN}/kernels-x86/ ${TEMPDIR}/isolinux/ --exclude='*.igz'
64 cp ${REPOSRC}/overlay-squashfs-x86/root/version ${TEMPDIR}
65
66 # ========= integrate the version number in f1boot.msg =========================
67 TXTVERSION=$(cat ${REPOSRC}/overlay-squashfs-x86/root/version)
68 sed -i -e "s/VERSION/${TXTVERSION}${EXTRAVER}/" ${TEMPDIR}/isolinux/f1boot.msg
69
70 # ========= merge (rescuecd.igz+rescue64.igz+altker32.igz) --> rescuecd.igz ====
71 curdir="${TEMPDIR}/isolinux"
72 newramfs="${curdir}/initram-root"
73 newinitrfs="${curdir}/initram.igz"
74 modulesdir="${newramfs}/lib/modules"
75
76 # prepare root of new initramfs
77 [ -d ${newramfs} ] && rm -rf ${newramfs}
78 mkdir -p ${newramfs}
79 cp -a ${REPOBIN}/overlay-initramfs/* ${newramfs}/
80 mkdir -p ${modulesdir}
81
82 # extract the old ramdisks
83 for ker in rescuecd rescue64 altker32 altker64
84 do
85         oldimg="${REPOBIN}/kernels-x86/${ker}.igz"
86         newdir="${curdir}/${ker}-tmp"
87         echo "extracting ${oldimg}..."
88         mkdir -p "${newdir}"
89         ( cd "${newdir}" && cat ${oldimg} | gzip -d | cpio -id 2>/dev/null )
90 done
91
92 # copy {rescue64,altker32,altker64}/lib/modules to the new initramfs
93 for ker in rescuecd rescue64 altker32 altker64
94 do
95         cp -a ${curdir}/${ker}-tmp/lib/modules/* ${modulesdir}/
96 done
97
98 # copy custom busybox binary to the new initramfs
99 cp ${curdir}/rescuecd-tmp/bin/busybox ${newramfs}/bin/
100 ( cd ${newramfs}/bin/ ; ln busybox sh )
101
102 # update the init boot script in the initramfs
103 cp ${REPOSRC}/mainfiles/linuxrc* ${newramfs}/
104 cp ${REPOSRC}/mainfiles/linuxrc ${newramfs}/init
105
106 # strip and compress kernel modules which are in the sysrcd.dat to save space
107 find ${modulesdir} -name "*.ko" -exec strip --strip-unneeded '{}' \;
108 find ${modulesdir} -name "*.ko" -exec gzip '{}' \;
109
110 # build new initramfs
111 echo 'building the new initramfs...'
112 ( cd ${newramfs} && find . | cpio -H newc -o | gzip -9 > ${newinitrfs} )
113
114 # remove old igz-images and tmp-dirs
115 [ -d ${newramfs} ] && rm -rf ${newramfs} 
116 for ker in rescuecd rescue64 altker32 altker64
117 do
118         #[ -f "${curdir}/${ker}.igz" ] && rm -f "${curdir}/${ker}.igz"
119         [ -d "${curdir}/${ker}-tmp" ] && rm -rf "${curdir}/${ker}-tmp"
120 done
121
122 # ========= copy the new files to the pxe environment =========================
123 if [ -d /tftpboot ]
124 then
125         cp ${TEMPDIR}/sysrcd.dat /tftpboot/
126         cp ${TEMPDIR}/sysrcd.md5 /tftpboot/
127         cp ${TEMPDIR}/isolinux/* /tftpboot/
128 fi
129
130 # ========= prepare the ISO image =============================================
131 ISOFILE="${DESTDIR}/systemrescuecd-${CURARCH}-${VERSION}-${MYDATE}.iso"
132
133 if [ "${CURARCH}" = "x86" ] || [ "${CURARCH}" = "amd64" ]
134 then
135         mkisofs -J -l -V ${VOLNAME} -input-charset utf-8 -o ${ISOFILE} -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table ${TEMPDIR}
136 fi
137
138 if [ "${CURARCH}" = "sparc" ]
139 then
140         mkisofs -G /boot/isofs.b -J -V ${VOLNAME} -B ... -r -o ${ISOFILE} ${TEMPDIR}
141 fi
142
143 # ========= prepare the backup ==================================================
144 tar cfjp "${DESTDIR}/systemrescuecd-${CURARCH}-${VERSION}-${MYDATE}.tar.bz2" /worksrc/sysresccd-src /worksrc/sysresccd-bin --exclude='.git'
145