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