2009-10-19 17:24:25 +00:00
|
|
|
#!/bin/sh
|
2010-04-15 17:20:09 +00:00
|
|
|
#
|
2011-05-04 11:44:53 +00:00
|
|
|
# Public Domain, 2009-2011 - Juan RP <xtraeme@gmail.com>
|
2010-04-15 17:20:09 +00:00
|
|
|
#
|
2009-10-19 17:24:25 +00:00
|
|
|
trap "echo; error_out $?" INT QUIT
|
|
|
|
|
|
|
|
info_msg()
|
|
|
|
{
|
|
|
|
printf "\033[1m$@\n\033[m"
|
|
|
|
}
|
2010-04-15 17:20:09 +00:00
|
|
|
|
|
|
|
mount_pseudofs()
|
|
|
|
{
|
2011-05-04 11:44:53 +00:00
|
|
|
local fs
|
|
|
|
|
|
|
|
if [ -n "$ROOTDIR" ]; then
|
|
|
|
mount --bind "$ROOTDIR" "$ROOTFS" || error_out $?
|
|
|
|
fi
|
|
|
|
|
2010-04-15 17:20:09 +00:00
|
|
|
for fs in sys proc dev; do
|
2011-05-04 11:44:53 +00:00
|
|
|
if [ ! -d "$ROOTFS/$fs" ]; then
|
|
|
|
mkdir -p "$ROOTFS/$fs"
|
2010-04-15 17:20:09 +00:00
|
|
|
fi
|
2011-05-04 11:44:53 +00:00
|
|
|
mount --bind /$fs "$ROOTFS/$fs" || error_out $?
|
2010-04-15 17:20:09 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
umount_pseudofs()
|
|
|
|
{
|
2011-05-04 11:44:53 +00:00
|
|
|
local fs
|
|
|
|
|
2010-04-15 17:20:09 +00:00
|
|
|
for fs in sys proc dev; do
|
2011-05-04 11:44:53 +00:00
|
|
|
umount -f "$ROOTFS/$fs" >/dev/null 2>&1
|
2010-04-15 17:20:09 +00:00
|
|
|
done
|
2011-05-04 11:44:53 +00:00
|
|
|
if [ -n "$1" -a -n "$ROOTDIR" ]; then
|
|
|
|
umount -f "$ROOTFS" >/dev/null 2>&1
|
|
|
|
fi
|
2010-04-15 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 17:24:25 +00:00
|
|
|
error_out()
|
|
|
|
{
|
2010-04-15 17:20:09 +00:00
|
|
|
umount_pseudofs
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
if [ "$1" -ne 0 ]; then
|
|
|
|
echo "ERROR: stage mentioned above returned $1!"
|
|
|
|
fi
|
|
|
|
info_msg "Cleaning up $BUILDDIR..."
|
|
|
|
rm -rf "$BUILDDIR"
|
2009-10-19 17:24:25 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
write_etc_motd()
|
|
|
|
{
|
2011-05-04 11:44:53 +00:00
|
|
|
cat >> "$ROOTFS/etc/motd" <<_EOF
|
2010-05-14 03:09:23 +00:00
|
|
|
###############################################################################
|
2011-06-25 09:23:56 +00:00
|
|
|
Autogenerated by vanilla-mklive @@MKLIVE_VERSION@@.
|
2010-05-14 03:09:23 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
2011-06-25 09:23:56 +00:00
|
|
|
Welcome to the Vanilla GNU/Linux Live system, you have been autologged in.
|
2009-10-19 17:24:25 +00:00
|
|
|
This user has full sudo(8) permissions without any password, be careful
|
|
|
|
executing commands through sudo(8).
|
|
|
|
|
2009-11-23 02:30:42 +00:00
|
|
|
To play with package management use the xbps-bin(8) and xbps-repo(8)
|
|
|
|
utilities. Please visit:
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2010-05-14 03:09:23 +00:00
|
|
|
http://code.google.com/p/xbps/
|
2009-11-23 02:30:42 +00:00
|
|
|
|
|
|
|
For more information and/or documentation about using the X Binary
|
|
|
|
Package System. Enjoy it.
|
|
|
|
|
2010-05-14 03:09:23 +00:00
|
|
|
Please also visit my personal blog and click to any of the Google ADs,
|
|
|
|
to help continuining developping XBPS. Thank you.
|
|
|
|
|
|
|
|
http://xtraeme.blogspot.com/
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-07-08 08:26:11 +00:00
|
|
|
Vanilla GNU/Linux: https://vanilla.github.com
|
2010-05-14 03:09:23 +00:00
|
|
|
|
|
|
|
###############################################################################
|
2009-10-19 17:24:25 +00:00
|
|
|
_EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
write_default_isolinux_conf()
|
|
|
|
{
|
|
|
|
local kver="$1"
|
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
if [ -r "$SPLASH_IMAGE" ]; then
|
|
|
|
BACKGROUND="MENU BACKGROUND $(basename $SPLASH_IMAGE)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat >> "$ISOLINUX_CFG" << _EOF
|
2009-10-19 17:24:25 +00:00
|
|
|
DEFAULT vesamenu.c32
|
|
|
|
PROMPT 0
|
2011-05-04 11:44:53 +00:00
|
|
|
TIMEOUT 100
|
|
|
|
ONTIMEOUT linux
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
$BACKGROUND
|
2009-10-19 17:24:25 +00:00
|
|
|
MENU VSHIFT 5
|
|
|
|
MENU ROWS 20
|
|
|
|
MENU TABMSGROW 10
|
|
|
|
MENU TABMSG Press ENTER to boot or TAB to edit a menu entry
|
|
|
|
MENU AUTOBOOT BIOS default device boot in # second{,s}...
|
|
|
|
MENU TIMEOUTROW 12
|
|
|
|
|
|
|
|
MENU COLOR title * #FF5255FF *
|
|
|
|
MENU COLOR border * #00000000 #00000000 none
|
|
|
|
MENU COLOR sel * #ffffffff #FF5255FF *
|
|
|
|
|
|
|
|
LABEL linux
|
2011-06-25 09:23:56 +00:00
|
|
|
MENU LABEL Boot Vanilla GNU/Linux ${kver} ($(uname -m))
|
2009-10-19 17:24:25 +00:00
|
|
|
KERNEL /casper/vmlinuz
|
2010-05-14 03:09:23 +00:00
|
|
|
INITRD /casper/initrd.lz
|
2011-05-04 11:44:53 +00:00
|
|
|
APPEND boot=casper keymap=${KEYMAP:-es} locale=${LOCALE:-es_ES} ro
|
2009-10-19 17:24:25 +00:00
|
|
|
|
|
|
|
LABEL linuxtoram
|
2011-06-25 09:23:56 +00:00
|
|
|
MENU LABEL Boot Vanilla GNU/Linux ${kver} (toram) ($(uname -m))
|
2009-10-19 17:24:25 +00:00
|
|
|
KERNEL /casper/vmlinuz
|
2010-05-14 03:09:23 +00:00
|
|
|
INITRD /casper/initrd.lz
|
2011-05-04 11:44:53 +00:00
|
|
|
APPEND boot=casper toram keymap=${KEYMAP:-es} locale=${LOCALE:-es_ES} ro
|
2009-10-19 17:24:25 +00:00
|
|
|
|
|
|
|
LABEL c
|
|
|
|
MENU LABEL Boot first HD found by the BIOS
|
|
|
|
LOCALBOOT 0x80
|
|
|
|
_EOF
|
|
|
|
}
|
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat <<_EOF
|
|
|
|
Usage: $(basename $0) [options]
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
#
|
|
|
|
# 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
|
2009-10-19 17:24:25 +00:00
|
|
|
done
|
2011-05-04 11:44:53 +00:00
|
|
|
shift $(($OPTIND - 1))
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
|
|
echo "ERROR: EPERM... got root?"
|
|
|
|
exit 1
|
2009-10-19 17:24:25 +00:00
|
|
|
fi
|
|
|
|
|
2011-06-25 09:23:56 +00:00
|
|
|
CONFIG_DIR="$HOME/.mklive"
|
2011-05-04 11:44:53 +00:00
|
|
|
CONFIG_FILE="$CONFIG_DIR/default.conf"
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
if [ -z "$OUTPUT_FILE" ]; then
|
2011-06-25 09:23:56 +00:00
|
|
|
OUTPUT_FILE="$HOME/vanilla-live-$(uname -m)-$(date +%Y%m%d).iso"
|
2011-05-04 11:44:53 +00:00
|
|
|
fi
|
|
|
|
if [ -z "$ISO_VOLUME" ]; then
|
2011-06-25 09:23:56 +00:00
|
|
|
ISO_VOLUME="Vanilla GNU/Linux Live $(uname -m)"
|
2009-10-19 17:24:25 +00:00
|
|
|
fi
|
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
#
|
|
|
|
# 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
|
2009-10-19 17:24:25 +00:00
|
|
|
fi
|
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
. $CONFIG_FILE
|
|
|
|
|
|
|
|
if [ -z "$PACKAGE_LIST" ]; then
|
2011-06-23 10:18:42 +00:00
|
|
|
PACKAGE_LIST="base-system xbps-casper"
|
2011-05-04 11:44:53 +00:00
|
|
|
else
|
2011-06-23 10:18:42 +00:00
|
|
|
PACKAGE_LIST="base-system xbps-casper $PACKAGE_LIST"
|
2010-05-14 01:27:14 +00:00
|
|
|
fi
|
2011-05-04 11:44:53 +00:00
|
|
|
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"
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
if [ ! -f $SYSLINUX_DATADIR/isolinux.bin ]; then
|
|
|
|
echo "Missing required isolinux files in $SYSLINUX_DATADIR!"
|
|
|
|
error_out
|
2009-10-19 17:24:25 +00:00
|
|
|
fi
|
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
#
|
|
|
|
# Mount pseudofs in the target rootfs.
|
|
|
|
#
|
2010-04-15 17:20:09 +00:00
|
|
|
mount_pseudofs
|
2011-05-04 11:44:53 +00:00
|
|
|
mkdir -p "$ROOTFS/tmp"
|
|
|
|
|
|
|
|
if [ -z "$ROOTDIR" ]; then
|
|
|
|
#
|
|
|
|
# Register all package repositories in the target rootfs.
|
|
|
|
#
|
2011-06-25 09:23:56 +00:00
|
|
|
xver=$(${XBPS_BIN_CMD} -V|awk '{print $2}')
|
|
|
|
if [ -z "$xver" -o "$xver" = "" ]; then
|
|
|
|
for _repo_ in ${PACKAGE_REPO}; do
|
|
|
|
info_msg "Adding ${_repo_} package repository..."
|
|
|
|
${XBPS_REPO_CMD} -r "$ROOTFS" add "${_repo_}" || error_out $?
|
|
|
|
done
|
|
|
|
fi
|
2011-05-04 11:44:53 +00:00
|
|
|
${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 $?
|
2009-12-22 15:05:54 +00:00
|
|
|
fi
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
${XBPS_BIN_CMD} -r "$ROOTFS" list > \
|
|
|
|
"${OUTPUT_FILE%.iso}"-package-list.txt || error_out $?
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prepare /etc/motd.
|
|
|
|
#
|
2009-10-19 17:24:25 +00:00
|
|
|
info_msg "Creating /etc/motd..."
|
|
|
|
write_etc_motd
|
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
#
|
|
|
|
# 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..."
|
2010-05-17 15:45:01 +00:00
|
|
|
sed -i -e "s|COMPRESS=gzip|COMPRESS=lzma|" \
|
2011-05-04 11:44:53 +00:00
|
|
|
"$ROOTFS"/etc/initramfs-tools/initramfs.conf
|
|
|
|
${XBPS_BIN_CMD} -r "$ROOTFS" -f reconfigure kernel || error_out $?
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
cp -f "${INITRD_IMG:-$ROOTFS/boot/initrd.img-${kver}}" \
|
|
|
|
"$BUILDDIR/casper/initrd.lz" || error_out $?
|
|
|
|
mkdir -p "$ROOTFS"/cow
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2010-02-20 04:53:13 +00:00
|
|
|
info_msg "Cleaning up rootfs..."
|
2011-05-04 11:44:53 +00:00
|
|
|
rm -f "$ROOTFS"/boot/initrd*
|
|
|
|
rm -f "$ROOTFS"/boot/vmlinuz*
|
2010-02-20 04:53:13 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
#
|
|
|
|
# The pseudofs aren't needed anymore in target rootfs.
|
|
|
|
#
|
2010-04-15 17:20:09 +00:00
|
|
|
umount_pseudofs
|
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prepare the squashed rootfs image.
|
|
|
|
#
|
2009-10-19 17:24:25 +00:00
|
|
|
info_msg "Building squashed root filesystem..."
|
2011-05-04 11:44:53 +00:00
|
|
|
mksquashfs "$ROOTFS" "$BUILDDIR/casper/filesystem.squashfs" \
|
|
|
|
-root-becomes / -comp ${SQUASHFS_COMPRESSION:-gzip} && \
|
|
|
|
chmod 444 "$BUILDDIR/casper/filesystem.squashfs" || error_out $?
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
if [ -n "$ROOTDIR" ]; then
|
|
|
|
umount_pseudofs yes
|
|
|
|
else
|
|
|
|
info_msg "Removing rootfs directory..."
|
|
|
|
rm -rf "$ROOTFS" || error_out $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prepare the ISO image.
|
|
|
|
#
|
2009-10-19 17:24:25 +00:00
|
|
|
info_msg "Building ISO image..."
|
|
|
|
mkisofs -J -r -V "$ISO_VOLUME" -b isolinux/isolinux.bin \
|
2011-05-04 11:44:53 +00:00
|
|
|
-c isolinux/boot.cat -no-emul-boot \
|
|
|
|
-boot-load-size 4 -boot-info-table \
|
|
|
|
-o "$OUTPUT_FILE" "$BUILDDIR" || error_out $?
|
2009-10-19 17:24:25 +00:00
|
|
|
|
2011-05-04 11:44:53 +00:00
|
|
|
info_msg "Removing build directory..."
|
|
|
|
rm -rf "$BUILDDIR" || error_out $?
|
2009-10-19 17:24:25 +00:00
|
|
|
|
|
|
|
info_msg "Created $(readlink -f $OUTPUT_FILE) successfully."
|
|
|
|
|
|
|
|
exit 0
|