How can I tell mcx to get packages from a local storage instead of getting it always from the web server? I've looked around in your script where you define a Cache() function, but I could not figure out how to do what I want to do.
The script mcx maintains a cache (default /tmp/mcx/cache) so it can avoid downloading extensions multiple times. Each time mcx is commanded to load an extension, it fetches the corresponding .md5.txt file from the repository. If the extension exits in the cache and its calculated MD5 sum matches the latest .md5.txt file from the repository, then mcx uses the extension from the cache. Otherwise, mcx downloads the extension from the repository and saves a copy in the cache. This algorithm always gives precedence to an extension in the repository, so putting a local extension in the cache will not give the behavior that you want.
If you want to save the cached extensions across reboots, one option is to use the "-tmp" option to change the location of the directory that contains temporary files (including the cache) so that directory is allocated in persistent storage. (I have not used or tested the "-tmp" option.)
Another option is to use rsync to move the cache:
rsync -av /tmp/mcx/cache/ /path/to/my/storage/cache/ # Save the cache
...
rsync -av /path/to/my/storage/cache/ /tmp/mcx/cache/ # Restore the cache
Rsync has the advantage over cp that it does not copy files that are unchanged in the destination directory.
Like.. copying /tmp/mcx/cache somewhere, then retrieve it at some point when I build a new image to prevent depending on the internet, or using updated packages that I haven't confirmed to work alongside my apps...
Below is an mcx script that I use to remaster Micro Core when I am testing a new extension. It accepts a source ISO, a destination ISO, and a list of extensions. If an extension is specified by a path containing "/", then that extension and any of its dependencies that are found in the same directory are loaded from that directory instead of the repository. For example, to remaster Micro Core to contain the dropbear extension from the repository and a local extension that I am testing, I use something similar to:
./remaster /path/to/MicroCoreIso /path/to/RemasteredIso dropbear /path/to/my/extension.tcz
#!/bin/sh
[ $# -lt 2 ] && echo "Usage: $(basename $0) /path/to/MicroCoreIso /path/to/RemasteredIso [extension ...]" && exit 0
#=====================================================================
# If $EXT is a local file, copy it to /opt/tce/optional, add its name
# to /opt/tce/onboot.lst, and load its dependencies. An attempt will
# be made to load those dependencies from the same directory as $EXT.
# If $EXT or one of its dependencies is not found in the same
# directory as $EXT, call mcx to fetch the extension from the repository.
Load () {
local DIR=$(dirname "$EXT")
local EXT=$(basename "$EXT")
if [ -r "$EXT" ]
then
echo "Getting $DIR/$EXT"
cp "$DIR/$EXT"* /tmp/mcx/microcore/opt/tce/optional/
echo "$EXT" >>/tmp/mcx/microcore/opt/tce/onboot.lst
for EXT in $(cat /tmp/mcx/microcore/opt/tce/optional/$EXT.dep 2>/dev/null)
do
EXT="$DIR/$EXT"
Load
done
else
mcx -install "$EXT"
fi
}
#=====================================================================
# Remember the first two parameters.
SRC=$1 ; DST=$2 ; shift 2
# Add the directory of this script to PATH.
PATH=$PATH:$(dirname $0)
# Unpack the ISO.
mcx -unpack $SRC
# Install the user-specified extensions.
for EXT in "$@"
do
# Add ".tcz" to the extension if needed.
case "$EXT" in
*.tcz) ;;
*.gz) ;;
*) EXT="$EXT.tcz" ;;
esac
# Load the extension with special processing if it contains "/".
case "$EXT" in
*/*) Load "$EXT" ;;
*) mcx -install "$EXT" ;;
esac
done
# Pack the files into the ISO $DST.
mcx -pack $DST
This script or something similar will work with a local subset of the repository if you execute the script from within the local repository and list each extension that you want to load with a "./" prefix.
I will consider adding the capability to load local extensions to the next version of mcx.