#!/bin/bash

# This tells shellcheck not to check this file
# shellcheck disable=SC1091
. /etc/LiteDistroBuilder/LiteDistroBuilder.version

# checking to make sure script is running with root privileges
if [ "$(whoami)" != "root" ]; then
    echo "Need to be root or run with sudo. Exiting."
    exit 1
fi

#create LiteDistroBuilder-firstboot script and populate with at least removal of the calamares*.desktop file from users Desktop and fix for recovery mode
    cat > /etc/init.d/LiteDistroBuilder-firstboot <<FOO
#! /bin/sh
### BEGIN INIT INFO
# Provides:          LiteDistroBuilder-firstboot
# Required-Start:    \$remote_fs \$syslog \$all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Run firstboot items for LiteDistroBuilder after a remastered system has been installed
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
        #REM302
        if [ "\`cat /proc/cmdline | grep casper\`" = "" ]; then
            [ "\$VERBOSE" != no ] && log_begin_msg "Running LiteDistroBuilder-firstboot"
            update-rc.d -f LiteDistroBuilder-firstboot remove
            sed -i -e 's/root:x:/root:!:/g' /etc/shadow
            rm -rf /home/*/*/install-linuxlite.desktop
            rm -rf /usr/share/applications/install-linuxlite.desktop
            rm -rf /home/*/*/install-linuxlite-oem.desktop
            rm -rf /usr/share/applications/install-linuxlite-oem.desktop
            rm -f /etc/lightdm/lightdm.conf.d/99-autologin.conf
            rm -rf /etc/rc.local
            # Set country-specific apt mirror via GeoIP (primary) or timezone (fallback)
            CC=\$(wget -qO- -T 10 http://geoip.ubuntu.com/lookup 2>/dev/null | sed -n 's/.*<CountryCode>\([^<]*\)<.*/\1/p' | tr A-Z a-z)
            if [ -z "\$CC" ]; then
                TZ=\$(cat /root/.calamares-tz 2>/dev/null || readlink -f /etc/localtime | sed 's|.*/zoneinfo/||' || cat /etc/timezone 2>/dev/null)
                CC=\$(grep -P "^\w+\t[^\t]+\t\$TZ" /usr/share/zoneinfo/zone.tab | cut -f1 | tr A-Z a-z)
            fi
            [ -n "\$CC" ] && find /etc/apt -type f \( -name "*.sources" -o -name "*.list" \) -exec sed -i "s|https\?://[^/]*/ubuntu/\?|http://\${CC}.archive.ubuntu.com/ubuntu/|g" {} \;
            rm -f /root/.calamares-tz
            rm -f /root/apt.tar.gz
            #apt-get -y -q purge firefox-locale-en libreoffice-help-en-* &> /dev/null
            #update-apt-xapian-index -vf
            #Place your custom commands below this line
            #Example to remove LiteDistroBuilder and clean up packages

            #apt-get purge litedistrobuilder --yes --assume-yes
            #apt-get --yes --assume-yes autoremove

            #Place your custom commands above this line
            ES=\$?
            [ "\$VERBOSE" != no ] && log_end_msg \$ES
            return \$ES
        fi

        


} 

case "\$1" in
    start)
        do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '\$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: \$0 start|stop" >&2
        exit 3
        ;;
esac

FOO


# load the LiteDistroBuilder.conf file
# This tells shellcheck not to check this file
# shellcheck disable=SC1091
. /etc/LiteDistroBuilder.conf

# if the LiteDistroBuilder.conf file is incorrect or missing, make sure to set defaults

if [ "$LIVEUSER" = "" ]; then
    #Somebody must have removed the username from the configuration file
    echo 
    #this is a custom live user
    LIVEUSER="custom"
fi

#make sure live user is all lowercase
LIVEUSER=$(echo $LIVEUSER | awk '{print tolower ($0)}')

if [ "$WORKDIR" = "" ]; then
    BASEWORKDIR="/home/LiteDistroBuilder"
    WORKDIR="/home/LiteDistroBuilder/LiteDistroBuilder"
else
    BASEWORKDIR="$WORKDIR"
    WORKDIR="$WORKDIR/LiteDistroBuilder"
fi

if [ ! -d $WORKDIR ]; then
    mkdir -p $WORKDIR
fi

#setup name variable for $CUSTOMLOG based on $CUSTOMISO name
CUSTOMLOG=${CUSTOMISO%.iso}

if [ -f $WORKDIR/"$CUSTOMLOG.log" ]; then
    rm -f $WORKDIR/"$CUSTOMLOG.log" &> /dev/null
fi

touch $WORKDIR/"$CUSTOMLOG.log"

# New log/debug log proc. Code by Carlos P. Rodriguez
log-msg() {
	
	if [ "$ENABLEDEBUGLOG" = "0" ]; then
       echo "$1"
       echo "$1" >>$WORKDIR/"$CUSTOMLOG.log"	
    else
       if [[ -n "$1" ]]; then
           echo "$1"
           IN="$1"
       else
           while read -r INPUT; do
               IN="$IN\n$INPUT"
           done
       fi
       # shellcheck disable=SC2128
       echo -e "[$(date --rfc-3339=seconds)], ${BASH_LINENO}: $IN" >>$WORKDIR/"$CUSTOMLOG.log"
    fi
}

if [ "$LIVECDLABEL" = "" ]; then
    LIVECDLABEL="Custom Live CD"
fi

if [ "$LIVECDURL" = "" ]; then
    LIVECDURL=""
fi

if [ "$SQUASHFSOPTS" = "" ]; then
    SQUASHFSOPTS="-no-recovery -always-use-fragments -b 1M -no-duplicates -comp xz -Xbcj x86"
fi

if [[ "$ENABLEDEBUGLOG" = "0" ||  "$ENABLEDEBUGLOG" = "1" ]]; then
    echo
else
    ENABLEDEBUGLOG="0"
fi

if [ "$2" = "cdfs" ]; then
    log-msg "Creating the cd filesystem only"
elif [ "$2" = "iso" ]; then
    log-msg "Creating the iso file only"
elif [ "$2" = "" ]; then
    echo " "
else
    CUSTOMISO="$2"
fi

if [ "$3" != "" ]; then
    CUSTOMISO="$3"
fi

if [ "$CUSTOMISO" = "" ]; then
    CUSTOMISO="custom$1.iso"
fi

CODENAME=$(lsb_release -c --short)
if [ "$SOURCESLIST" = "" ]; then
    SOURCESLIST="deb http://archive.ubuntu.com/ubuntu $CODENAME main restricted
deb http://archive.ubuntu.com/ubuntu $CODENAME universe
deb http://archive.ubuntu.com/ubuntu $CODENAME-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu $CODENAME partner
deb http://archive.ubuntu.com/ubuntu $CODENAME-security main restricted
deb http://archive.ubuntu.com/ubuntu $CODENAME-security universe
deb http://archive.ubuntu.com/ubuntu $CODENAME-security multiverse
## Major bug fix updates produced after the final release of the distribution.
deb http://archive.ubuntu.com/ubuntu $CODENAME-updates main restricted
deb http://archive.ubuntu.com/ubuntu $CODENAME-updates universe
deb http://archive.ubuntu.com/ubuntu $CODENAME-updates multiverse"
fi

case $1  in

    clean)
        echo "Removing the build directory now..."
        rm -rf $WORKDIR
        echo "Cleaning apt cache..."
        apt-get clean -y
        echo "Done...Exiting"
        exit 0
        ;;

    dist)
        log-msg "Distribution Mode Selected"
        ;;


    *)
        # This tells shellcheck to not worry about $LiteDistroBuilderVERSION not being assigned
        # as it comes from the /etc/LiteDistroBuilder.version file
        # shellcheck disable=SC2154
        echo "Usage of LiteDistroBuilder $LiteDistroBuilderVERSION is as follows:"
        echo " "
        echo "   sudo LiteDistroBuilder clean|dist [cdfs|iso] [filename.iso]"
        echo " "
        echo " "
        echo "Examples:"
        echo " "
        echo " "
        echo "   sudo LiteDistroBuilder clean    (to clean up temporary files of LiteDistroBuilder)"
        echo " "
        echo "   sudo LiteDistroBuilder dist     (to make a distributable livecd/dvd of your system)"
        echo " "
        echo "   sudo LiteDistroBuilder dist cdfs"
        echo "                             (to make a distributable livecd/dvd filesystem only)"
        echo " "
        echo "   sudo LiteDistroBuilder dist iso custom.iso"
        echo "                             (to make a distributable iso named custom.iso but only"
        echo "                              if the cdfs is already present)"
        echo " "
        echo "   cdfs and iso options should only be used if you wish to modify something on the"
        echo "   cd before the iso is created.  An example of this would be to modify the isolinux"
        echo "   portion of the livecd/dvd"
        echo " "
        exit 1
        ;;

esac

cdfs (){
#Cleaning build machine Apt
log-msg "Cleaning build machine Apt"
find /etc/apt -type f -iname \*.save -delete &> /dev/null
find /etc/apt -type f -iname \*~ -delete &> /dev/null
apt-get update &> /dev/null
    
#Cleaning systemd journal to save ISO image space
log-msg "Cleaning systemd journal to save ISO image space"
journalctl --vacuum-time=10d &> /dev/null

log-msg "Enabling LiteDistroBuilder-firstboot"
chmod 755 /etc/init.d/LiteDistroBuilder-firstboot
update-rc.d LiteDistroBuilder-firstboot defaults

log-msg "Checking filesystem type of the Working Folder"
DIRTYPE=$(df -T -P $WORKDIR | grep "^\/dev" | awk '{print $2}')
log-msg "$WORKDIR is on a $DIRTYPE filesystem"


    #Ensure casper user-uid is set to 1000 (default for Resolute)
    #Previous builds may have changed this to 990 which is outside UID_MIN and breaks user creation
    log-msg "Ensuring casper user-uid is set to 1000"
    sed -i -e 's@user-uid [0-9]*@user-uid 1000@' /usr/share/initramfs-tools/scripts/casper-bottom/*adduser

    #Fix casper autologin backtick bug so lightdm autologin is properly configured
    log-msg "Fixing casper autologin script"
    sed -i 's/`grep/grep/g; s/File`/File/g' /usr/share/initramfs-tools/scripts/casper-bottom/15autologin

    #make sure there is no telemetry - Linux Lite
    log-msg "Making sure there is no telemetry installed in Linux Lite"
    apt-get -y -q remove ubuntu-report apport whoopsie &> /dev/null
    echo "[*] Resolving \"metrics.ubuntu.com\" to localhost"
    echo 127.0.0.1 www.metrics.ubuntu.com >>/etc/hosts
    echo 127.0.0.1 metrics.ubuntu.com >>/etc/hosts
    echo "[*] Resolving \"popcon.ubuntu.com\" to localhost"
    echo 127.0.0.1 www.popcon.ubuntu.com >>/etc/hosts
    echo 127.0.0.1 popcon.ubuntu.com >>/etc/hosts
    
    #removing popularity-contest as it is telemetry
    log-msg "Making sure popularity contest is not installed"
    apt-get -y -q remove popularity-contest &> /dev/null

    #removing syslinux-themes as it causes problems
    log-msg "Making sure syslinux-themes is not installed"
    apt-get -y -q purge syslinux-themes* &> /dev/null

    #removing gnome-initial-setup as it causes problems
    log-msg "Making sure gnome-initial-setup is not installed"
    apt-get -y -q purge gnome-initial-setup &> /dev/null

    #Ensure Calamares installer and Linux Lite settings are installed
    log-msg "Installing the Calamares installer"
    apt-get -y -q purge ubiquity-casper ubiquity ubiquity-ubuntu-artwork ubiquity-frontend-gtk &> /dev/null
    if ! dpkg -s calamares-settings-linuxlite &> /dev/null; then
        log-msg "calamares-settings-linuxlite is not installed. Please install it first, Exiting"
        exit 1
    fi
    if apt-get -y -q install calamares > /dev/null; then
        log-msg "Calamares installer Installed"
    else
        log-msg "Calamares installer failed to Install, Exiting"
        exit 1
    fi
    chmod +x /home/linux/Desktop/*.desktop &> /dev/null
    chmod +x /etc/skel/Desktop/*.desktop &> /dev/null

    #Detect Architecture and export so it can be used in the ISO code block as
    #well as the CDFS block. This way we only have to check and set it once as
    #it is used in both code blocks.
    log-msg "Checking and setting the Architecture of the system"
    ARCH=$(dpkg --print-architecture)
    export ARCH

    # Fixing some permissions in /etc/skel - NEW 21/10/23
    chmod +x /etc/skel/Desktop/*.desktop

    log-msg "Cleaning System before building"
    log-msg "Cleaning Apt package cache"
    apt-get clean
    rm -rf /opt/teamviewer/config/global.conf

    #Removing swapfile
    log-msg "Removing Swapfile"
    swapoff -v /swapfile &> /dev/null
    rm /swapfile &> /dev/null
    sed -i '/swapfile/d' /etc/fstab &> /dev/null

    log-msg "Renaming Distro to $LIVECDLABEL"
    sed -i 's/PRETTY_NAME=.*/PRETTY_NAME="LIVECDLABEL"/g' /usr/lib/os-release
    sed -i "s/LIVECDLABEL/$LIVECDLABEL/g" /usr/lib/os-release

    # Check if they are using lightdm and if it is setup properly for the live default session
    # [ "`grep lightdm /etc/X11/default-display-manager`" != "" ] && [ ! -f /etc/lightdm/lightdm.conf ] && [ ! -f /usr/share/xsessions/ubuntu.desktop ] && echo "Lightdm not setup properly. You must set your default desktop with lightdm prior to remastering" &&  echo "Lightdm not setup properly. You must set your default desktop with lightdm prior to remastering" >> $WORKDIR/"$CUSTOMLOG.log" && exit 1

    sleep 1


    # Step 3 - Create the CD tree in $WORKDIR/ISOTMP
    log-msg "Checking if the $WORKDIR folder has been created"
    if [ -d "$WORKDIR/dummysys" ]; then
        rm -rf $WORKDIR/dummysys/var/*
        rm -rf $WORKDIR/dummysys/etc/*
        rm -rf $WORKDIR/dummysys/run/*
        rm -rf $WORKDIR/ISOTMP/{grub,.disk}
    else
        log-msg "Creating $WORKDIR folder tree"
        mkdir -p $WORKDIR/ISOTMP/{casper,preseed}
        mkdir -p $WORKDIR/dummysys/{dev,etc,proc,tmp,sys,mnt,media/cdrom,var}
        rsync -a /dev/urandom $WORKDIR/dummysys/dev/
        if [ -d /run ]; then
            mkdir -p $WORKDIR/dummysys/run
        fi
        chmod ug+rwx,o+rwt $WORKDIR/dummysys/tmp

    fi

    log-msg "Creating $WORKDIR/ISOTMP folder tree"
    mkdir -p $WORKDIR/ISOTMP/{install,.disk}

    log-msg "Copying /var and /etc to temp area and excluding extra files  ... this will take a while so be patient"

    if [ "$EXCLUDES" != "" ]; then
        for addvar in $EXCLUDES ; do
            # This needs looking into need command args array
            # shellcheck disable=SC2089,SC2090
            VAREXCLUDES="$VAREXCLUDES --exclude='$addvar' "
        done
    fi
 
    # This needs looked into need command args array
    # shellcheck disable=SC2086,SC2090
    rsync --exclude='*.log.*' --exclude='*~' --exclude='*.pid' --exclude='*.bak' --exclude='*.[0-9].gz' --exclude='*.deb' $VAREXCLUDES-a /var/. "$WORKDIR"/dummysys/var/.
    # This needs looked into need command args array
    # shellcheck disable=SC2086,SC2090
    rsync $VAREXCLUDES-a /etc/. "$WORKDIR"/dummysys/etc/.

    # Disable firstboot on the build VM immediately after rsync captured it
    # This prevents firstboot from firing if the build VM is rebooted
    log-msg "Disabling LiteDistroBuilder-firstboot on build VM (kept in dummysys)"
    update-rc.d -f LiteDistroBuilder-firstboot remove
    chmod 644 /etc/init.d/LiteDistroBuilder-firstboot

    # Fix /etc/skel permissions in dummysys — home dir perms (700) break casper user creation
    log-msg "Fixing /etc/skel permissions in dummysys"
    find $WORKDIR/dummysys/etc/skel -type d -exec chmod 755 {} \;
    find $WORKDIR/dummysys/etc/skel -type f -exec chmod 644 {} \;
    chmod +x $WORKDIR/dummysys/etc/skel/Desktop/*.desktop &> /dev/null
    chmod +x $WORKDIR/dummysys/etc/skel/.config/folderlangs.sh &> /dev/null
    chmod +x $WORKDIR/dummysys/etc/skel/.config/home-open.sh &> /dev/null
    chown -R root:root $WORKDIR/dummysys/etc/skel

    # Clean /etc/skel/.cache to prevent broken symlinks and machine-specific
    # files from breaking casper user creation (user-setup-apply fails on these)
    log-msg "Cleaning /etc/skel/.cache from dummysys"
    rm -rf $WORKDIR/dummysys/etc/skel/.cache &> /dev/null

    # Remove user-dirs config and English-named xdg directories so
    # xdg-user-dirs-update creates locale-appropriate folder names
    # (Schreibtisch, Dokumente, etc.) on first login
    log-msg "Removing user-dirs config and English xdg dirs from dummysys skel"
    rm -f $WORKDIR/dummysys/etc/skel/.config/user-dirs.locale &> /dev/null
    rm -f $WORKDIR/dummysys/etc/skel/.config/user-dirs.dirs &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/skel/Documents &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/skel/Downloads &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/skel/Music &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/skel/Pictures &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/skel/Public &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/skel/Templates &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/skel/Videos &> /dev/null

    # Allow live user to perform privileged actions without authentication (polkit)
    mkdir -p $WORKDIR/dummysys/etc/polkit-1/localauthority/50-local.d
    cat > $WORKDIR/dummysys/etc/polkit-1/localauthority/50-local.d/live-session.pkla <<POLKITEOF
[Live Session]
Identity=unix-user:$LIVEUSER
Action=*
ResultAny=yes
ResultInactive=yes
ResultActive=yes
POLKITEOF

    # Also create JavaScript rules file for newer polkitd (Ubuntu 24.04+)
    mkdir -p $WORKDIR/dummysys/etc/polkit-1/rules.d
    cat > $WORKDIR/dummysys/etc/polkit-1/rules.d/49-live-session.rules <<POLKITJSEOF
polkit.addRule(function(action, subject) {
    if (subject.user == "$LIVEUSER") {
        return polkit.Result.YES;
    }
});
POLKITJSEOF

    # Configure lightdm autologin for live session.
    # Casper's 15autologin script has a backtick bug that prevents it from
    # ever configuring lightdm autologin, so we set it explicitly here.
    # Clear any conf.d overrides that may conflict, then write autologin
    # to both lightdm.conf and conf.d to cover all priority orderings.
    rm -f $WORKDIR/dummysys/etc/lightdm/lightdm.conf.d/*.conf &> /dev/null
    mkdir -p $WORKDIR/dummysys/etc/lightdm/lightdm.conf.d
    cat > $WORKDIR/dummysys/etc/lightdm/lightdm.conf <<LDMEOF
[LightDM]

[Seat:*]
user-session=xfce
allow-guest=false
autologin-guest=false
autologin-user=$LIVEUSER
autologin-user-timeout=0
greeter-setup-script=/usr/bin/numlockx on

[SeatDefaults]
allow-guest=false
autologin-guest=false
autologin-user=$LIVEUSER
autologin-user-timeout=0
LDMEOF
    cat > $WORKDIR/dummysys/etc/lightdm/lightdm.conf.d/lightdm-autologin-greeter.conf <<LDMEOF2
[Seat:*]
autologin-user=$LIVEUSER
autologin-user-timeout=0
LDMEOF2

    #Adding packages location to sources
    #ARCH=$(archdetect | awk -F "/" '{print $1}')
    DISKINFONAME=$(echo "$LIVECDLABEL" | awk '{print $1}')
    . /etc/lsb-release

    #renaming grub config
    log-msg "Renaming grub config"
    #DO NOT RENAME GRUB_DISTRIBUTOR using $LIVECDLABEL it breaks UEFI Boot after install in 18.04+ BOG 20191118
    #sed -i "s/GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"$LIVECDLABEL\"/g" $WORKDIR/dummysys/etc/default/grub
    chmod 777 $WORKDIR/dummysys/etc/lsb-release
    sed -i '/DISTRIB_DESCRIPTION/d' $WORKDIR/dummysys/etc/lsb-release &> /dev/null
    echo "DISTRIB_DESCRIPTION=\"$LIVECDLABEL\"" >> /home/LiteDistroBuilder/LiteDistroBuilder/dummysys/etc/lsb-release

    #Creating startup script for the live system
    #Only do this for dist mode.
    log-msg "Creating startup script for the live system"
    if [ "$1" = "dist" ]; then
        cat > $WORKDIR/dummysys/etc/rc.local <<RCEOF
#!/bin/sh
echo "$LIVEUSER:linux" | /usr/sbin/chpasswd
sudo -i -u $LIVEUSER dbus-run-session -- gio set /home/$LIVEUSER/Desktop/install-linuxlite.desktop metadata::trusted yes
sudo -i -u $LIVEUSER dbus-run-session -- gio set /home/$LIVEUSER/Desktop/helpmanual.desktop metadata::trusted yes
sudo -i -u $LIVEUSER dbus-run-session -- gio set /home/$LIVEUSER/Desktop/install-linuxlite-oem.desktop metadata::trusted yes
exit 0
RCEOF
        chmod 755 $WORKDIR/dummysys/etc/rc.local
    fi

    #Set Calamares icon, comment and exec in the source .desktop file (used by the menu)
    sed -i 's|^Icon=.*|Icon=/usr/share/pixmaps/liteinstall.png|' /usr/share/applications/install-linuxlite.desktop &> /dev/null
    sed -i '/^Comment=/d' /usr/share/applications/install-linuxlite.desktop &> /dev/null
    sed -i '/^Name=/{a\Comment=Install Linux Lite on your computer
    }' /usr/share/applications/install-linuxlite.desktop &> /dev/null

    #Copy Calamares installer to live user Desktop and dummysys skel
    log-msg "Copying Calamares installer to live user Desktop"
    cp /usr/share/applications/install-linuxlite.desktop /home/$LIVEUSER/Desktop/ &> /dev/null
    cp /usr/share/applications/install-linuxlite.desktop /etc/skel/Desktop/ &> /dev/null
    mkdir -p $WORKDIR/dummysys/etc/skel/Desktop
    cp /usr/share/applications/install-linuxlite.desktop $WORKDIR/dummysys/etc/skel/Desktop/ &> /dev/null
    sed -i 's|^Icon=.*|Icon=/usr/share/pixmaps/liteinstall.png|' /home/$LIVEUSER/Desktop/install-linuxlite.desktop &> /dev/null
    sed -i 's|^Icon=.*|Icon=/usr/share/pixmaps/liteinstall.png|' /etc/skel/Desktop/install-linuxlite.desktop &> /dev/null
    sed -i 's|^Icon=.*|Icon=/usr/share/pixmaps/liteinstall.png|' $WORKDIR/dummysys/etc/skel/Desktop/install-linuxlite.desktop &> /dev/null
    sed -i 's|^Exec=.*|Exec=sudo calamares|' /home/$LIVEUSER/Desktop/install-linuxlite.desktop &> /dev/null
    sed -i 's|^Exec=.*|Exec=sudo calamares|' /etc/skel/Desktop/install-linuxlite.desktop &> /dev/null
    sed -i 's|^Exec=.*|Exec=sudo calamares|' $WORKDIR/dummysys/etc/skel/Desktop/install-linuxlite.desktop &> /dev/null
    chmod +x /home/$LIVEUSER/Desktop/install-linuxlite.desktop &> /dev/null
    chmod +x /etc/skel/Desktop/install-linuxlite.desktop &> /dev/null
    chmod +x $WORKDIR/dummysys/etc/skel/Desktop/install-linuxlite.desktop &> /dev/null

    #Copy OEM Calamares installer to live user Desktop and dummysys skel
    log-msg "Copying OEM Calamares installer to live user Desktop"
    cp /usr/share/applications/install-linuxlite-oem.desktop /home/$LIVEUSER/Desktop/ &> /dev/null
    cp /usr/share/applications/install-linuxlite-oem.desktop /etc/skel/Desktop/ &> /dev/null
    cp /usr/share/applications/install-linuxlite-oem.desktop $WORKDIR/dummysys/etc/skel/Desktop/ &> /dev/null
    chmod +x /home/$LIVEUSER/Desktop/install-linuxlite-oem.desktop &> /dev/null
    chmod +x /etc/skel/Desktop/install-linuxlite-oem.desktop &> /dev/null
    chmod +x $WORKDIR/dummysys/etc/skel/Desktop/install-linuxlite-oem.desktop &> /dev/null

    #Creating Network Update Script
    log-msg "Creating Network Update Script"
    touch $WORKDIR/dummysys/etc/network/if-up.d/update
    echo "#!/bin/sh" >> $WORKDIR/dummysys/etc/network/if-up.d/update
    echo "apt-get update" >> $WORKDIR/dummysys/etc/network/if-up.d/update
    chmod 755 $WORKDIR/dummysys/etc/network/if-up.d/update
    chmod +x $WORKDIR/dummysys/etc/network/if-up.d/update

    log-msg "Cleaning up files not needed for the live in $WORKDIR/dummysys"
    rm -rf $WORKDIR/dummysys/etc/apt/sources.list.d/*.save &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/apt/apt.conf.d/*.save &> /dev/null
    rm -rf $WORKDIR/dummysys/etc/apt/preferences.d/*.save &> /dev/null
    rm -rf $WORKDIR/dummysys/var/lib/apt/lists/* -vf &> /dev/null
    rm -rf $WORKDIR/dummysys/var/lib/apt/lists/lock &> /dev/null
    find $WORKDIR/dummysys/var/cache/apt -type f -exec rm -rf '{}' \; &> /dev/null
    find $WORKDIR/dummysys/var/cache/apt-xapian-index -type f -exec rm -rf '{}' \; &> /dev/null
    find $WORKDIR/dummysys/var/lib/apt -type f -exec rm -rf '{}' \; &> /dev/null
    rm -rf $WORKDIR/dummysys/var/lib/ureadahead/pack &> /dev/null
    find $WORKDIR/dummysys/etc/X11/ -maxdepth 1 -type f -name 'xorg.conf*' -delete &> /dev/null
    rm -f $WORKDIR/dummysys/etc/{hostname,mtab*,fstab}
    if [ ! -L $WORKDIR/dummysys/etc/resolv.conf ]; then
        rm -f $WORKDIR/dummysys/etc/resolv.conf
    fi
    rm -f $WORKDIR/dummysys/etc/udev/rules.d/70-persistent*
    rm -f $WORKDIR/dummysys/etc/cups/ssl/{server.crt,server.key}
    rm -f $WORKDIR/dummysys/etc/ssh/*key*
    rm -f $WORKDIR/dummysys/var/lib/dbus/machine-id
    rsync -a /dev/urandom $WORKDIR/dummysys/dev/
    find $WORKDIR/dummysys/var/log/ $WORKDIR/dummysys/var/lock/ $WORKDIR/dummysys/var/backups/ $WORKDIR/dummysys/var/tmp/ $WORKDIR/dummysys/var/crash/ -type f -exec rm -f {} \;

    if [ "$1" = "dist" ]; then

        rm -f $WORKDIR/dummysys/etc/{group,passwd,shadow,shadow-,gshadow,gshadow-}
        rm -f $WORKDIR/dummysys/etc/wicd/{wired-settings.conf,wireless-settings.conf}
        rm -rf $WORKDIR/dummysys/etc/NetworkManager/system-connections/*
        rm -f $WORKDIR/dummysys/etc/printcap
        rm -f $WORKDIR/dummysys/etc/cups/printers.conf
        touch $WORKDIR/dummysys/etc/printcap
        touch $WORKDIR/dummysys/etc/cups/printers.conf
        rm -rf $WORKDIR/dummysys/var/cache/gdm3/*
        rm -rf $WORKDIR/dummysys/var/lib/sudo/*
        rm -rf $WORKDIR/dummysys/var/lib/AccountsService/users/*
	    rm -rf $WORKDIR/dummysys/var/lib/kdm/*
        rm -rf $WORKDIR/dummysys/var/run/console/*
        rm -f $WORKDIR/dummysys/etc/gdm3/gdm3.conf-custom
        cp -a /etc/LiteDistroBuilder/scripts/logo $WORKDIR/dummysys/etc/cron.hourly
        chmod +x $WORKDIR/dummysys/etc/cron.hourly/logo
        chmod 755 $WORKDIR/dummysys/etc/cron.hourly/logo
        #Setting up auto timed login for gdm3
        cp -a /etc/LiteDistroBuilder/gdm3 $WORKDIR/dummysys/etc/
        sed -i "s/LIVEUSER/$LIVEUSER/g" $WORKDIR/dummysys/etc/gdm3/custom.conf
        chmod +x $WORKDIR/dummysys/etc/gdm3/custom.conf
        chmod 755 $WORKDIR/dummysys/etc/gdm3/custom.conf
        #Setting up auto timed login for MDM
        cp -a /etc/LiteDistroBuilder/mdm $WORKDIR/dummysys/etc/
        sed -i "s/LIVEUSER/$LIVEUSER/g" $WORKDIR/dummysys/etc/mdm/mdm.conf
        chmod +x $WORKDIR/dummysys/etc/mdm/mdm.conf
        chmod 755 $WORKDIR/dummysys/etc/mdm/mdm.conf
        if [ ! -d /run ]; then
		find $WORKDIR/dummysys/var/run/ $WORKDIR/dummysys/var/mail/ $WORKDIR/dummysys/var/spool/ -type f -exec rm -f {} \;
	else
		find $WORKDIR/dummysys/var/mail/ $WORKDIR/dummysys/var/spool/ -type f -exec rm -f {} \;
		unlink $WORKDIR/dummysys/var/run

		cd $WORKDIR/dummysys/var || exit 1
		ln -sf ../run run
	fi
        for i in dpkg.log lastlog mail.log syslog auth.log daemon.log faillog lpr.log mail.warn user.log boot debug mail.err messages wtmp bootstrap.log dmesg kern.log mail.info
        do
            touch $WORKDIR/dummysys/var/log/${i}
        done

        log-msg "Cleaning up passwd, group, shadow and gshadow files for the live system"
        grep '^[^:]*:[^:]*:[0-9]:' /etc/passwd > $WORKDIR/dummysys/etc/passwd
        {
            grep '^[^:]*:[^:]*:[0-9][0-9]:' /etc/passwd
            grep '^[^:]*:[^:]*:[0-9][0-9][0-9]:' /etc/passwd
            grep '^[^:]*:[^:]*:[3-9][0-9][0-9][0-9][0-9]:' /etc/passwd 
         }  >> $WORKDIR/dummysys/etc/passwd

        grep '^[^:]*:[^:]*:[0-9]:' /etc/group > $WORKDIR/dummysys/etc/group
        {
            grep '^[^:]*:[^:]*:[0-9][0-9]:' /etc/group
            grep '^[^:]*:[^:]*:[0-9][0-9][0-9]:' /etc/group
            grep '^[^:]*:[^:]*:[3-9][0-9][0-9][0-9][0-9]:' /etc/group
        } >> $WORKDIR/dummysys/etc/group
        #Add Liveuser to groups

        grep '^[^:]*:[^:]*:[5-9][0-9][0-9]:' /etc/passwd | awk -F ":" '{print $1}'> $WORKDIR/tmpusers1
        grep '^[^:]*:[^:]*:[1-9][0-9][0-9][0-9]:' /etc/passwd | awk -F ":" '{print $1}'> $WORKDIR/tmpusers2
        grep '^[^:]*:[^:]*:[1-2][0-9][0-9][0-9][0-9]:' /etc/passwd | awk -F ":" '{print $1}'> $WORKDIR/tmpusers3

        cat $WORKDIR/tmpusers1 $WORKDIR/tmpusers2 $WORKDIR/tmpusers3 > $WORKDIR/tmpusers
        rm -f $WORKDIR/tmpusers[0-9] &> /dev/null

        # This needs looked into
        # shellcheck disable=SC2002
        cat $WORKDIR/tmpusers | while read -r LINE ;do

            echo "$LINE" | xargs -I{} sed -e 's/,{}$//g' "$WORKDIR"/dummysys/etc/group > "$WORKDIR"/dummysys/etc/group.new1
            echo "$LINE" | xargs -I{} sed -e 's/,{},/,/g' "$WORKDIR"/dummysys/etc/group.new1 > "$WORKDIR"/dummysys/etc/group.new2
            echo "$LINE" | xargs -I{} sed -e 's/:{}$/:/g' "$WORKDIR"/dummysys/etc/group.new2 > "$WORKDIR"/dummysys/etc/group.new3
            echo "$LINE" | xargs -I{} sed -e 's/:{},/:/g' "$WORKDIR"/dummysys/etc/group.new3 > "$WORKDIR"/dummysys/etc/group

            rm -f $WORKDIR/dummysys/etc/group.new* &> /dev/null

        done

    fi


    # make sure the adduser and autologin functions of casper as set according to the mode
    log-msg "Making sure adduser and autologin functions of casper are set properly"
    [ "$1" = "dist" ] && [ ! -d $WORKDIR/dummysys/home ] && mkdir $WORKDIR/dummysys/home
    [ "$1" = "dist" ] && chmod 755 /usr/share/initramfs-tools/scripts/casper-bottom/*adduser /usr/share/initramfs-tools/scripts/casper-bottom/*autologin /usr/share/initramfs-tools/scripts/casper

    # copy over some of the necessary stuff for the livecd

    #copy any preseed files
    log-msg "Copying any preseed files"
    cp /etc/LiteDistroBuilder/preseed/* $WORKDIR/ISOTMP/preseed/

    # ISOLINUX boot (BIOS) — graphical vesamenu
    log-msg "Copying isolinux boot files"
    mkdir -p $WORKDIR/ISOTMP/isolinux
    cp /usr/lib/ISOLINUX/isolinux.bin $WORKDIR/ISOTMP/isolinux/
    cp /usr/lib/syslinux/modules/bios/vesamenu.c32 $WORKDIR/ISOTMP/isolinux/
    cp /usr/lib/syslinux/modules/bios/ldlinux.c32 $WORKDIR/ISOTMP/isolinux/
    cp /usr/lib/syslinux/modules/bios/libcom32.c32 $WORKDIR/ISOTMP/isolinux/
    cp /usr/lib/syslinux/modules/bios/libutil.c32 $WORKDIR/ISOTMP/isolinux/
    cp /usr/lib/syslinux/modules/bios/reboot.c32 $WORKDIR/ISOTMP/isolinux/ 2>/dev/null
    cp /usr/lib/syslinux/modules/bios/poweroff.c32 $WORKDIR/ISOTMP/isolinux/ 2>/dev/null
    cp /usr/lib/LiteDistroBuilder/boot/isolinux/isolinux.cfg $WORKDIR/ISOTMP/isolinux/
    cp /usr/lib/LiteDistroBuilder/boot/isolinux/splash.png $WORKDIR/ISOTMP/isolinux/

    # EFI boot — GRUB (stock cd-boot-images)
    log-msg "Copying EFI GRUB boot files"
    cp -a /usr/share/cd-boot-images-amd64/tree/boot $WORKDIR/ISOTMP/boot
    cp -a /usr/share/cd-boot-images-amd64/tree/EFI $WORKDIR/ISOTMP/EFI
    cp /usr/share/cd-boot-images-amd64/images/boot/grub/efi.img $WORKDIR/ISOTMP/boot/grub/efi.img

    cp /usr/lib/LiteDistroBuilder/boot/grub/grub.cfg $WORKDIR/ISOTMP/boot/grub/grub.cfg
    cp /usr/lib/LiteDistroBuilder/boot/grub/loopback.cfg $WORKDIR/ISOTMP/boot/grub/loopback.cfg
    cp -a /usr/lib/LiteDistroBuilder/boot/grub/themes $WORKDIR/ISOTMP/boot/grub/
    sed -i "s/__LIVECDLABEL__/$LIVECDLABEL/g" $WORKDIR/ISOTMP/boot/grub/grub.cfg
    sed -i "s/__LIVECDLABEL__/$LIVECDLABEL/g" $WORKDIR/ISOTMP/boot/grub/loopback.cfg

    #Downloading packages for offline install
    log-msg "Downloading packages for CD"

    # Check Architecture (in case iso is called without cdfs)
    if [ -z "$ARCH" ]; then
        ARCH=$(dpkg --print-architecture)
    fi

    mkdir -p $WORKDIR/ISOTMP/pool
    chmod 777 $WORKDIR/ISOTMP/pool
    cd $WORKDIR/ISOTMP/pool  || exit 1
    log-msg "Update source list again because previously we clean apt cache to copy system folders to dummysys"
    apt-get update 2>&1 | log-msg
    log-msg "Downloading packages needed for offline install"
    if [ "$ARCH" = "amd64" ] ; then
        POOL_PACKAGES="efibootmgr b43-fwcutter grub-efi grub-efi-amd64 grub-efi-amd64-bin grub-efi-amd64-signed grub-efi-ia32 grub-efi-ia32-bin mokutil shim shim-signed"
    else
        POOL_PACKAGES="efibootmgr b43-fwcutter grub-efi grub-efi-ia32 grub-efi-ia32-bin mokutil"
    fi
    for pkg in $POOL_PACKAGES ; do
        log-msg "Downloading $pkg"
        apt-get download "$pkg" 2>&1 | log-msg
    done
    mkdir -p $WORKDIR/ISOTMP/dists
    cd $WORKDIR/ISOTMP/  || exit 1
    dpkg-scanpackages pool /dev/null | gzip -9c > dists/Packages.gz
    apt-ftparchive release ./dists > ./dists/Release

    cat > $WORKDIR/ISOTMP/README.diskdefines <<FOO
#define DISKNAME  $LIVECDLABEL
#define TYPE  binary
#define TYPEbinary  1
#define ARCH  $ARCH
#define ARCH$ARCH  1
#define DISKNUM  1
#define DISKNUM1  1
#define TOTALNUM  0
#define TOTALNUM0  1
FOO
    cp $WORKDIR/ISOTMP/README.diskdefines $WORKDIR/ISOTMP/casper/README.diskdefines

    sleep 1

    # Step 4 - Make the filesystem.manifest and filesystem.manifest-desktop
    log-msg "Creating filesystem.manifest and filesystem.manifest-desktop"
    dpkg-query -W --showformat='${Package} ${Version}\n' > $WORKDIR/ISOTMP/casper/filesystem.manifest

    cp $WORKDIR/ISOTMP/casper/filesystem.manifest $WORKDIR/ISOTMP/casper/filesystem.manifest-desktop
    # Suggested by lkjoel from Ubuntu Forums - Joel Leclerc to remove the frontend so the Install menu item is not on the installed system
    sed -i '/calamares/d' $WORKDIR/ISOTMP/casper/filesystem.manifest-desktop

    sleep 1

    # Step 5 - Prepare casper.conf
    log-msg "Preparing casper.conf file"

        LIVEUSER=$(who -u | grep -v root | cut -d " " -f1| uniq)
        if [ "$(who -u | grep -v root | cut -d " " -f1| uniq | wc -l)" != "1" ]; then
            LIVEUSER=$(grep '^[^:]*:[^:]*:1000:' /etc/passwd | awk -F ":" '{ print $1 }')
        fi
        if [ "$LIVEUSER" = "" ]; then
            log-msg "Can't determine which user to use. Please logoff all users except for your main user and try again. Exiting."
            exit 1
        fi
        
    log-msg "Creating the casper.conf file."
    # Added FLAVOUR= as the new casper live boot will make it the first word from the Live CD Name if FLAVOUR is not set
    cat > /etc/casper.conf <<FOO
# This file should go in /etc/casper.conf
# Supported variables are:
# USERNAME, USERFULLNAME, HOST, BUILD_SYSTEM

export USERNAME="$LIVEUSER"
export USERFULLNAME="Live session user"
export HOST="$LIVEUSER"
export BUILD_SYSTEM="Ubuntu"
export FLAVOUR="$LIVEUSER"
FOO
    cp /etc/casper.conf $WORKDIR/dummysys/etc/

    sleep 1

    log-msg "Setting up casper options for $1 mode"

    # make a new initial ramdisk including the casper scripts
    log-msg "Creating a new initial ramdisk for the live system"
    mkinitramfs -o /boot/initrd.img-"$(uname -r)" "$(uname -r)"

    log-msg "Copying your kernel and initrd for the livecd"
    cp /boot/vmlinuz-"$(uname -r)" "$WORKDIR"/ISOTMP/casper/vmlinuz
    cp /boot/initrd.img-"$(uname -r)" "$WORKDIR"/ISOTMP/casper/initrd.gz
    if [ ! -f "$WORKDIR"/ISOTMP/casper/vmlinuz ]; then
        log-msg "Missing valid kernel. Exiting"
        exit 1
    fi
    if [ ! -f "$WORKDIR"/ISOTMP/casper/initrd.gz ]; then
        log-msg "Missing valid initial ramdisk. Exiting"
        exit 1
    fi

    # Step 6 - Make filesystem.squashfs

    if [ -f $WORKDIR/ISOTMP/casper/filesystem.squashfs ]; then
        rm -f $WORKDIR/ISOTMP/casper/filesystem.squashfs &> /dev/null
    fi

    log-msg "Creating filesystem.squashfs   ... this will take a while so be patient"

    REALFOLDERS=""
    
    # This needs looked at
    #shellcheck disable=SC2045,SC2010
    for d in $(ls -d $WORKDIR/dummysys/*); do
        REALFOLDERS="$REALFOLDERS $d"
    done

    # This needs looked at
    # shellcheck disable=SC2010
    for d in $(ls / | grep -v etc | grep -v run | grep -v tmp | grep -v sys | grep -v var | grep -v dev | grep -v media | grep -v mnt | grep -v lost+found | grep -v proc | grep -v home); do
        REALFOLDERS="$REALFOLDERS /$d"
    done
    
    # Remove "no-duplicates" from mksquashfs line. BOG 20190315
    # Needs looked at another command args array issue
    # shellcheck disable=SC2086
    mksquashfs $REALFOLDERS $WORKDIR/ISOTMP/casper/filesystem.squashfs $SQUASHFSOPTS -e /boot/efi/EFI /boot/grub $BASEWORKDIR $EXCLUDES 2>> $WORKDIR/"$CUSTOMLOG.log"


    sleep 1

    #add some stuff the log in case of problems so I can troubleshoot it easier
    echo "Updating the $CUSTOMLOG.log"
    {
    echo "------------------------------------------------------"
    echo "Mount information"
    mount
    echo "------------------------------------------------------"
    echo "Disk size information"
    df -h
    echo "------------------------------------------------------"
    echo "Casper Script info"
    ls -l /usr/share/initramfs-tools/scripts/casper-bottom/
    echo "------------------------------------------------------"
    echo "/etc/LiteDistroBuilder.conf info"
    cat /etc/LiteDistroBuilder.conf
    echo "------------------------------------------------------"
    echo "/etc/casper.conf info"
    cat /etc/casper.conf
    echo "------------------------------------------------------"
    echo "/etc/passwd info"
    cat $WORKDIR/dummysys/etc/passwd
    echo "------------------------------------------------------"
    echo "/etc/group info"
    cat $WORKDIR/dummysys/etc/group
    echo "------------------------------------------------------"
    echo "/etc/X11/default-display-manager info"
    cat $WORKDIR/dummysys/etc/X11/default-display-manager
    echo "------------------------------------------------------"
    echo "/etc/skel info"
    find /etc/skel
    echo "------------------------------------------------------"
    echo "lsb-release info"
    cat $WORKDIR/dummysys/etc/lsb-release
    echo "------------------------------------------------------"
    echo "LiteDistroBuilder version info"
    cat $WORKDIR/dummysys/etc/LiteDistroBuilder/LiteDistroBuilder.version
    echo "------------------------------------------------------"
    echo "ISOTMP info"
    ls -Rl $WORKDIR/ISOTMP
    echo "------------------------------------------------------"
    echo "$WORKDIR/tmpusers info"
    cat $WORKDIR/tmpusers
    echo "------------------------------------------------------"
    echo "Command-line options = $*"
    echo "------------------------------------------------------"
    } >>$WORKDIR/"$CUSTOMLOG.log"

    apt-get install -y "$(check-language-support)" &> /dev/null
    
    sleep 1

    #add filesystem size for lucid
    log-msg "Calculating the installed filesystem size for the installer"

    unsquashfs -lls $WORKDIR/ISOTMP/casper/filesystem.squashfs | grep -v " inodes " | grep -v "unsquashfs:" | awk '{print $3}' | grep -v "," > /tmp/size.tmp

    # Needs looked into
    # shellcheck disable=SC2013
    for i in $(cat /tmp/size.tmp); do a=$((a+i)); done
    echo $a > $WORKDIR/ISOTMP/casper/filesystem.size

    log-msg "Removing LiteDistroBuilder-firstboot from system startup"
    update-rc.d -f LiteDistroBuilder-firstboot remove
    chmod 644 /etc/init.d/LiteDistroBuilder-firstboot

}

iso (){
	# Tell shellcheck to ignore.. use of "which" is OK.
    # shellcheck disable=SC2230
    CREATEISO=$(which xorriso)
    if [ "$CREATEISO" = "" ]; then
        log-msg "xorriso is not installed. Please install it with: sudo apt-get install xorriso"
        exit 1
    fi

    # check to see if the cd filesystem exists

    if [ ! -f "$WORKDIR/ISOTMP/casper/filesystem.squashfs" ]; then
        log-msg "The filesystem.squashfs filesystem is missing.  Either there was a problem creating the compressed filesystem or you are trying to run sudo LiteDistroBuilder dist iso before sudo LiteDistroBuilder dist cdfs"
        exit 1
    fi


    #Step 6.5 - Added by Tim Farley. Make ISO compatible with Ubuntu Startup Disk Creator (Karmic).
    log-msg "Making disk compatible with Ubuntu Startup Disk Creator."
    . /etc/lsb-release
    touch $WORKDIR/ISOTMP/ubuntu
    touch $WORKDIR/ISOTMP/.disk/base_installable
    echo "full_cd/single" > $WORKDIR/ISOTMP/.disk/cd_type
    # starting with 12.04 need to have correct ubuntu version or startup disk creator uses syslinux-legacy which won't work
    DISKINFONAME=$(echo "$LIVECDLABEL" | awk '{print $0}')
    echo "$DISKINFONAME" - Release "$ARCH" > "$WORKDIR/ISOTMP"/.disk/info
    echo "$LIVECDURL" > $WORKDIR/ISOTMP/.disk/release_notes_url
    # Step 7 - Make md5sum.txt for the files on the livecd - this is used during the
    # checking function of the livecd
    log-msg "Creating md5sum.txt for the livecd/dvd"
    cd $WORKDIR/ISOTMP && find . -type f -print0 | xargs -0 md5sum > md5sum.txt

    sleep 1

    # Step 8 - Make the ISO file
    log-msg "Creating $CUSTOMISO in $WORKDIR"
    # shellcheck disable=SC2086
    $CREATEISO -as mkisofs -iso-level 3 -V "$LIVECDLABEL" -J -joliet-long -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -isohybrid-gpt-basdat -o $WORKDIR/$CUSTOMISO "$WORKDIR/ISOTMP" 2>>$WORKDIR/"$CUSTOMLOG.log" 1>>$WORKDIR/"$CUSTOMLOG.log"
    if [ ! -f "$WORKDIR/$CUSTOMISO" ]; then
        log-msg "The iso was not created. There was a problem. Exiting"
        exit 1
    fi

    # create the md5 sum file so the user doesn't have to - this is good so the iso
    # file can later be tested to ensure it hasn't become corrupted

    log-msg "Creating $CUSTOMISO.md5 in $WORKDIR"

    cd $WORKDIR  || exit 1
    md5sum "$CUSTOMISO" > "$CUSTOMISO.md5"

    sleep 1

    log-msg "Creating $CUSTOMISO.sha256 in $WORKDIR"

    cd $WORKDIR  || exit 1
    sha256sum "$CUSTOMISO" > "$CUSTOMISO.sha256"

    sleep 1

    # shellcheck disable=SC2012
    ISOSIZE=$(ls -hs "$WORKDIR/$CUSTOMISO" | awk '{print $1}')

    log-msg "$WORKDIR/$CUSTOMISO which is $ISOSIZE in size is ready to be burned or tested in a virtual machine."

}

# check to see if either iso or cdfs options have been invoked and proceed accordingly


case $2 in
    iso )
        iso "$@"
    ;;
    cdfs )
        cdfs "$@"
    ;;
    * )
        cdfs "$@"
        iso "$@"
    ;;
esac




exit 0
