MultiCD - How Plugins Work

How It Works

Last updated: April 25, 2012

Each plugin is a .sh file in the plugins folder. I'll take feather.sh, the plugin for Feather Linux, as an example. Feather hasn't been updated in the last couple of years, but it's simple enough to make a good plugin sample.

#!/bin/sh
set -e
. "${MCDDIR}"/functions.sh
#Feather Linux plugin for multicd.sh
#version 20140424
#Copyright (c) 2014 Isaac Schemm
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.

This section contains a "set -e" command that tells the script to quit on errors, the name and version (usually a last-modified date) of the plugin, and the MIT license. It also has a command . ${MCDDIR}/functions.sh, which loads functions like mcdmount and umcdmount from the functions.sh file packaged with multicd.sh. (The variable ${MCDDIR} is set by multicd.sh - it's the folder multicd is in.)

if [ $1 = links ];then
	echo "feather-*.iso feather.iso none"

multicd.sh calls this section before it starts building the ISO. There's a long, confusing function in functions.sh that takes the output of these echo commands and uses them to create symlinks to the ISOs you put in the folder, so the plugins can find them later using a standard filename pattern. This line will lead to any ISO named "feather-[something].iso" getting a symlink to it created named "feather.iso".
When multicd.sh exits, it deletes any symlinks in the multicd folder that point to other files also in the multicd folder - because these are almost always auto-created links, like the one just described.

elif [ $1 = scan ];then
	if [ -f feather.iso ];then
		echo "Feather"
	fi

multicd.sh calls this section next.
Each plugin will scan to see if its respective ISO is in the folder and should be included.
For some plugins, it might be more complicated, i.e. if two CDs can't be on the same disc.

elif [ $1 = copy ];then
	if [ -f feather.iso ];then
		echo "Copying Feather..."
		mcdmount feather
		mkdir "${WORK}"/FEATHER
		mcdcp -r "${MNT}"/feather/KNOPPIX/* "${WORK}"/FEATHER/ #Compressed filesystem
		mkdir "${WORK}"/boot/feather
		cp "${MNT}"/feather/boot/isolinux/linux24 "${WORK}"/boot/feather/linux24
		cp "${MNT}"/feather/boot/isolinux/minirt24.gz "${WORK}"/boot/feather/minirt24.gz
		umcdmount feather
	fi

This is the copy section, called in the middle of multicd.sh.
First, the plugin sees if the ISO is there (again, since it doesn't remember), then the mcdmount function makes a temporary mountpoint for the ISO image, makes sure nothing's mounted there, then mounts it. If MultiCD can't find a way, to loop-mount the image (i.e. you're not root and don't have fuseiso installed), mcdmount might actually extract the ISO to the folder instead, with a program like file-roller or 7z.
After mounting, the necessary components are copied into multicd's working directory. Feather Linux has a folder named KNOPPIX, which gets renamed, and a kernel and intrd that reside elsewhere. Once this is done, umcdmount unmounts and removes the mountpoint.

Each ISO will have different files that need to be copied. This will often be a kernel, an initrd, and a file or folder with a compressed filesystem image (like Ubuntu's casper.)

elif [ $1 = writecfg ];then
if [ -f feather.iso ];then
if [ $(cat "${TAGS}"/lang) ];then
	LANGCODE=$(cat "${TAGS}"/lang)
else
	LANGCODE=us
fi
echo "LABEL feather
MENU LABEL ^Feather Linux
KERNEL /boot/feather/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=$LANGCODE apm=power-off vga=791 initrd=/boot/feather/minirt24.gz knoppix_dir=FEATHER nomce quiet BOOT_IMAGE=knoppix
LABEL feather-toram
MENU LABEL Feather Linux (load to RAM)
KERNEL /boot/feather/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=$LANGCODE apm=power-off vga=791 initrd=/boot/feather/minirt24.gz knoppix_dir=FEATHER nomce quiet toram BOOT_IMAGE=knoppix
LABEL feather-2
MENU LABEL Feather Linux (boot to command line)
KERNEL /boot/feather/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=$LANGCODE apm=power-off vga=791 initrd=/boot/feather/minirt24.gz knoppix_dir=FEATHER nomce quiet 2 BOOT_IMAGE=knoppix
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi

The third part of the plugin script is called right before the multicd.iso image is made.
This section adds the distro's ISOLINUX commands to the new isolinux.cfg.
It checks if the ISO is there (yet again,) and if it is, it appends text to isolinux.cfg.
The plugin for Feather has the boot commands hard-coded into the plugin script. This is easier, but if the boot commands get updated in the next version of the distro, the script will need to be updated.
Keep in mind that if the files aren't in the same place as they are on the original CD, you'll have to change some things. For Feather Linux, this means using "/boot/feather" instead of "/boot/isolinux" and adding "knoppix_dir=FEATHER".

else
	echo "Usage: $0 {links|scan|copy|writecfg}"
	echo "Use only from within multicd.sh or a compatible script!"
	echo "Don't use this plugin script on its own!"
fi

The end is always the same. If the script is not called with one of the three arguments multicd.sh uses (i.e. if a user calls it seperately), the script tells the user that the script can't be used on its own.