## HELP AND BASIC ARGUMENT PROCESSING
#####################################
+PROG="${0}"
+ISODIR="/livemnt/boot"
+ROOTDIR="/livemnt/squashfs"
+WORKDIR="/mnt/custom"
+ISOLINUX="isolinux"
+USB_ISOLINUX="syslinux"
+MKSQUASHFS="mksquashfs"
+
usage()
{
cat <<EOF
sysresccd-custom: SystemRescueCd customization script for x86
-Syntax: sysresccd-custom <command> ...
+Syntax: ${PROG} [options] <command> ...
Please, read the manual for help about how to use this script.
http://www.sysresccd.org/Sysresccd-manual-en_How_to_personalize_SystemRescueCd
3) setkmap <keymap-code> Force a keymap to be loaded without prompt
4) isogen <cd_volume_name> Generate the final bootable ISO image
- -h|--help Display this screen
+ -h|--help Display this screen and exit
+ -u Use the USB "$USB_ISOLINUX" rather than the CD "$ISOLINUX"
+ -i ISODIR Set the mount directory for the stock SysRescCD iso ($ISODIR)
+ -r ROOTDIR Set the source directory for the stock SysRescCD root ($ROOTDIR)
+ -w WORKDIR Set the work directory for the custom CD (${WORKDIR})
+ -m MKSQUASHFS Set the squashfs compression program ($MKSQUASHFS)
Distributed under the GNU Public License version 2 - http://www.sysresccd.org
EOF
exit 1
}
-## Main
-###########################################
-
-if [ "$1" = "-h" ] || [ "$1" = "--help" ]
-then
- usage
- exit 1
-fi
-
-if [ "$(whoami)" != "root" ]
-then
- help_readman "$0: This script requires root privileges to operate."
-fi
-
-if [ ! -d "/mnt/custom" ]
-then
- help_readman "$0: You need to mount a partition with free space on /mnt/custom"
- exit 1
-fi
-
-if grep -q " /mnt/custom " /proc/mounts
-then
- echo "/mnt/custom is mounted -> ok"
-else
- help_readman "$0: /mnt/custom is not mounted. Cannot continue."
- exit 1
-fi
-
-PROG=${0}
-
## ERROR HANDLING
#####################################
# $1 == MB required by the function
check_freespace()
{
- SIZE=`(\df -m -P /mnt/custom) | grep " /mnt/custom$" | tail -n 1 | awk '{print $4}'`
+ SIZE=`(\df -m -P ${WORKDIR}) | grep " ${WORKDIR}$" | tail -n 1 | awk '{print $4}'`
if [ $SIZE -gt $1 ]
then
echo "there is enough estimated free space here ($SIZE MB) -> ok"
else
- echo "$PROG: not enough room in /mnt/custom"
+ echo "${PROG}: not enough room in ${WORKDIR}"
help_readman "You only have $SIZE MB free, and the script needs at least $1 MB free"
exit 1
fi
}
-## MAIN FUNCTIONS: Extracting the squashfs to the hard disk
+## MAIN FUNCTIONS: Check if squashfs extraction is possible
########################################################
do_extract_check()
{
check_freespace 900
}
+## MAIN FUNCTIONS: Extract the squashfs to the hard disk
+########################################################
do_extract()
{
# ---- check the original contents
- for curfile in /livemnt/boot/sysrcd.dat /livemnt/boot/sysrcd.md5 /livemnt/boot/isolinux/rescuecd
+ for curfile in ${ISODIR}/sysrcd.dat ${ISODIR}/sysrcd.md5 ${ISODIR}/${ISOLINUX}/rescuecd
do
if [ ! -f "${curfile}" ]
then
- die "File ${curfile} was not found. All the original sysresccd files must be available in /livemnt/boot"
+ die "File ${curfile} was not found. All the original sysresccd files must be available in ${ISODIR}"
fi
done
# ---- copy the original contents
- mkdir -p /mnt/custom/customcd/isoroot/
- rm -rf /mnt/custom/customcd/isoroot/*
+ mkdir -p ${WORKDIR}/customcd/isoroot/
+ rm -rf ${WORKDIR}/customcd/isoroot/*
# ---- copy critical files and directories
- for curfile in version isolinux
+ for curfile in version $ISOLINUX
do
- cp -a /livemnt/boot/${curfile} /mnt/custom/customcd/isoroot/ || die "copy: cannot copy ${curfile} to /mnt/custom/customcd/isoroot/"
+ cp -a ${ISODIR}/${curfile} ${WORKDIR}/customcd/isoroot/ || die "copy: cannot copy ${curfile} to ${WORKDIR}/customcd/isoroot/"
done
- # ---- copy optionnal files and directories
+ # ---- copy optional files and directories
for curfile in bootprog bootdisk ntpasswd
do
- if ! cp -a /livemnt/boot/${curfile} /mnt/custom/customcd/isoroot/ 2>/dev/null
+ if ! cp -a ${ISODIR}/${curfile} ${WORKDIR}/customcd/isoroot/ 2>/dev/null
then
- echo "cannot copy ${curfile} to /mnt/custom/customcd/isoroot/ (non critical error)"
- rm -rf /mnt/custom/customcd/isoroot/${curfile}
+ echo "cannot copy ${curfile} to ${WORKDIR}/customcd/isoroot/ (non critical error)"
+ rm -rf ${WORKDIR}/customcd/isoroot/${curfile}
break
fi
done
# ---- extract files (/livemnt/squashfs is the mount point of sysrcd.dat)
- mkdir -p /mnt/custom/customcd/files/
- rm -rf /mnt/custom/customcd/files/*
- cp -a /livemnt/squashfs/* /mnt/custom/customcd/files/ || die "cannot copy the files from the squashfs filesystem."
+ mkdir -p ${WORKDIR}/customcd/files/
+ rm -rf ${WORKDIR}/customcd/files/*
+ cp -a ${ROOTDIR}/* ${WORKDIR}/customcd/files/ || die "cannot copy the files from the squashfs filesystem."
}
+## MAIN FUNCTIONS: Create the new squashfs
+########################################################
do_squashfs()
{
# check for free space
check_freespace 350
# prepare the directories
- mkdir -p /mnt/custom/customcd/
- mkdir -p /mnt/custom/customcd/files/
- mkdir -p /mnt/custom/customcd/isoroot/
- touch "/mnt/custom/customcd/files/customized"
+ mkdir -p ${WORKDIR}/customcd/
+ mkdir -p ${WORKDIR}/customcd/files/
+ mkdir -p ${WORKDIR}/customcd/isoroot/
+ touch "${WORKDIR}/customcd/files/customized"
# check that the files have been extracted
- if [ "$(ls -A /mnt/custom/customcd/files/ 2>/dev/null | wc -l)" -eq 0 ]
+ if [ "$(ls -A ${WORKDIR}/customcd/files/ 2>/dev/null | wc -l)" -eq 0 ]
then
- die "squashfs: /mnt/custom/customcd/files/ is empty, your must extract the files first."
+ die "squashfs: ${WORKDIR}/customcd/files/ is empty, your must extract the files first."
fi
# check that there are no remaining filesystems mounted
for curfs in proc
do
- curpath="/mnt/custom/customcd/files/${curfs}"
+ curpath="${WORKDIR}/customcd/files/${curfs}"
dircnt="$(ls -A ${curpath} 2>/dev/null | wc -l)"
if [ "${dircnt}" -gt 0 ]
then
fi
done
- rm -f /mnt/custom/customcd/isoroot/sysrcd.dat
- cmd="mksquashfs /mnt/custom/customcd/files/ /mnt/custom/customcd/isoroot/sysrcd.dat"
+ rm -f ${WORKDIR}/customcd/isoroot/sysrcd.dat
+ cmd="${MKSQUASHFS} ${WORKDIR}/customcd/files/ ${WORKDIR}/customcd/isoroot/sysrcd.dat"
echo "${cmd}"
${cmd} || die
- (cd /mnt/custom/customcd/isoroot/ ; md5sum sysrcd.dat > sysrcd.md5)
+ (cd ${WORKDIR}/customcd/isoroot/ ; md5sum sysrcd.dat > sysrcd.md5)
# Change permissions to allow the file to be sent by thttpd for PXE-boot
- chmod 666 /mnt/custom/customcd/isoroot/sysrcd.{dat,md5}
+ chmod 644 ${WORKDIR}/customcd/isoroot/sysrcd.{dat,md5}
}
## MAIN FUNCTIONS: Force a keymap to be loaded without prompt
if [ -z "${KEYMAP}" ]
then
- die "do_setkmap: you must specify the keymap you want to use (eg: \"$0 setkmap uk\")"
+ die "do_setkmap: you must specify the keymap you want to use (eg: \"${PROG} setkmap uk\")"
fi
- if [ ! -d "/mnt/custom/customcd/isoroot/isolinux" ]
+ if [ ! -d "${WORKDIR}/customcd/isoroot/${ISOLINUX}" ]
then
die "do_setkmap: you have to run command copy before setkmap"
fi
echo "Keymap to be loaded: ${KEYMAP}"
- # Set keymap in isolinux.cfg
- cp /mnt/custom/customcd/isoroot/isolinux/isolinux.cfg /mnt/custom/customcd/isoroot/isolinux/isolinux.bak
- sed -i -r -e "s:setkmap=[a-z0-9]+ ::g ; s:append:append setkmap=${KEYMAP}:g" /mnt/custom/customcd/isoroot/isolinux/isolinux.cfg
-}
+ # Set keymap in ${ISOLINUX}.cfg
+ cp ${WORKDIR}/customcd/isoroot/${ISOLINUX}/${ISOLINUX}.cfg ${WORKDIR}/customcd/isoroot/${ISOLINUX}/${ISOLINUX}.bak
+ sed -i -r -e "s:setkmap=[a-z0-9]+ ::g ; s:append:append setkmap=${KEYMAP}:g" ${WORKDIR}/customcd/isoroot/${ISOLINUX}/${ISOLINUX}.cfg
+}
## MAIN FUNCTIONS: Create the new ISO image
########################################################
die "do_isogen: you must specify the name of the volume you want to use for the iso image."
fi
- mkdir -p /mnt/custom/customcd/isofile/
- rm -rf /mnt/custom/customcd/isofile/*.iso
+ mkdir -p ${WORKDIR}/customcd/isofile/
+ rm -rf ${WORKDIR}/customcd/isofile/*.iso
- if [ ! -d "/mnt/custom/customcd/isoroot/isolinux" ]
+ if [ ! -d "${WORKDIR}/customcd/isoroot/${ISOLINUX}" ]
then
die "do_isogen: you must create a squashfs filesystem before you run isogen"
fi
- touch "/mnt/custom/customcd/isoroot/customized"
+ touch "${WORKDIR}/customcd/isoroot/customized"
echo "Volume name of the CDRom: ${ISO_VOLUME}"
- cmd="mkisofs -J -l -o /mnt/custom/customcd/isofile/sysresccd-${curtime}.iso \
- -b isolinux/isolinux.bin -c isolinux/boot.cat -input-charset utf-8 \
+ cmd="mkisofs -J -l -o ${WORKDIR}/customcd/isofile/sysresccd-${curtime}.iso \
+ -b ${ISOLINUX}/isolinux.bin -c ${ISOLINUX}/boot.cat -input-charset utf-8 \
-no-emul-boot -boot-load-size 4 -boot-info-table \
- -V \"${ISO_VOLUME}\" /mnt/custom/customcd/isoroot"
+ -V \"${ISO_VOLUME}\" ${WORKDIR}/customcd/isoroot"
${cmd}
res="$?"
echo "${cmd} --> $res"
die "mkisofs failed"
fi
- md5sum /mnt/custom/customcd/isofile/sysresccd-${curtime}.iso > /mnt/custom/customcd/isofile/sysresccd-${curtime}.md5
+ md5sum ${WORKDIR}/customcd/isofile/sysresccd-${curtime}.iso > ${WORKDIR}/customcd/isofile/sysresccd-${curtime}.md5
- echo "Final ISO image: /mnt/custom/customcd/isofile/sysresccd-${curtime}.iso"
+ echo "Final ISO image: ${WORKDIR}/customcd/isofile/sysresccd-${curtime}.iso"
}
## MAIN SHELL FUNCTION
########################################################
+## Main
+###########################################
+if [ $# -eq 0 ] # Script invoked with no command-line args?
+then
+ usage
+ exit 1
+fi
+
+while getopts ":ui:r:w:m:" Option
+do
+ case $Option in
+ u ) ISOLINUX="$USB_ISOLINUX";;
+ i ) ISODIR="$OPTARG";;
+ r ) ROOTDIR="$OPTARG";;
+ w ) WORKDIR="$OPTARG";;
+ * ) usage; exit 1;; # Default, handles -h
+ esac
+done
+shift $(($OPTIND - 1))
COMMAND="${1}"
shift
+
+if [ "$(whoami)" != "root" ]
+then
+ help_readman "${PROG}: This script requires root privileges to operate."
+fi
+
+if [ ! -d "${WORKDIR}" ]
+then
+ help_readman "${PROG}: You need to mount a partition with free space on ${WORKDIR}"
+ exit 1
+fi
+
+if grep -q " ${WORKDIR} " /proc/mounts
+then
+ echo "${WORKDIR} is mounted -> ok"
+else
+ help_readman "${PROG}: ${WORKDIR} is not mounted. Cannot continue."
+ exit 1
+fi
+
case "${COMMAND}" in
extract)
do_extract_check "$@"
isogen)
do_isogen "$@"
;;
- *)
+ *) # Default, handles --help
usage
exit 1
;;