qubes-linux-template-builder/qubeize_image

131 lines
3.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
if [ "$VERBOSE" -ge 2 -o "$DEBUG" == "1" ]; then
set -x
fi
2015-08-10 20:59:53 +00:00
set -e
# ------------------------------------------------------------------------------
# Configurations and Conditionals
# ------------------------------------------------------------------------------
export CLEANIMG="$1"
export NAME="$2"
export LC_ALL=POSIX
. ./builder_setup >/dev/null
. ./umount_kill.sh >/dev/null
if [ $# -eq 0 ]; then
echo "usage $0 <clean_image_file> <template_name>"
exit
fi
if [ "x$CLEANIMG" = x ]; then
echo "Image file not specified!"
exit 1
fi
if [ "x$NAME" = x ]; then
echo "Name not given!"
exit 1
fi
ID=$(id -ur)
if [ $ID != 0 ] ; then
echo "This script should be run as root user."
exit 1
fi
if [ "$VERBOSE" == "1" ]; then
export YUM_OPTS="$YUM_OPTS -q"
fi
# ------------------------------------------------------------------------------
# Cleanup function
# ------------------------------------------------------------------------------
function cleanup() {
2015-02-10 15:09:04 +00:00
errval=$?
trap - ERR
trap
umount_kill "$PWD/mnt" || true
losetup -d ${IMG_LOOP}
2015-02-10 15:09:04 +00:00
exit $errval
}
trap cleanup ERR
# ------------------------------------------------------------------------------
# Mount qubeized_image
# ------------------------------------------------------------------------------
export IMG="qubeized_images/$NAME/root.img"
mkdir -p "qubeized_images/$NAME"
if [ "$TRAVIS" = "true" ]; then
echo "--> Moving $CLEANIMG to $IMG (save space on Travis-CI)..."
mv "$CLEANIMG" "$IMG" || exit 1
else
echo "--> Copying $CLEANIMG to $IMG..."
cp "$CLEANIMG" "$IMG" || exit 1
fi
echo "--> Mounting $IMG"
mkdir -p mnt
if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then
IMG_LOOP=$(losetup -P -f --show "$IMG")
IMG_DEV=${IMG_LOOP}p1
else
IMG_LOOP=$(losetup -f --show "$IMG")
IMG_DEV=${IMG_LOOP}
fi
mount "$IMG_DEV" mnt || exit 1
export INSTALLDIR=mnt
# ------------------------------------------------------------------------------
# Run qubeize script
# ------------------------------------------------------------------------------
2015-02-10 15:09:04 +00:00
"$SCRIPTSDIR/04_install_qubes.sh"
# ------------------------------------------------------------------------------
# Create App Menus
# ------------------------------------------------------------------------------
echo "--> Choosing appmenus whitelists..."
_appmenus_dir="${APPMENUS_DIR:-${SCRIPTSDIR}}"
rm -f appmenus
if [ -d "${_appmenus_dir}/appmenus_${DIST}_${TEMPLATE_FLAVOR}" ]; then
ln -s "${_appmenus_dir}/appmenus_${DIST}_${TEMPLATE_FLAVOR}" appmenus
elif [ -d "${_appmenus_dir}/appmenus_$DIST" ]; then
ln -s "${_appmenus_dir}/appmenus_$DIST" appmenus
elif [ -d "${_appmenus_dir}/appmenus" ]; then
ln -s "${_appmenus_dir}/appmenus" appmenus
else
ln -s "appmenus_generic" appmenus
fi
# ------------------------------------------------------------------------------
# Link directories so they can be mounted
# ------------------------------------------------------------------------------
echo "--> Linking /home to /rw/home..."
mv mnt/home mnt/home.orig
mkdir mnt/home
echo "--> Linking /usr/local to /rw/usrlocal..."
mv mnt/usr/local mnt/usr/local.orig
ln -sf /rw/usrlocal mnt/usr/local
echo "Reducing image size (calling cleanup_image)..."
ls -als $IMG
./cleanup_image "$INSTALLDIR"
ls -als $IMG
# ------------------------------------------------------------------------------
# Finsh - unmount image
# ------------------------------------------------------------------------------
echo "--> Unmounting $IMG"
2015-02-10 15:09:04 +00:00
umount_kill "$PWD/mnt" || true
losetup -d ${IMG_LOOP}
echo "Qubeized image stored at: $IMG"
chown -R --reference=. qubeized_images/$NAME