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 #####################################
12 sysresccd-custom: SystemRescueCd customization script for x86
13 Syntax: sysresccd-custom <command> ...
15 Please, read the manual for help about how to use this script.
16 http://www.sysresccd.org/Sysresccd-manual-en_How_to_personalize_SystemRescueCd
17 This script must be executed outside of the chroot environment.
19 Commands (execute in that order):
20 1) extract Extract files from the squashfs into your disk
21 2) squashfs Recreate the compressed loopback squashfs image
22 3) setkmap <keymap-code> Force a keymap to be loaded without prompt
23 4) isogen <cd_volume_name> Generate the final bootable ISO image
25 -h|--help Display this screen
27 Distributed under the GNU Public License version 2 - http://www.sysresccd.org
31 ## MISC FUNCTIONS: Many utilities functions
32 ###########################################
34 # show the error message ($1 = first line of the message)
38 echo "Please, read the manual for more help about this script"
39 echo "Web: http://www.sysresccd.org"
44 ###########################################
46 if [ "$1" = "-h" ] || [ "$1" = "--help" ]
52 if [ "$(whoami)" != "root" ]
54 help_readman "$0: This script requires root privileges to operate."
57 if [ ! -d "/mnt/custom" ]
59 help_readman "$0: You need to mount a partition with free space on /mnt/custom"
63 if grep -q " /mnt/custom " /proc/mounts
65 echo "/mnt/custom is mounted -> ok"
67 help_readman "$0: /mnt/custom is not mounted. Cannot continue."
74 #####################################
80 echo "${PROG}: error: $1"
82 echo "${PROG}: aborting."
87 ## MISC FUNCTIONS: Many utilities functions
88 ###########################################
90 # $1 == MB required by the function
93 SIZE=`(\df -m -P /mnt/custom) | grep " /mnt/custom$" | tail -n 1 | awk '{print $4}'`
97 echo "there is enough estimated free space here ($SIZE MB) -> ok"
99 echo "$PROG: not enough room in /mnt/custom"
100 help_readman "You only have $SIZE MB free, and the script needs at least $1 MB free"
105 ## MAIN FUNCTIONS: Extracting the squashfs to the hard disk
106 ########################################################
109 # check for free space
115 # ---- check the original contents
116 for curfile in /livemnt/boot/sysrcd.dat /livemnt/boot/sysrcd.md5 /livemnt/boot/isolinux/rescuecd
118 if [ ! -f "${curfile}" ]
120 die "File ${curfile} was not found. All the original sysresccd files must be available in /livemnt/boot"
124 # ---- copy the original contents
125 mkdir -p /mnt/custom/customcd/isoroot/
126 rm -rf /mnt/custom/customcd/isoroot/*
128 # ---- copy critical files and directories
129 for curfile in version isolinux
131 cp -a /livemnt/boot/${curfile} /mnt/custom/customcd/isoroot/ || die "copy: cannot copy ${curfile} to /mnt/custom/customcd/isoroot/"
134 # ---- copy optionnal files and directories
135 for curfile in bootprog bootdisk ntpasswd
137 if ! cp -a /livemnt/boot/${curfile} /mnt/custom/customcd/isoroot/ 2>/dev/null
139 echo "cannot copy ${curfile} to /mnt/custom/customcd/isoroot/ (non critical error)"
140 rm -rf /mnt/custom/customcd/isoroot/${curfile}
145 # ---- extract files (/livemnt/squashfs is the mount point of sysrcd.dat)
146 mkdir -p /mnt/custom/customcd/files/
147 rm -rf /mnt/custom/customcd/files/*
148 cp -a /livemnt/squashfs/* /mnt/custom/customcd/files/ || die "cannot copy the files from the squashfs filesystem."
153 # check for free space
156 # prepare the directories
157 mkdir -p /mnt/custom/customcd/
158 mkdir -p /mnt/custom/customcd/files/
159 mkdir -p /mnt/custom/customcd/isoroot/
160 touch "/mnt/custom/customcd/files/customized"
162 # check that the files have been extracted
163 if [ "$(ls -A /mnt/custom/customcd/files/ 2>/dev/null | wc -l)" -eq 0 ]
165 die "squashfs: /mnt/custom/customcd/files/ is empty, your must extract the files first."
168 # check that there are no remaining filesystems mounted
171 curpath="/mnt/custom/customcd/files/${curfs}"
172 dircnt="$(ls -A ${curpath} 2>/dev/null | wc -l)"
173 if [ "${dircnt}" -gt 0 ]
175 die "squashfs: the directory ${curpath} must be empty"
179 rm -f /mnt/custom/customcd/isoroot/sysrcd.dat
180 cmd="mksquashfs /mnt/custom/customcd/files/ /mnt/custom/customcd/isoroot/sysrcd.dat"
183 (cd /mnt/custom/customcd/isoroot/ ; md5sum sysrcd.dat > sysrcd.md5)
185 # Change permissions to allow the file to be sent by thttpd for PXE-boot
186 chmod 666 /mnt/custom/customcd/isoroot/sysrcd.{dat,md5}
189 ## MAIN FUNCTIONS: Force a keymap to be loaded without prompt
190 ########################################################
195 if [ -z "${KEYMAP}" ]
197 die "do_setkmap: you must specify the keymap you want to use (eg: \"$0 setkmap uk\")"
200 if [ ! -d "/mnt/custom/customcd/isoroot/isolinux" ]
202 die "do_setkmap: you have to run command copy before setkmap"
205 echo "Keymap to be loaded: ${KEYMAP}"
207 # Set keymap in isolinux.cfg
208 cp /mnt/custom/customcd/isoroot/isolinux/isolinux.cfg /mnt/custom/customcd/isoroot/isolinux/isolinux.bak
209 sed -i -r -e "s:setkmap=[a-z0-9]+ ::g ; s:append:append setkmap=${KEYMAP}:g" /mnt/custom/customcd/isoroot/isolinux/isolinux.cfg
212 ## MAIN FUNCTIONS: Create the new ISO image
213 ########################################################
217 curtime="$(date +%Y%m%d-%H%M)"
219 # check for free space
222 if [ -z "${ISO_VOLUME}" ]
224 die "do_isogen: you must specify the name of the volume you want to use for the iso image."
227 mkdir -p /mnt/custom/customcd/isofile/
228 rm -rf /mnt/custom/customcd/isofile/*.iso
230 if [ ! -d "/mnt/custom/customcd/isoroot/isolinux" ]
232 die "do_isogen: you must create a squashfs filesystem before you run isogen"
235 touch "/mnt/custom/customcd/isoroot/customized"
237 echo "Volume name of the CDRom: ${ISO_VOLUME}"
239 cmd="mkisofs -J -l -o /mnt/custom/customcd/isofile/sysresccd-${curtime}.iso \
240 -b isolinux/isolinux.bin -c isolinux/boot.cat -input-charset utf-8 \
241 -no-emul-boot -boot-load-size 4 -boot-info-table \
242 -V \"${ISO_VOLUME}\" /mnt/custom/customcd/isoroot"
245 echo "${cmd} --> $res"
246 if [ "${res}" != '0' ]
251 md5sum /mnt/custom/customcd/isofile/sysresccd-${curtime}.iso > /mnt/custom/customcd/isofile/sysresccd-${curtime}.md5
253 echo "Final ISO image: /mnt/custom/customcd/isofile/sysresccd-${curtime}.iso"
256 ## MAIN SHELL FUNCTION
257 ########################################################
263 do_extract_check "$@"