2 # Project page: http://www.sysresccd.org/
3 # (C) 2003-2008 Francois Dupoux
4 # This scipt is available under the GPL-2 license
6 ## HELP AND BASIC ARGUMENT PROCESSING
7 #####################################
10 ISODIR="/livemnt/boot"
11 ROOTDIR="/livemnt/squashfs"
14 USB_ISOLINUX="syslinux"
15 MKSQUASHFS="mksquashfs"
20 sysresccd-custom: SystemRescueCd customization script for x86
21 Syntax: ${PROG} [options] <command> ...
23 Please, read the manual for help about how to use this script.
24 http://www.sysresccd.org/Sysresccd-manual-en_How_to_personalize_SystemRescueCd
25 This script must be executed outside of the chroot environment.
27 Commands (execute in that order):
28 1) extract Extract files from the squashfs into your disk
29 2) squashfs Recreate the compressed loopback squashfs image
30 3) setkmap <keymap-code> Force a keymap to be loaded without prompt
31 4) isogen <cd_volume_name> Generate the final bootable ISO image
33 -h|--help Display this screen and exit
34 -u Use the USB "$USB_ISOLINUX" rather than the CD "$ISOLINUX"
35 -i ISODIR Set the mount directory for the stock SysRescCD iso ($ISODIR)
36 -r ROOTDIR Set the source directory for the stock SysRescCD root ($ROOTDIR)
37 -w WORKDIR Set the work directory for the custom CD (${WORKDIR})
38 -m MKSQUASHFS Set the squashfs compression program ($MKSQUASHFS)
40 Distributed under the GNU Public License version 2 - http://www.sysresccd.org
44 ## MISC FUNCTIONS: Many utilities functions
45 ###########################################
47 # show the error message ($1 = first line of the message)
51 echo "Please, read the manual for more help about this script"
52 echo "Web: http://www.sysresccd.org"
57 #####################################
63 echo "${PROG}: error: $1"
65 echo "${PROG}: aborting."
70 ## MISC FUNCTIONS: Many utilities functions
71 ###########################################
73 # $1 == MB required by the function
76 SIZE=`(\df -m -P ${WORKDIR}) | grep " ${WORKDIR}$" | tail -n 1 | awk '{print $4}'`
80 echo "there is enough estimated free space here ($SIZE MB) -> ok"
82 echo "${PROG}: not enough room in ${WORKDIR}"
83 help_readman "You only have $SIZE MB free, and the script needs at least $1 MB free"
88 ## MAIN FUNCTIONS: Check if squashfs extraction is possible
89 ########################################################
92 # check for free space
96 ## MAIN FUNCTIONS: Extract the squashfs to the hard disk
97 ########################################################
100 # ---- check the original contents
101 for curfile in ${ISODIR}/sysrcd.dat ${ISODIR}/sysrcd.md5 ${ISODIR}/${ISOLINUX}/rescuecd
103 if [ ! -f "${curfile}" ]
105 die "File ${curfile} was not found. All the original sysresccd files must be available in ${ISODIR}"
109 # ---- copy the original contents
110 mkdir -p ${WORKDIR}/customcd/isoroot/
111 rm -rf ${WORKDIR}/customcd/isoroot/*
113 # ---- copy critical files and directories
114 for curfile in version $ISOLINUX
116 cp -a ${ISODIR}/${curfile} ${WORKDIR}/customcd/isoroot/ || die "copy: cannot copy ${curfile} to ${WORKDIR}/customcd/isoroot/"
119 # ---- copy optional files and directories
120 for curfile in bootprog bootdisk ntpasswd
122 if ! cp -a ${ISODIR}/${curfile} ${WORKDIR}/customcd/isoroot/ 2>/dev/null
124 echo "cannot copy ${curfile} to ${WORKDIR}/customcd/isoroot/ (non critical error)"
125 rm -rf ${WORKDIR}/customcd/isoroot/${curfile}
130 # ---- extract files (/livemnt/squashfs is the mount point of sysrcd.dat)
131 mkdir -p ${WORKDIR}/customcd/files/
132 rm -rf ${WORKDIR}/customcd/files/*
133 cp -a ${ROOTDIR}/* ${WORKDIR}/customcd/files/ || die "cannot copy the files from the squashfs filesystem."
136 ## MAIN FUNCTIONS: Create the new squashfs
137 ########################################################
140 # check for free space
143 # prepare the directories
144 mkdir -p ${WORKDIR}/customcd/
145 mkdir -p ${WORKDIR}/customcd/files/
146 mkdir -p ${WORKDIR}/customcd/isoroot/
147 touch "${WORKDIR}/customcd/files/customized"
149 # check that the files have been extracted
150 if [ "$(ls -A ${WORKDIR}/customcd/files/ 2>/dev/null | wc -l)" -eq 0 ]
152 die "squashfs: ${WORKDIR}/customcd/files/ is empty, your must extract the files first."
155 # check that there are no remaining filesystems mounted
158 curpath="${WORKDIR}/customcd/files/${curfs}"
159 dircnt="$(ls -A ${curpath} 2>/dev/null | wc -l)"
160 if [ "${dircnt}" -gt 0 ]
162 die "squashfs: the directory ${curpath} must be empty"
166 rm -f ${WORKDIR}/customcd/isoroot/sysrcd.dat
167 cmd="${MKSQUASHFS} ${WORKDIR}/customcd/files/ ${WORKDIR}/customcd/isoroot/sysrcd.dat"
170 (cd ${WORKDIR}/customcd/isoroot/ ; md5sum sysrcd.dat > sysrcd.md5)
172 # Change permissions to allow the file to be sent by thttpd for PXE-boot
173 chmod 644 ${WORKDIR}/customcd/isoroot/sysrcd.{dat,md5}
176 ## MAIN FUNCTIONS: Force a keymap to be loaded without prompt
177 ########################################################
182 if [ -z "${KEYMAP}" ]
184 die "do_setkmap: you must specify the keymap you want to use (eg: \"${PROG} setkmap uk\")"
187 if [ ! -d "${WORKDIR}/customcd/isoroot/${ISOLINUX}" ]
189 die "do_setkmap: you have to run command copy before setkmap"
192 echo "Keymap to be loaded: ${KEYMAP}"
194 # Set keymap in ${ISOLINUX}.cfg
195 cp ${WORKDIR}/customcd/isoroot/${ISOLINUX}/${ISOLINUX}.cfg ${WORKDIR}/customcd/isoroot/${ISOLINUX}/${ISOLINUX}.bak
196 sed -i -r -e "s:setkmap=[a-z0-9]+ ::g ; s:append:append setkmap=${KEYMAP}:g" ${WORKDIR}/customcd/isoroot/${ISOLINUX}/${ISOLINUX}.cfg
199 ## MAIN FUNCTIONS: Create the new ISO image
200 ########################################################
204 curtime="$(date +%Y%m%d-%H%M)"
206 # check for free space
209 if [ -z "${ISO_VOLUME}" ]
211 die "do_isogen: you must specify the name of the volume you want to use for the iso image."
214 mkdir -p ${WORKDIR}/customcd/isofile/
215 rm -rf ${WORKDIR}/customcd/isofile/*.iso
217 if [ ! -d "${WORKDIR}/customcd/isoroot/${ISOLINUX}" ]
219 die "do_isogen: you must create a squashfs filesystem before you run isogen"
222 touch "${WORKDIR}/customcd/isoroot/customized"
224 echo "Volume name of the CDRom: ${ISO_VOLUME}"
226 cmd="mkisofs -J -l -o ${WORKDIR}/customcd/isofile/sysresccd-${curtime}.iso \
227 -b ${ISOLINUX}/isolinux.bin -c ${ISOLINUX}/boot.cat -input-charset utf-8 \
228 -no-emul-boot -boot-load-size 4 -boot-info-table \
229 -V \"${ISO_VOLUME}\" ${WORKDIR}/customcd/isoroot"
232 echo "${cmd} --> $res"
233 if [ "${res}" != '0' ]
238 md5sum ${WORKDIR}/customcd/isofile/sysresccd-${curtime}.iso > ${WORKDIR}/customcd/isofile/sysresccd-${curtime}.md5
240 echo "Final ISO image: ${WORKDIR}/customcd/isofile/sysresccd-${curtime}.iso"
243 ## MAIN SHELL FUNCTION
244 ########################################################
246 ###########################################
247 if [ $# -eq 0 ] # Script invoked with no command-line args?
253 while getopts ":ui:r:w:m:" Option
256 u ) ISOLINUX="$USB_ISOLINUX";;
257 i ) ISODIR="$OPTARG";;
258 r ) ROOTDIR="$OPTARG";;
259 w ) WORKDIR="$OPTARG";;
260 * ) usage; exit 1;; # Default, handles -h
263 shift $(($OPTIND - 1))
268 if [ "$(whoami)" != "root" ]
270 help_readman "${PROG}: This script requires root privileges to operate."
273 if [ ! -d "${WORKDIR}" ]
275 help_readman "${PROG}: You need to mount a partition with free space on ${WORKDIR}"
279 if grep -q " ${WORKDIR} " /proc/mounts
281 echo "${WORKDIR} is mounted -> ok"
283 help_readman "${PROG}: ${WORKDIR} is not mounted. Cannot continue."
289 do_extract_check "$@"
304 *) # Default, handles --help