3 ## HELP AND BASIC ARGUMENT PROCESSING
4 #####################################
8 ISODIR=/worksrc/isofiles
10 WORKDIR=/worksrc/catalyst/isotemp
11 DESTDIR=/home/sysresccdiso
12 REPOSRC=/worksrc/sysresccd-src
13 REPOBIN=/worksrc/sysresccd-bin
14 MYDATE=$(date +%Y%m%d-%Hh%M)
19 Usage: ${PROG} [options] <arch>
21 Rebuild the distribution iso by applying the SystemRescueCD overlays
22 and recent kernels to a previous vesion.
24 arch: x86 | amd64 | sparc
27 -h|--help Display this screen and exit
28 -i ISODIR Directory containing the iso file to rebuild ($ISODIR)
29 <isodir>/systemrescuecd-<arch>-current.iso
30 -w WORKDIR Set the work directory for the custom CD (${WORKDIR})
31 -r REPOSRC Location of git systemrescuecd repo ($REPOSRC)
32 -b REPOBIN ? ($REPOBIN)
33 -d DESTDIR Set the directory for saving the rebuild iso file ($DESTDIR)
34 -m MOUNTDIR Set the directory for mounting the current iso ($MOUNTDIR)
35 -e EXTRAVER Extra version information for f1boot.msg ($EXTRAVER)
37 Distributed under the GNU Public License version 2 - http://www.sysresccd.org
41 while getopts ":i:w:r:b:d:m:e:" Option
44 i ) ISODIR="$OPTARG";;
45 w ) WORKDIR="$OPTARG";;
46 r ) REPOSRC="$OPTARG";;
47 b ) REPOBIN="$OPTARG";;
48 d ) DESTDIR="$OPTARG";;
49 m ) MOUNTDIR="$OPTARG";;
50 e ) EXTRAVER="$OPTARG";;
51 * ) usage; exit 1;; # Default, handles -h
54 shift $(($OPTIND - 1))
57 if [ "$1" = "x86" ] || [ "$1" = "amd64" ] || [ "$1" = "sparc" ]
64 amd64) BASEARCH="x86";;
65 sparc) BASEARCH="sparc";;
68 VERSION=$(cat ${REPOSRC}/overlay-squashfs-${BASEARCH}/root/version)
69 VOLNAME="sysrcd-${VERSION}"
72 #####################################
78 echo "${PROG}: error: $1"
80 echo "${PROG}: aborting."
85 # ========= copy files from the temp iso image ================================
86 CURFILE="${ISODIR}/systemrescuecd-${ARCH}-current.iso"
90 [ -f "${CURFILE}" ] || die "Cannot find \"${CURFILE}\""
92 umount ${MOUNTDIR} 2>/dev/null || die "Cannot unmount \"${MOUNTDIR}\""
93 mount -o loop,ro ${CURFILE} ${MOUNTDIR} || die "Cannot mount \"${CURFILE}\""
95 [ -f ${MOUNTDIR}/image.squashfs ] || die "Cannot find a valid file in the ISO"
97 [ -d ${WORKDIR} ] && rm -rf ${WORKDIR}
99 cp ${MOUNTDIR}/isolinux/rescuecd* ${REPOBIN}/kernels-${ARCH}/
100 cp ${MOUNTDIR}/image.squashfs ${WORKDIR}/sysrcd.dat
101 ( cd ${WORKDIR} ; md5sum sysrcd.dat > sysrcd.md5 ; chmod 644 sysrcd.* )
104 # ========= copy files from overlays ===========================================
105 rsync -ax ${REPOBIN}/overlay-iso-${BASEARCH}/ "${WORKDIR}/"
106 rsync -ax ${REPOSRC}/overlay-iso-${BASEARCH}/isolinux/ "${WORKDIR}/isolinux/"
107 rsync -ax ${REPOBIN}/kernels-${ARCH}/ ${WORKDIR}/isolinux/ --exclude='*.igz'
108 cp ${REPOSRC}/overlay-squashfs-${BASEARCH}/root/version ${WORKDIR}
110 # ========= integrate the version number in f1boot.msg =========================
111 sed -i -e "s/VERSION/${VERSION}${EXTRAVER}/" ${WORKDIR}/isolinux/f1boot.msg
113 # ========= merge (rescuecd.igz+rescue64.igz+altker32.igz) --> rescuecd.igz ====
114 curdir="${WORKDIR}/isolinux"
115 newramfs="${curdir}/initram-root"
116 newinitrfs="${curdir}/initram.igz"
117 modulesdir="${newramfs}/lib/modules"
119 # prepare root of new initramfs
120 [ -d ${newramfs} ] && rm -rf ${newramfs}
122 cp -a ${REPOBIN}/overlay-initramfs/* ${newramfs}/
123 mkdir -p ${modulesdir}
125 # extract the old ramdisks
126 for ker in rescuecd rescue64 altker32 altker64
128 oldimg="${REPOBIN}/kernels-${ARCH}/${ker}.igz"
129 newdir="${curdir}/${ker}-tmp"
130 echo "extracting ${oldimg}..."
132 ( cd "${newdir}" && cat ${oldimg} | gzip -d | cpio -id 2>/dev/null )
135 # copy {rescue64,altker32,altker64}/lib/modules to the new initramfs
136 for ker in rescuecd rescue64 altker32 altker64
138 cp -a ${curdir}/${ker}-tmp/lib/modules/* ${modulesdir}/
141 # copy custom busybox binary to the new initramfs
142 cp ${curdir}/rescuecd-tmp/bin/busybox ${newramfs}/bin/
143 ( cd ${newramfs}/bin/ ; ln busybox sh )
145 # update the init boot script in the initramfs
146 cp ${REPOSRC}/mainfiles/linuxrc* ${newramfs}/
147 cp ${REPOSRC}/mainfiles/linuxrc ${newramfs}/init
149 # strip and compress kernel modules which are in the sysrcd.dat to save space
150 find ${modulesdir} -name "*.ko" -exec strip --strip-unneeded '{}' \;
151 find ${modulesdir} -name "*.ko" -exec gzip '{}' \;
153 # build new initramfs
154 echo 'building the new initramfs...'
155 ( cd ${newramfs} && find . | cpio -H newc -o | gzip -9 > ${newinitrfs} )
157 # remove old igz-images and tmp-dirs
158 [ -d ${newramfs} ] && rm -rf ${newramfs}
159 for ker in rescuecd rescue64 altker32 altker64
161 #[ -f "${curdir}/${ker}.igz" ] && rm -f "${curdir}/${ker}.igz"
162 [ -d "${curdir}/${ker}-tmp" ] && rm -rf "${curdir}/${ker}-tmp"
165 # ========= copy the new files to the pxe environment =========================
168 cp ${WORKDIR}/sysrcd.dat /tftpboot/
169 cp ${WORKDIR}/sysrcd.md5 /tftpboot/
170 cp ${WORKDIR}/isolinux/* /tftpboot/
173 # ========= prepare the ISO image =============================================
174 ISOFILE="${DESTDIR}/systemrescuecd-${ARCH}-${VERSION}-${MYDATE}.iso"
176 if [ "${ARCH}" = "x86" ] || [ "${ARCH}" = "amd64" ]
178 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 ${WORKDIR}
181 if [ "${ARCH}" = "sparc" ]
183 mkisofs -G /boot/isofs.b -J -V ${VOLNAME} -B ... -r -o ${ISOFILE} ${WORKDIR}
186 # ========= prepare the backup ==================================================
187 tar cfjp "${DESTDIR}/systemrescuecd-${ARCH}-${VERSION}-${MYDATE}.tar.bz2" ${REPOSRC} ${REPOBIN} --exclude='.git'