## HELP AND BASIC ARGUMENT PROCESSING
#####################################
-# minimal size required for sysresccd in mega-bytes
+PROG="${0}"
+ISODIR="/livemnt/boot"
+USBDIR="/mnt/usbstick"
+SYSLINUX="sylinux"
MINSIZEMB=300
+cdfiles=('sysrcd.dat' 'sysrcd.md5' 'version' 'isolinux/initram.igz'
+ 'isolinux/rescuecd' 'isolinux/rescue64' 'isolinux/f1boot.msg'
+ 'isolinux/isolinux.bin' 'isolinux/isolinux.cfg')
usage()
{
5) syslinux <partname> Make the device bootable
-h|--help Display this screen
+ -i ISODIR Set the mount directory for the stock SysRescCD iso ($ISODIR)
+ -u USBDIR Set the directory for mounting the USB stick ($USBDIR)
+ -m SYSLINUX Set the syslinux program ($SYSLINUX)
+ -s MINSIZEMB Minimal size required for SysRescCD in mega-bytes
dialog Dialog to make SystemRescueCD-USB-Sticks
Distributed under the GNU Public License version 2 - http://www.sysresccd.org
EOF
}
-cdfiles=('sysrcd.dat' 'sysrcd.md5' 'version' 'isolinux/initram.igz'
- 'isolinux/rescuecd' 'isolinux/rescue64' 'isolinux/f1boot.msg'
- 'isolinux/isolinux.bin' 'isolinux/isolinux.cfg')
-
## MISC FUNCTIONS: Many utilities functions
###########################################
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 ! cat /proc/mounts | awk '{print $2}' | grep -q -F '/memory'
-then
- help_readman "$0: This script must be executed from SystemRescueCd"
- exit 1
-fi
-
-PROG=${0}
-
## ERROR HANDLING
#####################################
check_sysresccd_files()
{
rootdir="$1"
- [ -z "${rootdir}" ] && rootdir="/livemnt/boot"
+ [ -z "${rootdir}" ] && rootdir="${ISODIR}"
for curfile in ${cdfiles[*]}
do
curcheck="${rootdir}/${curfile}"
partname="$1"
check_valid_partname "${partname}"
- # check the important files are available in /livemnt/boot
- check_sysresccd_files "/livemnt/boot"
+ # check the important files are available in ${ISODIR}
+ check_sysresccd_files "${ISODIR}"
check_sizeof_dev "${partname}"
- mkdir -p /mnt/usbstick 2>/dev/null
- if ! mount -t vfat ${partname} /mnt/usbstick
+ mkdir -p ${USBDIR} 2>/dev/null
+ if ! mount -t vfat ${partname} ${USBDIR}
then
- die "cannot mount ${partname} on /mnt/usbstick"
+ die "cannot mount ${partname} on ${USBDIR}"
fi
- echo "${partname} successfully mounted on /mnt/usbstick"
+ echo "${partname} successfully mounted on ${USBDIR}"
- check_disk_freespace "/mnt/usbstick"
+ check_disk_freespace "${USBDIR}"
- if cp -r --remove-destination /livemnt/boot/* /mnt/usbstick/ && sync
+ if cp -r --remove-destination ${ISODIR}/* ${USBDIR}/ && sync
then
echo "Files have been successfully copied to ${partname}"
else
echo "Cannot copy files to ${partname}"
fi
- for curfile in '/mnt/usbstick/isolinux/isolinux.cfg'
+ for curfile in '${USBDIR}/isolinux/isolinux.cfg'
do
if [ ! -f "${curfile}" ]
then
- umount /mnt/usbstick
+ umount ${USBDIR}
die "${curfile} not found, cannot continue"
fi
done
# check the important files have been copied
- check_sysresccd_files "/mnt/usbstick"
+ check_sysresccd_files "${USBDIR}"
# move isolinux files to syslinux files
- rm -rf /mnt/usbstick/syslinux
- if ! mv /mnt/usbstick/isolinux/isolinux.cfg /mnt/usbstick/isolinux/syslinux.cfg \
- || ! mv /mnt/usbstick/isolinux /mnt/usbstick/syslinux
+ rm -rf ${USBDIR}/syslinux
+ if ! mv ${USBDIR}/isolinux/isolinux.cfg ${USBDIR}/isolinux/syslinux.cfg \
+ || ! mv ${USBDIR}/isolinux ${USBDIR}/syslinux
then
- umount /mnt/usbstick
+ umount ${USBDIR}
die "cannot move isolinux to syslinux, failed"
fi
# remove the last lines which produces error messages 'bad keyword' with syslinux
- sed -i -e '/label disk[1-2]$/d' -e '/label floppy$/d' -e '/label nextboot$/d' -e '/localboot/d' /mnt/usbstick/syslinux/syslinux.cfg
+ sed -i -e '/label disk[1-2]$/d' -e '/label floppy$/d' -e '/label nextboot$/d' -e '/localboot/d' ${USBDIR}/syslinux/syslinux.cfg
# add scandelay option which allows the usb devices to be detected
- sed -i -e 's!initrd=initram.igz!initrd=initram.igz scandelay=5!g' /mnt/usbstick/syslinux/syslinux.cfg
+ sed -i -e 's!initrd=initram.igz!initrd=initram.igz scandelay=5!g' ${USBDIR}/syslinux/syslinux.cfg
- umount /mnt/usbstick
+ umount ${USBDIR}
}
do_syslinux()
partname="$1"
check_valid_partname "${partname}"
- if [ -z "$(which syslinux)" ]
+ if [ -z "$(which ${SYSLINUX})" ]
then
- die "syslinux not found on your system, please install syslinux first."
+ die "${SYSLINUX} not found on your system, please install syslinux first."
fi
- if syslinux ${partname} && sync
+ if ${SYSLINUX} ${partname} && sync
then
- echo "syslinux has successfully prepared ${partname}"
+ echo "${SYSLINUX} has successfully prepared ${partname}"
else
- echo "syslinux failed to prepare ${partname}"
+ echo "${SYSLINUX} failed to prepare ${partname}"
fi
}
## MAIN SHELL FUNCTION
########################################################
+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
+ 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 "$0: This script requires root privileges to operate."
+fi
+
+if ! cat /proc/mounts | awk '{print $2}' | grep -q -F '/memory'
+then
+ help_readman "$0: This script must be executed from SystemRescueCd"
+ exit 1
+fi
+
case "${COMMAND}" in
listdev)
do_listdev