2016-04-20 08:23:36 +00:00
|
|
|
#!/bin/bash
|
2010-04-05 22:25:37 +00:00
|
|
|
|
2015-07-28 20:47:40 +00:00
|
|
|
if [ "$VERBOSE" -ge 2 -o "$DEBUG" == "1" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2015-08-10 20:59:53 +00:00
|
|
|
set -e
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Configurations and Conditionals
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
export CLEANIMG="$1"
|
|
|
|
export NAME="$2"
|
2014-07-28 16:53:49 +00:00
|
|
|
export LC_ALL=POSIX
|
2010-04-05 22:25:37 +00:00
|
|
|
|
2014-07-26 02:30:31 +00:00
|
|
|
. ./builder_setup >/dev/null
|
2014-10-14 21:04:42 +00:00
|
|
|
. ./umount_kill.sh >/dev/null
|
2013-02-16 15:00:50 +00:00
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
if [ $# -eq 0 ]; then
|
2014-10-14 16:02:12 +00:00
|
|
|
echo "usage $0 <clean_image_file> <template_name>"
|
|
|
|
exit
|
2010-04-05 22:25:37 +00:00
|
|
|
fi
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
if [ "x$CLEANIMG" = x ]; then
|
|
|
|
echo "Image file not specified!"
|
|
|
|
exit 1
|
2010-04-05 22:25:37 +00:00
|
|
|
fi
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
if [ "x$NAME" = x ]; then
|
|
|
|
echo "Name not given!"
|
|
|
|
exit 1
|
2010-04-05 22:25:37 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
ID=$(id -ur)
|
|
|
|
|
|
|
|
if [ $ID != 0 ] ; then
|
2014-10-14 16:02:12 +00:00
|
|
|
echo "This script should be run as root user."
|
|
|
|
exit 1
|
2010-04-05 22:25:37 +00:00
|
|
|
fi
|
|
|
|
|
2012-11-18 03:01:49 +00:00
|
|
|
if [ "$VERBOSE" == "1" ]; then
|
2014-10-14 16:02:12 +00:00
|
|
|
export YUM_OPTS="$YUM_OPTS -q"
|
2012-11-18 03:01:49 +00:00
|
|
|
fi
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Cleanup function
|
|
|
|
# ------------------------------------------------------------------------------
|
2012-11-17 11:55:05 +00:00
|
|
|
function cleanup() {
|
2015-02-10 15:09:04 +00:00
|
|
|
errval=$?
|
|
|
|
trap - ERR
|
|
|
|
trap
|
|
|
|
umount_kill "$PWD/mnt" || true
|
2017-06-14 08:53:22 +00:00
|
|
|
losetup -d ${IMG_LOOP}
|
2015-02-10 15:09:04 +00:00
|
|
|
exit $errval
|
2012-11-17 11:55:05 +00:00
|
|
|
}
|
|
|
|
trap cleanup ERR
|
2010-04-05 22:25:37 +00:00
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Mount qubeized_image
|
|
|
|
# ------------------------------------------------------------------------------
|
2015-03-09 12:38:09 +00:00
|
|
|
export IMG="qubeized_images/$NAME/root.img"
|
|
|
|
mkdir -p "qubeized_images/$NAME"
|
2014-10-14 16:02:12 +00:00
|
|
|
|
2014-10-19 05:18:58 +00:00
|
|
|
echo "--> Copying $CLEANIMG to $IMG..."
|
|
|
|
cp "$CLEANIMG" "$IMG" || exit 1
|
2010-04-05 22:25:37 +00:00
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
echo "--> Mounting $IMG"
|
2010-04-05 22:25:37 +00:00
|
|
|
mkdir -p mnt
|
2017-06-14 08:53:22 +00:00
|
|
|
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
|
2013-01-25 08:03:51 +00:00
|
|
|
export INSTALLDIR=mnt
|
2010-04-05 22:25:37 +00:00
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Run qubeize script
|
|
|
|
# ------------------------------------------------------------------------------
|
2015-02-10 15:09:04 +00:00
|
|
|
"$SCRIPTSDIR/04_install_qubes.sh"
|
2010-04-05 22:25:37 +00:00
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Create App Menus
|
|
|
|
# ------------------------------------------------------------------------------
|
2012-06-22 19:12:57 +00:00
|
|
|
echo "--> Choosing appmenus whitelists..."
|
2017-09-06 16:59:42 +00:00
|
|
|
_appmenus_dir="${APPMENUS_DIR:-${SCRIPTSDIR}}"
|
2012-06-22 19:12:57 +00:00
|
|
|
rm -f appmenus
|
2015-04-28 01:20:29 +00:00
|
|
|
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
|
2012-06-22 19:12:57 +00:00
|
|
|
else
|
2014-10-14 16:02:12 +00:00
|
|
|
ln -s "appmenus_generic" appmenus
|
2012-06-22 19:12:57 +00:00
|
|
|
fi
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Link directories so they can be mounted
|
|
|
|
# ------------------------------------------------------------------------------
|
2010-10-04 17:59:11 +00:00
|
|
|
echo "--> Linking /home to /rw/home..."
|
|
|
|
mv mnt/home mnt/home.orig
|
2015-03-10 03:19:28 +00:00
|
|
|
mkdir mnt/home
|
2010-10-04 17:59:11 +00:00
|
|
|
|
|
|
|
echo "--> Linking /usr/local to /rw/usrlocal..."
|
|
|
|
mv mnt/usr/local mnt/usr/local.orig
|
|
|
|
ln -sf /rw/usrlocal mnt/usr/local
|
|
|
|
|
2017-06-14 08:53:22 +00:00
|
|
|
echo "Reducing image size (calling cleanup_image)..."
|
|
|
|
ls -als $IMG
|
|
|
|
./cleanup_image "$INSTALLDIR"
|
|
|
|
ls -als $IMG
|
|
|
|
|
2014-10-14 16:02:12 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Finsh - unmount image
|
|
|
|
# ------------------------------------------------------------------------------
|
2010-04-05 22:25:37 +00:00
|
|
|
echo "--> Unmounting $IMG"
|
2015-02-10 15:09:04 +00:00
|
|
|
umount_kill "$PWD/mnt" || true
|
2017-06-14 08:53:22 +00:00
|
|
|
losetup -d ${IMG_LOOP}
|
2010-04-05 22:25:37 +00:00
|
|
|
|
|
|
|
echo "Qubeized image stored at: $IMG"
|
|
|
|
|
2015-03-10 03:19:28 +00:00
|
|
|
chown -R --reference=. qubeized_images/$NAME
|