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 -r 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))
56 if [ "$1" = "x86" ] || [ "$1" = "amd64" ] || [ "$1" = "sparc" ]
60 usage # handles --help
63 VERSION=$(cat ${REPOSRC}/overlay-squashfs-${ARCH}/root/version)
64 VOLNAME="sysrcd-${VERSION}"
67 #####################################
73 echo "${PROG}: error: $1"
75 echo "${PROG}: aborting."
80 # ========= copy files from the temp iso image ================================
81 CURFILE="${ISODIR}/systemrescuecd-${ARCH}-current.iso"
85 [ -f "${CURFILE}" ] || die "Cannot find \"${CURFILE}\""
87 umount ${MOUNTDIR} 2>/dev/null || die "Cannot unmount \"${MOUNTDIR}\""
88 mount -o loop,ro ${CURFILE} ${MOUNTDIR} || die "Cannot mount \"${CURFILE}\""
90 [ -f ${MOUNTDIR}/image.squashfs ] || die "Cannot find a valid file in the ISO"
92 [ -d ${WORKDIR} ] && rm -rf ${WORKDIR}
94 cp ${MOUNTDIR}/isolinux/rescuecd* ${REPOBIN}/kernels-${ARCH}/
95 cp ${MOUNTDIR}/image.squashfs ${WORKDIR}/sysrcd.dat
96 ( cd ${WORKDIR} ; md5sum sysrcd.dat > sysrcd.md5 ; chmod 644 sysrcd.* )
99 # ========= copy files from overlays ===========================================
100 rsync -ax ${REPOBIN}/overlay-iso-${ARCH}/ "${WORKDIR}/"
101 rsync -ax ${REPOSRC}/overlay-iso-${ARCH}/isolinux/ "${WORKDIR}/isolinux/"
102 rsync -ax ${REPOBIN}/kernels-${ARCH}/ ${WORKDIR}/isolinux/ --exclude='*.igz'
103 cp ${REPOSRC}/overlay-squashfs-${ARCH}/root/version ${WORKDIR}
105 # ========= integrate the version number in f1boot.msg =========================
106 sed -i -e "s/VERSION/${VERSION}${EXTRAVER}/" ${WORKDIR}/isolinux/f1boot.msg
108 # ========= merge (rescuecd.igz+rescue64.igz+altker32.igz) --> rescuecd.igz ====
109 curdir="${WORKDIR}/isolinux"
110 newramfs="${curdir}/initram-root"
111 newinitrfs="${curdir}/initram.igz"
112 modulesdir="${newramfs}/lib/modules"
114 # prepare root of new initramfs
115 [ -d ${newramfs} ] && rm -rf ${newramfs}
117 cp -a ${REPOBIN}/overlay-initramfs/* ${newramfs}/
118 mkdir -p ${modulesdir}
120 # extract the old ramdisks
121 for ker in rescuecd rescue64 altker32 altker64
123 oldimg="${REPOBIN}/kernels-${ARCH}/${ker}.igz"
124 newdir="${curdir}/${ker}-tmp"
125 echo "extracting ${oldimg}..."
127 ( cd "${newdir}" && cat ${oldimg} | gzip -d | cpio -id 2>/dev/null )
130 # copy {rescue64,altker32,altker64}/lib/modules to the new initramfs
131 for ker in rescuecd rescue64 altker32 altker64
133 cp -a ${curdir}/${ker}-tmp/lib/modules/* ${modulesdir}/
136 # copy custom busybox binary to the new initramfs
137 cp ${curdir}/rescuecd-tmp/bin/busybox ${newramfs}/bin/
138 ( cd ${newramfs}/bin/ ; ln busybox sh )
140 # update the init boot script in the initramfs
141 cp ${REPOSRC}/mainfiles/linuxrc* ${newramfs}/
142 cp ${REPOSRC}/mainfiles/linuxrc ${newramfs}/init
144 # strip and compress kernel modules which are in the sysrcd.dat to save space
145 find ${modulesdir} -name "*.ko" -exec strip --strip-unneeded '{}' \;
146 find ${modulesdir} -name "*.ko" -exec gzip '{}' \;
148 # build new initramfs
149 echo 'building the new initramfs...'
150 ( cd ${newramfs} && find . | cpio -H newc -o | gzip -9 > ${newinitrfs} )
152 # remove old igz-images and tmp-dirs
153 [ -d ${newramfs} ] && rm -rf ${newramfs}
154 for ker in rescuecd rescue64 altker32 altker64
156 #[ -f "${curdir}/${ker}.igz" ] && rm -f "${curdir}/${ker}.igz"
157 [ -d "${curdir}/${ker}-tmp" ] && rm -rf "${curdir}/${ker}-tmp"
160 # ========= copy the new files to the pxe environment =========================
163 cp ${WORKDIR}/sysrcd.dat /tftpboot/
164 cp ${WORKDIR}/sysrcd.md5 /tftpboot/
165 cp ${WORKDIR}/isolinux/* /tftpboot/
168 # ========= prepare the ISO image =============================================
169 ISOFILE="${DESTDIR}/systemrescuecd-${ARCH}-${VERSION}-${MYDATE}.iso"
171 if [ "${ARCH}" = "x86" ] || [ "${ARCH}" = "amd64" ]
173 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}
176 if [ "${ARCH}" = "sparc" ]
178 mkisofs -G /boot/isofs.b -J -V ${VOLNAME} -B ... -r -o ${ISOFILE} ${WORKDIR}
181 # ========= prepare the backup ==================================================
182 tar cfjp "${DESTDIR}/systemrescuecd-${ARCH}-${VERSION}-${MYDATE}.tar.bz2" ${REPOSRC} ${REPOBIN} --exclude='.git'