mklive.sh: double-quote vars to make building an iso on a path

that has spaces in directory names possible.
This commit is contained in:
mobinmob 2018-06-17 23:33:13 +03:00 committed by Michael Aldridge
parent 49a0cbf98b
commit 40027cd5a6

View File

@ -31,7 +31,7 @@ umask 022
readonly REQUIRED_PKGS="base-files libgcc dash coreutils sed tar gawk syslinux grub-i386-efi grub-x86_64-efi squashfs-tools xorriso"
readonly INITRAMFS_PKGS="binutils xz device-mapper dhclient dracut-network"
readonly PROGNAME=$(basename $0)
readonly PROGNAME=$(basename "$0")
info_msg() {
printf "\033[1m$@\n\033[m"
@ -46,19 +46,19 @@ print_step() {
}
mount_pseudofs() {
for f in sys dev proc; do
mkdir -p $ROOTFS/$f
mount --bind /$f $ROOTFS/$f
mkdir -p "$ROOTFS"/$f
mount --bind /$f "$ROOTFS"/$f
done
}
umount_pseudofs() {
umount -f $ROOTFS/sys >/dev/null 2>&1
umount -f $ROOTFS/dev >/dev/null 2>&1
umount -f $ROOTFS/proc >/dev/null 2>&1
umount -f "$ROOTFS"/sys >/dev/null 2>&1
umount -f "$ROOTFS"/dev >/dev/null 2>&1
umount -f "$ROOTFS"/proc >/dev/null 2>&1
}
error_out() {
umount_pseudofs
[ -d "$BUILDDIR" -a -z "$KEEP_BUILDDIR" ] && rm -rf "$BUILDDIR"
exit ${1:=0}
exit "${1:=0}"
}
usage() {
@ -100,133 +100,133 @@ copy_void_conf() {
}
copy_dracut_files() {
mkdir -p $1/usr/lib/dracut/modules.d/01vmklive
cp dracut/vmklive/* $1/usr/lib/dracut/modules.d/01vmklive/
mkdir -p "$1"/usr/lib/dracut/modules.d/01vmklive
cp dracut/vmklive/* "$1"/usr/lib/dracut/modules.d/01vmklive/
}
copy_autoinstaller_files() {
mkdir -p $1/usr/lib/dracut/modules.d/01autoinstaller
cp dracut/autoinstaller/* $1/usr/lib/dracut/modules.d/01autoinstaller/
mkdir -p "$1"/usr/lib/dracut/modules.d/01autoinstaller
cp dracut/autoinstaller/* "$1"/usr/lib/dracut/modules.d/01autoinstaller/
}
install_prereqs() {
copy_void_conf $VOIDHOSTDIR
XBPS_ARCH=$ARCH $XBPS_INSTALL_CMD -r $VOIDHOSTDIR $XBPS_REPOSITORY \
$XBPS_HOST_CACHEDIR -y ${REQUIRED_PKGS}
copy_void_conf "$VOIDHOSTDIR"
XBPS_ARCH=$ARCH "$XBPS_INSTALL_CMD" -r "$VOIDHOSTDIR" ${XBPS_REPOSITORY} \
-c "$XBPS_HOST_CACHEDIR" -y $REQUIRED_PKGS
[ $? -ne 0 ] && die "Failed to install required software, exiting..."
}
install_packages() {
copy_void_conf $ROOTFS
copy_void_conf "$ROOTFS"
XBPS_ARCH=$BASE_ARCH ${XBPS_INSTALL_CMD} -r $ROOTFS \
$XBPS_REPOSITORY $XBPS_CACHEDIR -yn ${PACKAGE_LIST} ${INITRAMFS_PKGS}
XBPS_ARCH=$BASE_ARCH "${XBPS_INSTALL_CMD}" -r "$ROOTFS" \
${XBPS_REPOSITORY} -c "$XBPS_CACHEDIR" -yn $PACKAGE_LIST $INITRAMFS_PKGS
[ $? -ne 0 ] && die "Missing required binary packages, exiting..."
mount_pseudofs
LANG=C XBPS_ARCH=$BASE_ARCH ${XBPS_INSTALL_CMD} -U -r $ROOTFS \
$XBPS_REPOSITORY $XBPS_CACHEDIR -y ${PACKAGE_LIST} ${INITRAMFS_PKGS}
LANG=C XBPS_ARCH=$BASE_ARCH "${XBPS_INSTALL_CMD}" -U -r "$ROOTFS" \
${XBPS_REPOSITORY} -c "$XBPS_CACHEDIR" -y $PACKAGE_LIST $INITRAMFS_PKGS
[ $? -ne 0 ] && die "Failed to install $PACKAGE_LIST"
xbps-reconfigure -r $ROOTFS -f base-files >/dev/null 2>&1
chroot $ROOTFS env -i xbps-reconfigure -f base-files
xbps-reconfigure -r "$ROOTFS" -f base-files >/dev/null 2>&1
chroot "$ROOTFS" env -i xbps-reconfigure -f base-files
# Enable choosen UTF-8 locale and generate it into the target rootfs.
if [ -f $ROOTFS/etc/default/libc-locales ]; then
sed -e "s/\#\(${LOCALE}.*\)/\1/g" -i $ROOTFS/etc/default/libc-locales
if [ -f "$ROOTFS"/etc/default/libc-locales ]; then
sed -e "s/\#\(${LOCALE}.*\)/\1/g" -i "$ROOTFS"/etc/default/libc-locales
fi
chroot $ROOTFS env -i xbps-reconfigure -a
chroot "$ROOTFS" env -i xbps-reconfigure -a
if [ -x installer.sh ]; then
install -Dm755 installer.sh $ROOTFS/usr/sbin/void-installer
install -Dm755 installer.sh "$ROOTFS"/usr/sbin/void-installer
else
install -Dm755 /usr/sbin/void-installer $ROOTFS/usr/sbin/void-installer
install -Dm755 /usr/sbin/void-installer "$ROOTFS"/usr/sbin/void-installer
fi
# Cleanup and remove useless stuff.
rm -rf $ROOTFS/var/cache/* $ROOTFS/run/* $ROOTFS/var/run/*
rm -rf "$ROOTFS"/var/cache/* "$ROOTFS"/run/* "$ROOTFS"/var/run/*
}
copy_include_directory() {
find $INCLUDE_DIRECTORY -mindepth 1 -maxdepth 1 -exec cp -rfpPv {} $ROOTFS/ \;
find "$INCLUDE_DIRECTORY" -mindepth 1 -maxdepth 1 -exec cp -rfpPv {} "$ROOTFS"/ \;
}
generate_initramfs() {
local _args
copy_dracut_files $ROOTFS
copy_autoinstaller_files $ROOTFS
copy_dracut_files "$ROOTFS"
copy_autoinstaller_files "$ROOTFS"
if [ "$BASE_SYSTEM_PKG" = "base-system-systemd" ]; then
_args="--add systemd"
else
_args="--omit systemd"
fi
chroot $ROOTFS env -i /usr/bin/dracut -N --${INITRAMFS_COMPRESSION} \
chroot "$ROOTFS" env -i /usr/bin/dracut -N --"${INITRAMFS_COMPRESSION}" \
--add-drivers "ahci" --force-add "vmklive autoinstaller" ${_args} "/boot/initrd" $KERNELVERSION
[ $? -ne 0 ] && die "Failed to generate the initramfs"
mv $ROOTFS/boot/initrd $BOOT_DIR
cp $ROOTFS/boot/vmlinuz-$KERNELVERSION $BOOT_DIR/vmlinuz
mv "$ROOTFS"/boot/initrd "$BOOT_DIR"
cp "$ROOTFS"/boot/vmlinuz-$KERNELVERSION "$BOOT_DIR"/vmlinuz
}
cleanup_rootfs() {
for f in ${INITRAMFS_PKGS}; do
revdeps=$(xbps-query -r $ROOTFS -X $f)
revdeps=$(xbps-query -r "$ROOTFS" -X $f)
if [ -n "$revdeps" ]; then
xbps-pkgdb -r $ROOTFS -m auto $f
xbps-pkgdb -r "$ROOTFS" -m auto $f
else
xbps-remove -r $ROOTFS -Ry ${f} >/dev/null 2>&1
xbps-remove -r "$ROOTFS" -Ry ${f} >/dev/null 2>&1
fi
done
rm -r $ROOTFS/usr/lib/dracut/modules.d/01vmklive
rm -r $ROOTFS/usr/lib/dracut/modules.d/01autoinstaller
rm -r "$ROOTFS"/usr/lib/dracut/modules.d/01vmklive
rm -r "$ROOTFS"/usr/lib/dracut/modules.d/01autoinstaller
}
generate_isolinux_boot() {
cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/ldlinux.c32 "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/libcom32.c32 "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/libutil.c32 "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/chain.c32 "$ISOLINUX_DIR"
cp -f "$SYSLINUX_DATADIR"/isolinux.bin "$ISOLINUX_DIR"
cp -f "$SYSLINUX_DATADIR"/ldlinux.c32 "$ISOLINUX_DIR"
cp -f "$SYSLINUX_DATADIR"/libcom32.c32 "$ISOLINUX_DIR"
cp -f "$SYSLINUX_DATADIR"/vesamenu.c32 "$ISOLINUX_DIR"
cp -f "$SYSLINUX_DATADIR"/libutil.c32 "$ISOLINUX_DIR"
cp -f "$SYSLINUX_DATADIR"/chain.c32 "$ISOLINUX_DIR"
cp -f isolinux/isolinux.cfg.in "$ISOLINUX_DIR"/isolinux.cfg
cp -f ${SPLASH_IMAGE} "$ISOLINUX_DIR"
sed -i -e "s|@@SPLASHIMAGE@@|$(basename ${SPLASH_IMAGE})|" \
sed -i -e "s|@@SPLASHIMAGE@@|$(basename "${SPLASH_IMAGE}")|" \
-e "s|@@KERNVER@@|${KERNELVERSION}|" \
-e "s|@@KEYMAP@@|${KEYMAP}|" \
-e "s|@@ARCH@@|$BASE_ARCH|" \
-e "s|@@LOCALE@@|${LOCALE}|" \
-e "s|@@BOOT_TITLE@@|${BOOT_TITLE}|" \
-e "s|@@BOOT_CMDLINE@@|${BOOT_CMDLINE}|" \
$ISOLINUX_DIR/isolinux.cfg
"$ISOLINUX_DIR"/isolinux.cfg
}
generate_grub_efi_boot() {
cp -f grub/grub.cfg $GRUB_DIR
cp -f grub/grub_void.cfg.in $GRUB_DIR/grub_void.cfg
sed -i -e "s|@@SPLASHIMAGE@@|$(basename ${SPLASH_IMAGE})|" \
cp -f grub/grub.cfg "$GRUB_DIR"
cp -f grub/grub_void.cfg.in "$GRUB_DIR"/grub_void.cfg
sed -i -e "s|@@SPLASHIMAGE@@|$(basename "${SPLASH_IMAGE}")|" \
-e "s|@@KERNVER@@|${KERNELVERSION}|" \
-e "s|@@KEYMAP@@|${KEYMAP}|" \
-e "s|@@ARCH@@|$BASE_ARCH|" \
-e "s|@@BOOT_TITLE@@|${BOOT_TITLE}|" \
-e "s|@@BOOT_CMDLINE@@|${BOOT_CMDLINE}|" \
-e "s|@@LOCALE@@|${LOCALE}|" $GRUB_DIR/grub_void.cfg
mkdir -p $GRUB_DIR/fonts
cp -f $GRUB_DATADIR/unicode.pf2 $GRUB_DIR/fonts
-e "s|@@LOCALE@@|${LOCALE}|" "$GRUB_DIR"/grub_void.cfg
mkdir -p "$GRUB_DIR"/fonts
cp -f "$GRUB_DATADIR"/unicode.pf2 "$GRUB_DIR"/fonts
modprobe -q loop || :
# Create EFI vfat image.
truncate -s 32M $GRUB_DIR/efiboot.img >/dev/null 2>&1
truncate -s 32M "$GRUB_DIR"/efiboot.img >/dev/null 2>&1
mkfs.vfat -F12 -S 512 -n "grub_uefi" "$GRUB_DIR/efiboot.img" >/dev/null 2>&1
GRUB_EFI_TMPDIR="$(mktemp --tmpdir=$HOME -d)"
LOOP_DEVICE="$(losetup --show --find ${GRUB_DIR}/efiboot.img)"
GRUB_EFI_TMPDIR="$(mktemp --tmpdir="$HOME" -d)"
LOOP_DEVICE="$(losetup --show --find "${GRUB_DIR}"/efiboot.img)"
mount -o rw,flush -t vfat "${LOOP_DEVICE}" "${GRUB_EFI_TMPDIR}" >/dev/null 2>&1
cp -a $IMAGEDIR/boot $VOIDHOSTDIR
xbps-uchroot $VOIDHOSTDIR grub-mkstandalone -- \
cp -a "$IMAGEDIR"/boot "$VOIDHOSTDIR"
xbps-uchroot "$VOIDHOSTDIR" grub-mkstandalone -- \
--directory="/usr/lib/grub/i386-efi" \
--format="i386-efi" \
--output="/tmp/bootia32.efi" \
@ -236,9 +236,9 @@ generate_grub_efi_boot() {
losetup --detach "${LOOP_DEVICE}"
die "Failed to generate EFI loader"
fi
mkdir -p ${GRUB_EFI_TMPDIR}/EFI/BOOT
cp -f $VOIDHOSTDIR/tmp/bootia32.efi ${GRUB_EFI_TMPDIR}/EFI/BOOT/BOOTIA32.EFI
xbps-uchroot $VOIDHOSTDIR grub-mkstandalone -- \
mkdir -p "${GRUB_EFI_TMPDIR}"/EFI/BOOT
cp -f "$VOIDHOSTDIR"/tmp/bootia32.efi "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTIA32.EFI
xbps-uchroot "$VOIDHOSTDIR" grub-mkstandalone -- \
--directory="/usr/lib/grub/x86_64-efi" \
--format="x86_64-efi" \
--output="/tmp/bootx64.efi" \
@ -248,10 +248,10 @@ generate_grub_efi_boot() {
losetup --detach "${LOOP_DEVICE}"
die "Failed to generate EFI loader"
fi
cp -f $VOIDHOSTDIR/tmp/bootx64.efi ${GRUB_EFI_TMPDIR}/EFI/BOOT/BOOTX64.EFI
cp -f "$VOIDHOSTDIR"/tmp/bootx64.efi "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64.EFI
umount "$GRUB_EFI_TMPDIR"
losetup --detach "${LOOP_DEVICE}"
rm -rf $GRUB_EFI_TMPDIR
rm -rf "$GRUB_EFI_TMPDIR"
}
generate_squashfs() {
@ -264,16 +264,16 @@ generate_squashfs() {
fi
mkdir -p "$BUILDDIR/tmp/LiveOS"
truncate -s "$((ROOTFS_SIZE+ROOTFS_FREESIZE))M" \
$BUILDDIR/tmp/LiveOS/ext3fs.img >/dev/null 2>&1
"$BUILDDIR"/tmp/LiveOS/ext3fs.img >/dev/null 2>&1
mkdir -p "$BUILDDIR/tmp-rootfs"
mkfs.ext3 -F -m1 "$BUILDDIR/tmp/LiveOS/ext3fs.img" >/dev/null 2>&1
mount -o loop "$BUILDDIR/tmp/LiveOS/ext3fs.img" "$BUILDDIR/tmp-rootfs"
cp -a $ROOTFS/* $BUILDDIR/tmp-rootfs/
cp -a "$ROOTFS"/* "$BUILDDIR"/tmp-rootfs/
umount -f "$BUILDDIR/tmp-rootfs"
mkdir -p "$IMAGEDIR/LiveOS"
$VOIDHOSTDIR/usr/bin/mksquashfs "$BUILDDIR/tmp" "$IMAGEDIR/LiveOS/squashfs.img" \
-comp ${SQUASHFS_COMPRESSION} || die "Failed to generate squashfs image"
"$VOIDHOSTDIR"/usr/bin/mksquashfs "$BUILDDIR/tmp" "$IMAGEDIR/LiveOS/squashfs.img" \
-comp "${SQUASHFS_COMPRESSION}" || die "Failed to generate squashfs image"
chmod 444 "$IMAGEDIR/LiveOS/squashfs.img"
# Remove rootfs and temporary dirs, we don't need them anymore.
@ -281,7 +281,7 @@ generate_squashfs() {
}
generate_iso_image() {
$VOIDHOSTDIR/usr/bin/xorriso -as mkisofs \
"$VOIDHOSTDIR"/usr/bin/xorriso -as mkisofs \
-iso-level 3 -rock -joliet \
-max-iso9660-filenames -omit-period \
-omit-version-number -relaxed-filenames -allow-lowercase \
@ -290,7 +290,7 @@ generate_iso_image() {
-eltorito-catalog boot/isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot -e boot/grub/efiboot.img -isohybrid-gpt-basdat -no-emul-boot \
-isohybrid-mbr $SYSLINUX_DATADIR/isohdpfx.bin \
-isohybrid-mbr "$SYSLINUX_DATADIR"/isohdpfx.bin \
-output "$CURDIR/$OUTPUT_FILE" "$IMAGEDIR" || die "Failed to generate ISO image"
}
@ -302,7 +302,7 @@ while getopts "a:b:r:c:C:T:Kk:l:i:I:s:S:o:p:h" opt; do
a) BASE_ARCH="$OPTARG";;
b) BASE_SYSTEM_PKG="$OPTARG";;
r) XBPS_REPOSITORY="--repository=$OPTARG $XBPS_REPOSITORY";;
c) XBPS_CACHEDIR="--cachedir=$OPTARG";;
c) XBPS_CACHEDIR="$OPTARG";;
K) readonly KEEP_BUILDDIR=1;;
k) KEYMAP="$OPTARG";;
l) LOCALE="$OPTARG";;
@ -326,8 +326,8 @@ ARCH=$(xbps-uhelper arch)
# Set defaults
: ${BASE_ARCH:=$(xbps-uhelper arch 2>/dev/null || uname -m)}
: ${XBPS_CACHEDIR:=-c $(pwd -P)/xbps-cachedir-${BASE_ARCH}}
: ${XBPS_HOST_CACHEDIR:=-c $(pwd -P)/xbps-cachedir-${ARCH}}
: ${XBPS_CACHEDIR:="$(pwd -P)"/xbps-cachedir-${BASE_ARCH}}
: ${XBPS_HOST_CACHEDIR:="$(pwd -P)"/xbps-cachedir-${ARCH}}
: ${KEYMAP:=us}
: ${LOCALE:=en_US.UTF-8}
: ${INITRAMFS_COMPRESSION:=xz}
@ -345,13 +345,14 @@ fi
readonly CURDIR="$PWD"
ISO_VOLUME="VOID_LIVE"
if [ -n "$ROOTDIR" ]; then
BUILDDIR=$(mktemp --tmpdir="$ROOTDIR" -d)
else
BUILDDIR=$(mktemp --tmpdir="$(pwd -P)" -d)
fi
BUILDDIR=$(readlink -f $BUILDDIR)
BUILDDIR=$(readlink -f "$BUILDDIR")
IMAGEDIR="$BUILDDIR/image"
ROOTFS="$IMAGEDIR/rootfs"
VOIDHOSTDIR="$BUILDDIR/void-host"
@ -363,8 +364,8 @@ CURRENT_STEP=0
STEP_COUNT=9
[ -n "${INCLUDE_DIRECTORY}" ] && ((STEP_COUNT=STEP_COUNT+1))
: ${SYSLINUX_DATADIR:=$VOIDHOSTDIR/usr/share/syslinux}
: ${GRUB_DATADIR:=$VOIDHOSTDIR/usr/share/grub}
: ${SYSLINUX_DATADIR:="$VOIDHOSTDIR"/usr/share/syslinux}
: ${GRUB_DATADIR:="$VOIDHOSTDIR"/usr/share/grub}
: ${SPLASH_IMAGE:=data/splash.png}
: ${XBPS_INSTALL_CMD:=xbps-install}
: ${XBPS_REMOVE_CMD:=xbps-remove}
@ -373,16 +374,16 @@ STEP_COUNT=9
: ${XBPS_UHELPER_CMD:=xbps-uhelper}
: ${XBPS_RECONFIGURE_CMD:=xbps-reconfigure}
mkdir -p $ROOTFS $VOIDHOSTDIR $ISOLINUX_DIR $GRUB_DIR
mkdir -p "$ROOTFS" "$VOIDHOSTDIR" "$ISOLINUX_DIR" "$GRUB_DIR"
print_step "Synchronizing XBPS repository data..."
copy_void_keys $ROOTFS
copy_void_keys $VOIDHOSTDIR
XBPS_ARCH=$BASE_ARCH $XBPS_INSTALL_CMD -r $ROOTFS ${XBPS_REPOSITORY} -S
XBPS_ARCH=$ARCH $XBPS_INSTALL_CMD -r $VOIDHOSTDIR $XBPS_REPOSITORY -S
copy_void_keys "$ROOTFS"
copy_void_keys "$VOIDHOSTDIR"
XBPS_ARCH=$BASE_ARCH $XBPS_INSTALL_CMD -r "$ROOTFS" ${XBPS_REPOSITORY} -S
XBPS_ARCH=$ARCH $XBPS_INSTALL_CMD -r "$VOIDHOSTDIR" ${XBPS_REPOSITORY} -S
_linux_series=$(XBPS_ARCH=$BASE_ARCH $XBPS_QUERY_CMD -r $ROOTFS ${XBPS_REPOSITORY:=-R} -x linux|head -1)
_kver=$(XBPS_ARCH=$BASE_ARCH $XBPS_QUERY_CMD -r $ROOTFS ${XBPS_REPOSITORY:=-R} -p pkgver ${_linux_series})
_linux_series=$(XBPS_ARCH=$BASE_ARCH $XBPS_QUERY_CMD -r "$ROOTFS" ${XBPS_REPOSITORY:=-R} -x linux|head -1)
_kver=$(XBPS_ARCH=$BASE_ARCH $XBPS_QUERY_CMD -r "$ROOTFS" ${XBPS_REPOSITORY:=-R} -p pkgver ${_linux_series})
KERNELVERSION=$($XBPS_UHELPER_CMD getpkgversion ${_kver})
: ${OUTPUT_FILE="void-live-${BASE_ARCH}-${KERNELVERSION}-$(date +%Y%m%d).iso"}
@ -391,8 +392,8 @@ print_step "Installing software to generate the image: ${REQUIRED_PKGS} ..."
install_prereqs
mkdir -p "$ROOTFS"/etc
[ -s data/motd ] && cp data/motd $ROOTFS/etc
[ -s data/issue ] && cp data/issue $ROOTFS/etc
[ -s data/motd ] && cp data/motd "$ROOTFS"/etc
[ -s data/issue ] && cp data/issue "$ROOTFS"/etc
print_step "Installing void pkgs into the rootfs: ${PACKAGE_LIST} ..."
install_packages
@ -421,4 +422,6 @@ print_step "Generating ISO image..."
generate_iso_image
hsize=$(du -sh "$CURDIR/$OUTPUT_FILE"|awk '{print $1}')
info_msg "Created $(readlink -f $CURDIR/$OUTPUT_FILE) ($hsize) successfully."
info_msg "Created $(readlink -f "$CURDIR"/"$OUTPUT_FILE") ($hsize) successfully."