#!/bin/bash

###
## Wrapper for running calamares on live media
###

set -x

true "$0: START"

#ls -la /run/live/medium/live/filesystem.squashfs
#ls -la /run/initramfs/live/LiveOS/squashfs.img

## dracut          : /run/live/medium/live/filesystem.squashfs
## initramfs-tools?: /run/initramfs/live/LiveOS/squashfs.img
if test ! -e /run/live/medium/live/filesystem.squashfs ; then
  if test -e /run/initramfs/live/LiveOS/squashfs.img ; then
    mkdir --parents /run/live/medium/live/
    ln -s /run/initramfs/live/LiveOS/squashfs.img /run/live/medium/live/filesystem.squashfs
  fi
fi

## Stale file left behind by live-build that messes with partitioning.
## TODO: Is this still required?
if test -f /etc/fstab ; then
  mv --verbose /etc/fstab /etc/fstab.orig.calamares
fi

#if ! test -f /etc/fstab ; then
  ## Restore stale fstab, for what it's worth.
  #mv --verbose /etc/fstab.orig.calamares /etc/fstab
#fi

true "$0: END"
