xbps-mklive: multiple fixes and improvements.

Some flags were added to specify rootdir, splash image, compression type.
This commit is contained in:
Juan RP 2011-05-04 13:44:53 +02:00
parent 548b8f1224
commit b27c65882e
2 changed files with 195 additions and 127 deletions

320
srcpkgs/xbps-mklive/files/xbps-mklive.sh.in Normal file → Executable file
View file

@ -1,40 +1,9 @@
#!/bin/sh
#
# Public Domain, 2009-2010 - Juan RP <xtraeme@gmail.com>
# Public Domain, 2009-2011 - Juan RP <xtraeme@gmail.com>
#
trap "echo; error_out $?" INT QUIT
[ "$(id -u)" -ne 0 ] && echo "root perms are required." && exit 1
ISOLINUX_ARGS="-b isolinux/isolinux.bin -c isolinux/boot.cat"
ISOLINUX_ARGS="$ISOLINUX_ARGS -boot-load-size 4 -no-emul-boot"
ISOLINUX_ARGS="$ISOLINUX_ARGS -boot-info-table"
CONFIG_FILE="$HOME/.xbps-mklive.conf"
#
# The following vars are overwritten by the config file.
#
PACKAGE_REPO="/storage/xbps/packages"
OUTPUT_FILE="$HOME/xbps-live-$(uname -m)-$(date +%Y%m%d).iso"
ISO_VOLUME="XBPS GNU/Linux Live $(uname -m)"
SYSLINUX_DATADIR="/usr/share/syslinux"
SPLASH_IMAGE=$HOME/splash.rle
if [ -f $CONFIG_FILE ]; then
. $CONFIG_FILE
fi
if [ -z "$PACKAGE_LIST" ]; then
PACKAGE_LIST="xbps-base-system xbps-casper"
else
PACKAGE_LIST="xbps-base-system xbps-casper $PACKAGE_LIST"
fi
BUILD_TMPDIR=$(mktemp --tmpdir="$(pwd)" -d) || exit 1
BUILD_TMPDIR=$(readlink -f $BUILD_TMPDIR)
TEMP_ROOTFS="$BUILD_TMPDIR/casper/rootfs"
ISOLINUX_DIR="$BUILD_TMPDIR/isolinux"
info_msg()
{
printf "\033[1m$@\n\033[m"
@ -42,34 +11,47 @@ info_msg()
mount_pseudofs()
{
local fs
if [ -n "$ROOTDIR" ]; then
mount --bind "$ROOTDIR" "$ROOTFS" || error_out $?
fi
for fs in sys proc dev; do
if [ ! -d $TEMP_ROOTFS/$fs ]; then
mkdir -p $TEMP_ROOTFS/$fs
if [ ! -d "$ROOTFS/$fs" ]; then
mkdir -p "$ROOTFS/$fs"
fi
mount --bind /$fs $TEMP_ROOTFS/$fs || error_out
mount --bind /$fs "$ROOTFS/$fs" || error_out $?
done
}
umount_pseudofs()
{
local fs
for fs in sys proc dev; do
umount -f $TEMP_ROOTFS/$fs >/dev/null 2>&1
umount -f "$ROOTFS/$fs" >/dev/null 2>&1
done
if [ -n "$1" -a -n "$ROOTDIR" ]; then
umount -f "$ROOTFS" >/dev/null 2>&1
fi
}
error_out()
{
umount_pseudofs
[ "$1" -ne 0 ] && echo "ERROR: stage mentioned above returned $1!"
info_msg "Cleaning up $BUILD_TMPDIR..."
rm -rf $BUILD_TMPDIR
if [ "$1" -ne 0 ]; then
echo "ERROR: stage mentioned above returned $1!"
fi
info_msg "Cleaning up $BUILDDIR..."
rm -rf "$BUILDDIR"
exit 1
}
write_etc_motd()
{
cat >> "$TEMP_ROOTFS/etc/motd" <<_EOF
cat >> "$ROOTFS/etc/motd" <<_EOF
###############################################################################
Autogenerated by xbps-mklive @@MKLIVE_VERSION@@.
-------------------------------------------------------------------------------
@ -101,13 +83,17 @@ write_default_isolinux_conf()
{
local kver="$1"
cat >> "$ISOLINUX_DIR/isolinux.cfg" << _EOF
if [ -r "$SPLASH_IMAGE" ]; then
BACKGROUND="MENU BACKGROUND $(basename $SPLASH_IMAGE)"
fi
cat >> "$ISOLINUX_CFG" << _EOF
DEFAULT vesamenu.c32
PROMPT 0
TIMEOUT 600
ONTIMEOUT c
TIMEOUT 100
ONTIMEOUT linux
MENU BACKGROUND $(basename $SPLASH_IMAGE)
$BACKGROUND
MENU VSHIFT 5
MENU ROWS 20
MENU TABMSGROW 10
@ -123,13 +109,13 @@ LABEL linux
MENU LABEL Boot XBPS GNU/Linux ${kver} ($(uname -m))
KERNEL /casper/vmlinuz
INITRD /casper/initrd.lz
APPEND boot=casper keymap=es locale=es_ES quiet
APPEND boot=casper keymap=${KEYMAP:-es} locale=${LOCALE:-es_ES} ro
LABEL linuxtoram
MENU LABEL Boot XBPS GNU/Linux ${kver} (toram) ($(uname -m))
KERNEL /casper/vmlinuz
INITRD /casper/initrd.lz
APPEND boot=casper toram keymap=es locale=es_ES quiet
APPEND boot=casper toram keymap=${KEYMAP:-es} locale=${LOCALE:-es_ES} ro
LABEL c
MENU LABEL Boot first HD found by the BIOS
@ -137,108 +123,190 @@ LOCALBOOT 0x80
_EOF
}
[ -z "$PACKAGE_LIST" ] && error_out
[ -z "$OUTPUT_FILE" ] && error_out
[ -z "$ISO_VOLUME" ] && error_out
[ -z "$PACKAGE_REPO" ] && error_out
usage()
{
cat <<_EOF
Usage: $(basename $0) [options]
for _repo_ in ${PACKAGE_REPO}; do
info_msg "Adding ${_repo_} package repository..."
xbps-repo.static -r $TEMP_ROOTFS add ${_repo_}
[ $? -ne 0 ] && error_out $?
Options:
-c comptype Compression type for the squashfs image.
-o outfile Output file name for the ISO image.
-r rootdir Rootfs directory.
-s splash Splash image file for isolinux.
-v volname ISO Volume name.
-h Shows this message.
_EOF
exit 1
}
#
# main()
#
while getopts "c:o:r:s:v:h" opt; do
case $opt in
c) export SQUASHFS_COMPRESSION="$OPTARG";;
o) export OUTPUT_FILE="$OPTARG";;
r) export ROOTDIR="$OPTARG";;
s) export SPLASH_IMAGE="$OPTARG";;
v) export ISO_VOLUME="$OPTARG";;
h) usage;;
esac
done
shift $(($OPTIND - 1))
if [ ! -f $SYSLINUX_DATADIR/isolinux.bin -o \
! -f $SYSLINUX_DATADIR/vesamenu.c32 ]; then
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: EPERM... got root?"
exit 1
fi
CONFIG_DIR="$HOME/.xbps-mklive"
CONFIG_FILE="$CONFIG_DIR/default.conf"
if [ -z "$OUTPUT_FILE" ]; then
OUTPUT_FILE="$HOME/xbps-live-$(uname -m)-$(date +%Y%m%d).iso"
fi
if [ -z "$ISO_VOLUME" ]; then
ISO_VOLUME="XBPS GNU/Linux Live $(uname -m)"
fi
#
# The following vars can be overwritten by the config file.
#
PACKAGE_REPO="/storage/xbps/packages"
SYSLINUX_DATADIR="/usr/share/syslinux"
XBPS_REPO_CMD="xbps-repo"
XBPS_BIN_CMD="xbps-bin"
XBPS_UHELPER_CMD="xbps-uhelper"
if [ ! -r $CONFIG_FILE ]; then
echo "Cannot find $CONFIG_FILE! exiting..."
error_out
fi
. $CONFIG_FILE
if [ -z "$PACKAGE_LIST" ]; then
PACKAGE_LIST="xbps-base-system xbps-casper"
else
PACKAGE_LIST="xbps-base-system xbps-casper $PACKAGE_LIST"
fi
BUILDDIR=$(mktemp --tmpdir="$(pwd)" -d) || exit 1
BUILDDIR=$(readlink -f $BUILDDIR)
ROOTFS="$BUILDDIR/casper/rootfs"
ISOLINUX_DIR="$BUILDDIR/isolinux"
ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg"
if [ ! -f $SYSLINUX_DATADIR/isolinux.bin ]; then
echo "Missing required isolinux files in $SYSLINUX_DATADIR!"
error_out
fi
[ ! -d "$ISOLINUX_DIR" ] && mkdir -p "$ISOLINUX_DIR"
#
# Mount pseudofs in the target rootfs.
#
mount_pseudofs
mkdir -p "$ROOTFS/tmp"
if [ ! -f "$ISOLINUX_DIR/isolinux.bin" ]; then
cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR"
if [ -z "$ROOTDIR" ]; then
#
# Register all package repositories in the target rootfs.
#
for _repo_ in ${PACKAGE_REPO}; do
info_msg "Adding ${_repo_} package repository..."
${XBPS_REPO_CMD} -r "$ROOTFS" add "${_repo_}" || error_out $?
done
${XBPS_BIN_CMD} -r "$ROOTFS" -y install ${PACKAGE_LIST} || error_out $?
${XBPS_BIN_CMD} -r "$ROOTFS" -y autoupdate || error_out $?
${XBPS_BIN_CMD} -r "$ROOTFS" -yp autoremove || error_out $?
${XBPS_BIN_CMD} -r "$ROOTFS" -yvp purge all || error_out $?
fi
if [ ! -f "$ISOLINUX_DIR/isolinux.cfg" ]; then
kernel_ver=$(xbps-repo.static -r $TEMP_ROOTFS show kernel|grep Version|awk '{print $2}')
if [ -z "$kernel_ver" ]; then
echo "Missing 'kernel' pkg in repository pool (xbps-repo)!"
error_out
fi
write_default_isolinux_conf ${kernel_ver}
${XBPS_BIN_CMD} -r "$ROOTFS" list > \
"${OUTPUT_FILE%.iso}"-package-list.txt || error_out $?
#
# Prepare /etc/motd.
#
info_msg "Creating /etc/motd..."
write_etc_motd
#
# We must know the installed kernel package version.
#
kver=$(${XBPS_UHELPER_CMD} -r "$ROOTFS" version kernel)
if [ -z "$kver" ]; then
echo "Missing 'kernel' package in repository pool!"
error_out
fi
#
# Rebuild the initramfs image with LZMA compression.
#
info_msg "Rebuilding and copying initramfs image..."
sed -i -e "s|COMPRESS=gzip|COMPRESS=lzma|" \
"$ROOTFS"/etc/initramfs-tools/initramfs.conf
${XBPS_BIN_CMD} -r "$ROOTFS" -f reconfigure kernel || error_out $?
cp -f "${INITRD_IMG:-$ROOTFS/boot/initrd.img-${kver}}" \
"$BUILDDIR/casper/initrd.lz" || error_out $?
mkdir -p "$ROOTFS"/cow
#
# Copy the linux image to the target directory.
#
info_msg "Copying kernel image..."
cp -f "${KERNEL_IMG:-$ROOTFS/boot/vmlinuz-${kver}}" \
"$BUILDDIR/casper/vmlinuz" || error_out $?
#
# Remove stuff that uses a lot of space.
#
info_msg "Cleaning up rootfs..."
rm -f "$ROOTFS"/boot/initrd*
rm -f "$ROOTFS"/boot/vmlinuz*
#
# The pseudofs aren't needed anymore in target rootfs.
#
umount_pseudofs
#
# Copy required isolinux files in the target rootfs.
#
mkdir -p "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR"
write_default_isolinux_conf ${kver}
if [ -f "$SPLASH_IMAGE" ]; then
cp -f $SPLASH_IMAGE "$ISOLINUX_DIR"
fi
if [ ! -f "$ISOLINUX_DIR/vesamenu.c32" ]; then
cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR"
fi
mount_pseudofs
xbps_relver=$(xbps-bin.static -V)
xbps-uhelper.static cmpver ${xbps_relver} 20100511
if [ $? -eq 255 ]; then
info_msg "Your XBPS utilities are outdated... please update to >= 0.5.1"
error_out 1
fi
xbps-bin.static -r $TEMP_ROOTFS -y install ${PACKAGE_LIST} || error_out $?
xbps-bin.static -r $TEMP_ROOTFS -y autoupdate || error_out $?
xbps-bin.static -r $TEMP_ROOTFS -yp autoremove || error_out $?
xbps-bin.static -r $TEMP_ROOTFS -yvp purge all || error_out $?
xbps-bin.static -r $TEMP_ROOTFS list > ${OUTPUT_FILE%.iso}-package-list.txt
info_msg "Creating /etc/motd..."
write_etc_motd
info_msg "Rebuilding and copying initramfs..."
# Set lzma compression for the initramfs, to save space.
sed -i -e "s|COMPRESS=gzip|COMPRESS=lzma|" \
$TEMP_ROOTFS/etc/initramfs-tools/initramfs.conf
xbps-bin.static -r $TEMP_ROOTFS -f reconfigure kernel
[ $? -ne 0 ] && error_out $?
cp -f "$TEMP_ROOTFS/boot/initrd.img-${kernel_ver}" \
"$BUILD_TMPDIR/casper/initrd.lz" || error_out $?
mkdir -p $TEMP_ROOTFS/cow
info_msg "Copying kernel binary..."
cp -f "$TEMP_ROOTFS/boot/vmlinuz-${kernel_ver}" \
"$BUILD_TMPDIR/casper/vmlinuz" || error_out $?
info_msg "Cleaning up rootfs..."
rm -f $TEMP_ROOTFS/boot/initrd*
rm -f $TEMP_ROOTFS/boot/vmlinuz*
umount_pseudofs
#
# Prepare the squashed rootfs image.
#
info_msg "Building squashed root filesystem..."
mksquashfs "$TEMP_ROOTFS" "$BUILD_TMPDIR/casper/filesystem.squashfs" \
-root-becomes / && \
chmod 444 "$BUILD_TMPDIR/casper/filesystem.squashfs"
[ $? -ne 0 ] && error_out $?
mksquashfs "$ROOTFS" "$BUILDDIR/casper/filesystem.squashfs" \
-root-becomes / -comp ${SQUASHFS_COMPRESSION:-gzip} && \
chmod 444 "$BUILDDIR/casper/filesystem.squashfs" || error_out $?
info_msg "Removing temporary rootfs directory..."
rm -rf "$TEMP_ROOTFS" || error_out $?
info_msg "Creating sha256 checksums..."
cd $BUILD_TMPDIR
for f in $(find . -type f -print); do
[ "$f" = "./sha256.txt" ] && continue
printf "${f#.}\t$(xbps-uhelper.static digest $f)\n" \
>> $BUILD_TMPDIR/sha256.txt
done
if [ -n "$ROOTDIR" ]; then
umount_pseudofs yes
else
info_msg "Removing rootfs directory..."
rm -rf "$ROOTFS" || error_out $?
fi
#
# Prepare the ISO image.
#
info_msg "Building ISO image..."
mkisofs -J -r -V "$ISO_VOLUME" -b isolinux/isolinux.bin \
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table -o "$OUTPUT_FILE" "$BUILD_TMPDIR"
[ $? -ne 0 ] && error_out $?
-c isolinux/boot.cat -no-emul-boot \
-boot-load-size 4 -boot-info-table \
-o "$OUTPUT_FILE" "$BUILDDIR" || error_out $?
info_msg "Removing temporary build directory..."
rm -rf "$BUILD_TMPDIR" || error_out $?
info_msg "Removing build directory..."
rm -rf "$BUILDDIR" || error_out $?
info_msg "Created $(readlink -f $OUTPUT_FILE) successfully."

View file

@ -1,6 +1,6 @@
# Template file for 'xbps-mklive'
pkgname=xbps-mklive
version=0.3.5
version=0.3.6
build_style=custom-install
short_desc="XBPS Live image maker"
maintainer="Juan RP <xtraeme@gmail.com>"