Add more flexibility to portage-overlay/.../sysresccd-custom
authorW. Trevor King <wking@drexel.edu>
Mon, 22 Mar 2010 21:29:20 +0000 (17:29 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 22 Mar 2010 22:28:50 +0000 (18:28 -0400)
  * Command-line options: ISODIR, ROOTDIR, WORKDIR, ...
  * chmod 644 sysrcd.* (rather than the previous 644).
    Global write access seemed unwise.

portage-overlay/sys-apps/sysresccd-scripts/Manifest
portage-overlay/sys-apps/sysresccd-scripts/files/sysresccd-custom

index cc4e1b57d094e73bff671142892e18abc4c3bf90..577c29250ac6f999cc8a97fbc59fdfc6689e1f8f 100644 (file)
@@ -4,7 +4,7 @@ AUX mountsys 15271 RMD160 8d3138fc2d63edfd99d000db64247d71c2282f6a SHA1 e51188d2
 AUX sysreport 5282 RMD160 0f2adae1d510c433eb5c69e26c77be210b3f8a13 SHA1 242f837d34d09a05bf5cff585a020c1f666eab20 SHA256 277aad5c858005ce25c6636f61db4f1693a662f89f6a8b5103117d16d71aa595
 AUX sysresccd-backstore 5402 RMD160 af8e40dfc4015d3484ebbf4c628be5cf8e866f4f SHA1 a188e01a1cdec73d21f336603a877fd0b73de738 SHA256 4382e98a63627263e4fab6ca1a5a86da821f7005b4f71b2f14cbdaf218335031
 AUX sysresccd-cleansys 3066 RMD160 ed0f5745bcc7686c9404f09b588a101de3ff0e47 SHA1 9fd2f1c219d981f5bbe6b951d085a27a1434aab8 SHA256 799ea4a5f9c3d08d31602107e7d00ea4df64d55e6aad49d38c36450dfe8f7b34
-AUX sysresccd-custom 7369 RMD160 24e4564a06b8a24bd065d194783cb0816adde9ea SHA1 6767858f29670df7ed3f2b5c60379ad4dc67fba1 SHA256 7446324529c490de88b2d1ea3607168b6ae91eb1f5dc40ad8dc72e752ab579b2
+AUX sysresccd-custom 8463 RMD160 34edac90b41f4f7c45f9b4c662008636d17dd11a SHA1 324390faf595ccecc9348f2747e08322721dbb16 SHA256 90a0854d917a0e79e9acc36ea7d57678dd31c650d42ce1bd7606763f3bbe87b6
 AUX sysresccd-pkgstats 2401 RMD160 8491162fefe3a0029773d493090732816b651722 SHA1 7ef5b0dcc07b151376eb82c5d6f94892a7a9010d SHA256 e9225a832fc33d85d4790c57784392f12754998de2455efa6add25650113a3a0
 AUX sysresccd-usbstick 11756 RMD160 a3dcbbfa2973ea92c6ffb94079b2e75231d8a65d SHA1 acb6c980cc57adf71fd32754f8a41003da92c50c SHA256 002137b9069267545a3804ee921e8686fb1429835ad52ee59d85c66067a100ac
 EBUILD sysresccd-scripts-1.5.0.ebuild 696 RMD160 35e443b4790bd55cb562d33a5acb4e3be1ec00fe SHA1 8fe54c95f9eb35c3f1a841bc23d851a87e02887f SHA256 50424009b7176e01b0feb9a2565b02a59022ce390fee9c7252b4b51930b0bf66
index 63d06dc333bec6203d4a602c128fbe6b393bc6f7..79957114b81722df13ffa2d1a759779eda26bef9 100755 (executable)
@@ -6,11 +6,19 @@
 ## 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
@@ -22,7 +30,12 @@ Commands (execute in that order):
  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
@@ -40,36 +53,6 @@ help_readman()
        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
 #####################################
 
@@ -90,19 +73,19 @@ die()
 # $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()
 {
@@ -110,65 +93,69 @@ 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
@@ -176,14 +163,14 @@ do_squashfs()
                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
@@ -194,20 +181,20 @@ do_setkmap()
 
        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
 ########################################################
@@ -224,22 +211,22 @@ do_isogen()
                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"
@@ -248,16 +235,55 @@ do_isogen()
                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 "$@"
@@ -275,7 +301,7 @@ case "${COMMAND}" in
        isogen)
                do_isogen "$@"
                ;;
-       *)
+       *)  # Default, handles --help
                usage 
                exit 1
                ;;