Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
copycat / usr / share / copycat / copycat-format
Size: Mime:
#!/bin/bash
#-----------------------------------------------------------------------------
# CopyCat Debian Version 1.0.18
# 2024
#-----------------------------------------------------------------------------
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# PATH
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin
# Added for translation purposes
# i18n - Internationalisation - Internationalisierung
VERSION=1.0.18
export TEXTDOMAIN=copycat_$VERSION
export TEXTDOMAINDIR="/usr/share/locale"
# variable for the gui
ICON="/usr/share/icons/hicolor/48x48/apps/copycat.svg"
EICON="/usr/share/copycat/icons/error.svg"
WICON="/usr/share/copycat/icons/warning.svg"
CANCEL="/usr/share/copycat/icons/cancel.svg"
OK="/usr/share/copycat/icons/ok.svg"
TITLE="CopyCat"
#set -x
run_as_root() {
#-----------------------------------------------
# run as root
#-----------------------------------------------
PID=`ps -eaf | grep yad | grep -v grep | awk '{print $2}'`
if [[ "" !=  "$PID" ]]; then
  echo "killing $PID"
  kill -9 $PID > /dev/null 2>&1 &
fi
if [ `id -u` -eq 0 ]; then
exec $@
else
`yad --title="CopyCat" --width=400 \
--height=100 --fixed --image=$EICON \
--window-icon=$EICON --center \
--text=$"\n\You need to be root to run CopyCat!" \
--button=Ok!$OK:"1"`
if [ "$?" = "1" ] ; then
exit 1
 fi 	
fi
rm -f /tmp/copycat >/dev/null 2>&1

NVME=$(grep -o nvme /etc/mtab| awk 'NR==1{print $0}')
if [[ $NVME = "$NVME" ]] 
then
lsblk | grep -o sd[a-z] | tail -n1 |awk '$0="/dev/"$0' > /tmp/copycat
sleep 0.50
USBdevice=$(grep -o sd[a-z] /proc/partitions |tail -n1)
lsblk -do VENDOR,MODEL,SIZE /dev/$USBdevice |sed -e 's/ \+/ /g'| awk 'NR == 2' >> /tmp/copycat
else
lsblk | grep -o sd[b-z] | tail -n1 |awk '$0="/dev/"$0' > /tmp/copycat
sleep 0.50
USBdevice=$(grep -o sd[a-z] /proc/partitions |tail -n1)
lsblk -do VENDOR,MODEL,SIZE /dev/$USBdevive |sed -e 's/ \+/ /g'| awk 'NR == 2' >> /tmp/copycat
fi
if [ -s "/tmp/copycat" ]; then 
exec $@
else
USERS=$(who |sed 's/ .*//'|head -n1)
su $USERS -c /usr/share/copycat/info_notify.py
pkill -f /usr/bin/copycat >/dev/null 2>&1
sleep 1
pkexec /usr/bin/copycat
exit 1
  fi
# Check if the user remouted the usb key 
CHMOUNT=$(grep -o "0B" /tmp/copycat)  
if [ "$CHMOUNT" = "" ] ; then
exec $@
else
`yad --title="CopyCat" --width=450 --height=100 --fixed --center --image=$WICON \
--window-icon=$WICON --center \
--text=$"\n\Remount the USB Device so it can be detected?\n<span color=\"#e07b39\">Continue only when the USB Device has been Inserted.</span>" \
--button=Cancel!$CANCEL:"1"`
if [ $? = 1 ] ; then 
pkill -SIGKILL copycat-format >/dev/null 2>&1 
exit
   fi
    fi
}
#-----------------------------------------------------------------------------
set_variables() {
DRIVES=""                           # The drive after the USB is plugged in
Part_Num=""                         # The partition number
ISO_FILE=""                         # The selected ISO file for the installation
JOB=""                              # Used to get ADD and LIVE variables from user
ADD=""                              # This is true if an additional OS is being installed
MPnt="/media/root/CopyCat"          # The mount point for the target partition (ext4)
NAME=""                             # The chosen name for the OS to be installed
SIZE1=""                            # The free space on the selected partition
SIZE2=""                            # The space required for the selected OS
Install_To=""                       # The partition selected for the installation
Type=""                             # We check the FS to ensure it is usable for the install
isolin_full=""                      # The full path and filename of the isolinx or renamed directory
PID=$$                              # Allows to kill the script on error.
sqfs_dir=""                         # The path only of the sqfs file
sqfs_full=""                        # Full path and name of the sqfs file
sqfs_name=""                        # The name only of the sqfs file ie. livecd
efi_Part=""                         # The EFI partition base name e.g  /dev/sdk1
efi_Mnt="/media/root/CopyCat.$RANDOM"    # The mount point for the EFI partition.
}
#-----------------------------------------------------------------------------------
if [ ! -d "/media/root/CopyCat" 2>/dev/null ]; then 
mkdir -p "/media/root/CopyCat" 
fi
create_mounts() {
mkdir $efi_Mnt                 # Create the directory for the EFI mount
}
get_device() {
# Get usb mounted device
usbinfo=$(cat /tmp/copycat | awk 'NR == 2')
usbdevice=$(cat /tmp/copycat | awk 'NR == 1')
DRIVES="$usbdevice"
Install_To="$usbdevice"2""
FMT_BOOT=$(yad --window-icon=$ICON --center --title="$TITLE" \
--width=425 --height=90 --fixed --image=$ICON \
--column=$"" \
--entry \
--text= \
$"Format and Partition $usbinfo (  $usbdevice  )" \
--button=Cancel!$CANCEL:"1" \
--button=Ok!$OK:"0")
if [ $? = "1" ]; then
umount /media/*/*
rm -rf /media/root/* > /dev/null 2>&1
rm -f /tmp/copycat >/dev/null 2>&1
pkill -SIGKILL copycat-format >/dev/null 2>&1
fi |
if [ $? = "3" ]; then
$(yad --width=375 --height=100 --fixed --center \
--window-icon=/usr/share/copycat/icons/info-help.svg \
--image=/usr/share/copycat/icons/help.png \
--title='Copycat' \
--button=Close!$CANCEL)
umount /media/root/*
rm -rf /media/root/* > /dev/null 2>&1
rm -f /tmp/copycat >/dev/null 2>&1
pkill -SIGKILL copycat-format >/dev/null 2>&1
else
if [ -n "${FMT_BOOT}" ]; then
case $FMT_BOOT in
"Format and Partition $usbinfo (  $usbdevice  )")
$(yad --title="CopyCat" --width=500 --height=100 --fixed --center \
--text=$"Creating and formatting on $usbinfo $usbdevice\nYou will need at least a 10GB usb key or larger for persistence.\n\n<span color=\"#e07b39\">Warning! This will delete all current data from this usb device!</span>\n" \
--window-icon=$WICON \
--image=$WICON \
--button=Cancel!$CANCEL:"1" \
--button=Ok!$OK:"0")
if [ "$?" = "1" ]; then
umount /media/root/*
rm -rf /media/root/* > /dev/null 2>&1
rm -f /tmp/copycat >/dev/null 2>&1
pkill -SIGKILL copycat-format > /dev/null 2>&1
exit 0
else
exec
fi
sleep 2
#---------------------------------
# Get the iso to format correctly
#---------------------------------
USER=$(who |sed 's/ .*//'|tail -n1)
ISO_FILE=$(yad --file --filename=/home/$USER --center --file-filter="*.iso" \
--window-icon=$ICON \
--image=$ICON --height=550 \
--width=725 --on-top --title="CopyCat" \
--text=$"<b>Select an ISO File to Start the Format process  $usbinfo $usbdevice</b>" \
--button=Cancel!$CANCEL:2 \
--button=Select!$OK:0)
if [ ${ISO_FILE: -4} == ".iso" 2>/dev/null ]; then
echo "$ISO_FILE" > /tmp/selected 
else
yad --window-icon=$ICON --width=500 --height=125 --fixed --center \
--image=$EICON \
--title=$"CopyCat" --text=$"
     <b>No Selected ISO or Incorrect File Selection</b>!
Your previous iso formatting was:\n<span color=\"#e07b39\">"$SELECTED"</span>
Restart the program if you want to continue" \
--button=Cancel!$CANCEL:1
umount -q $MPnt
rm -rf $MPnt.*
pkill -SIGKILL copycat-format > /dev/null 2>&1
exit 0
 fi
if [ $? = "2" ]; then
yad --window-icon=$EICON --width=425 --height=125 --fixed --center \
--image=$EICON \
--title=$"CopyCat" --text=$"
     <b>No File Selected or Available</b>!

 Restart the program if you want to continue" \
--button=Cancel!$CANCEL:5
if [ $? = "5" ]; then
umount -q $MPnt
rm -rf $MPnt.* 
pkill -SIGKILL copycat-format > /dev/null 2>&1
exit 0
fi
 fi
CASPER=(`isoinfo -l -i "$ISO_FILE" | grep -E CASPER | awk 'NR==1{print $0}' | awk -F']' '{print $NF}' | sed 's/^..//' > /tmp/casper`)
Check="`grep -E CASPER /tmp/casper | awk 'NR==1{print $0}'`"
if [[ $Check == "" ]]
then 
#-----------------------------------------------
# Formatting other Debian iso's
#-----------------------------------------------
usbinfo=$(cat /tmp/copycat | awk 'NR == 2')
usbdevice=$(cat /tmp/copycat | awk 'NR == 1')
install_usb="$usbdevice"
DRIVES="$install_usb"
sleep 1
USB_DEVICE=""
Partitions=""
dmesg -c > /dev/null
sleep 0.1
#Format and Partition
while true; do 
echo "#Creating and formatting device..." 2>/dev/null; 
sleep 5m;
done | yad --center --progress --pulsate --title="CopyCat" \
--window-icon=$ICON --image=$ICON --width=600 \
--button="Cancel!$CANCEL":1 --height=100 --fixed \
--text=$"\nCreating Partitions and formatting $usbinfo (  $usbdevice  )" &
while [ "$USB_DEVICE" = "" ]
do
sleep 1
USB_DEVICE="$usbdevice"
done
# umount any existing mounted partitions
Partitions=$(lsblk -l -o FSTYPE,NAME,SIZE,LABEL $USB_DEVICE | grep "sd[a-z][1-9]" | tr -s ' ' | cut -d ' ' -f2)
for i in $Partitions; do umount /dev/$i ; done
#

# Delete the device partition structure
wipefs -a $USB_DEVICE
#
# Zero the first 2MB for the bios_grub
dd if=/dev/zero of=$USB_DEVICE bs=1M count=2
#
# Create new structure
# This causes the /ext4 partition to mount so we need to umount it below
# so it can be formatted.
echo "label: gpt
unit: sectors
first-lba: 34
: start=        2048, size=     2048, type=21686148-6449-6E6F-744E-656564454649
: start=        4096, size= 19003392, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
: start=        19007488              type=21686148-6449-6E6F-744E-656564454649
" | sfdisk $USB_DEVICE
#
# Format partitions
(
Device1="$USB_DEVICE"3
echo y | mkfs.ext4 -L persistence $Device1
sleep 2
mount "$USB_DEVICE"3 /mnt 
cd /mnt
echo "/ union" > persistence.conf  
umount -q "$USB_DEVICE"3
sleep 2
Device2="$USB_DEVICE"2
echo y | mkfs.fat -n CopyCat $Device2
)
rm -f /tmp/casper > /dev/null 2>&1
eject $DRIVES
sleep 1
PID=`ps -eaf | grep yad | grep -v grep | awk '{print $2}'`
if [[ "" !=  "$PID" ]]; then
kill -9 $PID > /dev/null 2>&1
fi &
$(yad --window-icon=$ICON --height=125 --width=550 --fixed --image=$ICON \
--center --on-top --title="$TITLE" --text=$"
<b>Creating partitions and formatting complete!</b>\n
<span color=\"#e07b39\">Remove $usbinfo (  $usbdevice  ) Reinsert and\nMount The USB Key Device to continue the Installation.</span>\n
Make sure to use the same iso image for persistence." \
--button="Close!$CANCEL":1) 
if [ $? = 1 ]; then
rm -f /tmp/casper > /dev/null 2>&1
rm -rf /media/root/CopyCat.*
pkill -SIGKILL copycat-format > /dev/null 2>&1
fi
else
#-----------------------------------------------
# Formatting Ubuntu/Mint
#-----------------------------------------------
usbinfo=$(cat /tmp/copycat | awk 'NR == 2')
usbdevice=$(cat /tmp/copycat | awk 'NR == 1')
install_usb="$usbdevice"
DRIVES="$install_usb"
sleep 1
USB_DEVICE=""
Partitions=""
dmesg -c > /dev/null
sleep 0.1
#Format and Partition
while true; do 
echo "#Creating and formatting device..." 2>/dev/null; 
sleep 5m;
done | yad --center --progress --pulsate --title="CopyCat" \
--window-icon=$ICON --image=$ICON --width=600 \
--button="Cancel!$CANCEL":1 --height=100 --fixed \
--text=$"\nCreating Partitions and formatting $usbinfo (  $usbdevice  )" &
while [ "$USB_DEVICE" = "" ]
do
sleep 1
USB_DEVICE="$usbdevice"
done
# umount any existing mounted partitions
Partitions=$(lsblk -l -o FSTYPE,NAME,SIZE,LABEL $USB_DEVICE | grep "sd[a-z][1-9]" | tr -s ' ' | cut -d ' ' -f2)
for i in $Partitions; do umount /dev/$i ; done
#

# Delete the device partition structure
wipefs -a $USB_DEVICE
#
# Zero the first 2MB for the bios_grub
dd if=/dev/zero of=$USB_DEVICE bs=1M count=2
#
# Create new structure
# This causes the /ext4 partition to mount so we need to umount it below
# so it can be formatted.
echo "label: gpt
unit: sectors
first-lba: 34
: start=        2048, size=     2048, type=21686148-6449-6E6F-744E-656564454649
: start=        4096, size= 19003392, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4
: start=        19007488              type=21686148-6449-6E6F-744E-656564454649
" | sfdisk $USB_DEVICE
#
# Format partitions
(
Device1="$USB_DEVICE"3
echo y | mkfs.ext4 -L casper-rw $Device1
sleep 2
Device2="$USB_DEVICE"2
echo y | mkfs.fat -n CopyCat $Device2
)
rm -f /tmp/casper > /dev/null 2>&1
eject $DRIVES
sleep 1
PID=`ps -eaf | grep yad | grep -v grep | awk '{print $2}'`
if [[ "" !=  "$PID" ]]; then
kill -9 $PID > /dev/null 2>&1
fi &
$(yad --window-icon=$ICON --height=125 --width=550 --fixed --image=$ICON \
--center --on-top --title="$TITLE" --text=$"
<b>Creating partitions and formatting complete!</b>\n
<span color=\"#e07b39\">Remove $usbinfo (  $usbdevice  ) Reinsert and\nMount The USB Key Device to continue the Installation.</span>\n
Make sure to use the same iso image for persistence." \
--button="Close!$CANCEL":1)  
if [ $? = 1 ]; then
rm -f /tmp/casper > /dev/null 2>&1
rm -rf /media/root/CopyCat.*
pkill -SIGKILL copycat-format > /dev/null 2>&1
fi
  fi
;;
 esac
fi
  fi
usbinfo=$(cat /tmp/copycat | awk 'NR == 2')
usbdevice=$(cat /tmp/copycat | awk 'NR == 1')
install_usb="$usbdevice"
if [ "$DRIVES" = "$DRIVES" ]; then
Install_To="$usbdevice"2""
echo "$Install_To"
else
yad --width=375 --height=100 --fixed --center \
--text=$"\nNo usb key mounted on system!\nMount the usb key to continue setup" \
--window-icon=$EICON \
--image=$EICON \
--title='Error' \
--button=Close!$CANCEL:1
umount -q $MPnt
rm -rf $MPnt.* 
pkill -SIGKILL copycat-format > /dev/null 2>&1
exit 0
 fi
usbdevice=$(cat /tmp/copycat | awk 'NR == 1')
sleep 1
Install_To="$usbdevice"2""
echo "$Install_To"
Install_To=$(echo $Install_To | sed 's/[|].*//'); echo $Install_To
umount -q $Install_To
Part_Num=$(echo "$Install_To" | cut -c9-10 )
}
get_device_type() {
FDISK_GET=$(dmesg | tail -8 | grep -i "Attached SCSI " | grep -i " disk" | grep -i sd[a-z] | sed 's|^.*\[||' | sed 's|\].*||' | sed 's|s|/dev/s|')
if [ $FDISK_GET = "" 2>/dev/null ]; then
FDISK_GET="$install_usb"
fi
DOS=""
GPT=""
DOS=$(fdisk -l $FDISK_GET | grep "dos" | sed 's| ||g'| cut -d : -f2)
GPT=$(fdisk -l $FDISK_GET | grep "gpt" | sed 's| ||g'| cut -d : -f2)
}
get_uuid() {
if [ "$DRIVES" = "$DRIVES" ]; then
exec
else
yad --width=375 --height=100 --fixed --center \
--text=$"\nInstallation Setup Failed!\nReinsert the usb key to continue" \
--window-icon=$EICON \
--image=$EICON \
--title='Error' \
--button=Close!$CANCEL:1
umount -q $MPnt
rm -rf $MPnt.* 
pkill -SIGKILL copycat-format > /dev/null 2>&1
exit 0
fi
# Get the UUID of partition 
PART_UUID=$(lsblk -l -n -o UUID "$Install_To")
if [ "$PART_UUID" == "" ] ; then
$(yad --window-icon=$WICON --width=475 --height=125 --fixed --center \
--image=$WICON --title=" $TITLE " \
--text=$"<b>Check the USB Device Partitions/Mount</b>

Two probable causes found on the USB selected device!

Formatting is needed or the USB key is not mounted\nPress Ok to restart or Cancel to exit" \
--button=Cancel!"$CANCEL":1 \
--button=Ok!"$OK":0)
if [ $? = "1" ]; then
umount -q $MPnt
rm -rf $MPnt.*
pkill -SIGKILL copycat-format > /dev/null
exit 0
else
exec "/usr/bin/copycat"
fi
 fi
}
#------------------------------
# Write a label for the USB drive
write_label() {
if [ "$DRIVES" = "$DRIVES" ]; then
#------------------------------
LABEL="CopyCat" 
echo ""
#------------------------------
else
yad --width=450 --height=100 --fixed --center \
--text=$"\nReinsert the key mounted on system!\nRemount the usb key to continue" \
--window-icon=$EICON \
--image=$EICON \
--title='Error' \
--button=Close!$CANCEL:1
umount -q $MPnt
rm -rf $MPnt.*
exit 0
 fi
}
get_iso() {
#------------------------------
# Get the iso image
#------------------------------
SELECTED=$(cat /tmp/selected | awk 'NR == 1')
USER=$(who |sed 's/ .*//'|tail -n1)
ISO_FILE=$(yad --file --filename=/home/$USER --center --file-filter="*.iso" \
--window-icon=$ICON \
--image=$ICON --height=550 \
--width=725 --on-top --title="CopyCat" \
--text=$"<b>Select an ISO File to Start the Install Process  $usbinfo $usbdevice</b>" \
--button=Cancel!$CANCEL:2 \
--button=Select!$OK)
if [ $SELECTED = "$ISO_FILE" ]
then
echo "$ISO_FILE"
mkdir -p /tmp/iso
mount "$ISO_FILE" /tmp/iso -o loop
else
yad --window-icon=$EICON --width=425 --height=125 --fixed --center \
--image=$EICON \
--title=$"CopyCat" --text=$"
     <b>No Selected ISO or File Selection Incorrect</b>!

    Restart the program if you want to continue" \
--button=Cancel!$CANCEL:1
umount -q $MPnt
rm -rf $MPnt.*
pkill -SIGKILL copycat-format > /dev/null 2>&1
exit 0
  fi
if [ $? = "2" ]; then
yad --window-icon=$EICON --width=425 --height=125 --fixed --center \
--image=$EICON \
--title=$"CopyCat" --text=$"
     <b>No File Selected or Available</b>!

 Restart the program if you want to continue" \
--button=Cancel!$CANCEL:5
if [ $? = "5" ]; then
umount -q $MPnt
rm -rf $MPnt.* 
pkill -SIGKILL copycat-format > /dev/null 2>&1
exit 0
fi
 fi
}
mount_part() {
mount $Install_To $MPnt
if [ "$?" != "0" ] ; then
yad --window-icon=$EICON --width=450 --height=125 --fixed --center \
--image=$EICON \
--title=$"Error" --text=$"
     <b>A Mounting Error has Occured</b>

     Seems the USB key has not been mounted properly?

         Please check about this mounting error." \
--button=Cancel!$CANCEL:1
if [ $? = 1 ]; then
umount -q $MPnt
rm -rf $MPnt.*
pkill -SIGKILL copycat-format > /dev/null 2>&1
exit 0
fi
 fi
}
get_name() {
while [[ ! "$NAME" =~ [a-zA-Z0-9] ]]; do
NAME=$(yad --window-icon=$ICON --center --list --height=400 --width=525 --title="$TITLE" --text=$"
<b>Select a Debian $OSNAME Distro Name</b>
<span color=\"#e07b39\">Highlight a name and select <b>OK</b> to accept it</span>" --editable --column $"- Suggested Names -
Highlight entry to edit name. Press Enter twice to apply your edit.
Custom edits must not be left blank or with spaces." "CINNAMON" "GNOME" "PLASMA" "MATE" "XFCE" "LXDE" "LXQT" \
--button=Cancel!$CANCEL:1 \
--button=OK!$OK:0)
if [ "$?" = "0" ] ; then
echo "$NAME"
fi
# Replace spaces with _    Leading spaces are omitted.
NAME=$(echo "$NAME" | sed 's/[|].*//')
if [ "$?" != "0" ] ; then
yad --window-icon=$EICON --height=150 --center --width=500 \
--image=$EICON --title=$"Error" --text=$"
                         <b>CANCEL</b>

     You have chosen to cancel this application.

        We will now abort the installation.

  Thank you for trying CopyCat" \
--button=Cancel!$CANCEL:1
if [ "$?" = "1" ] ; then
umount -q $MPnt
rm -rf $MPnt.*
exit 0
fi
 fi
if [ "$NAME" = "" ]
then
yad --window-icon=$EICON --center --width=400 --height=125 --fixed \
--image=$EICON --title=$"Error" --text=$"
		<b>An Error has Occured</b>

  You failed to correctly enter or select a name for the OS.

                      Please try again." \
--button=Quit!$CANCEL:1 \
--button=OK!$OK:0
if [ "$?" = "1" ] ; then
umount -q $MPnt
rm -rf $MPnt.* 
pkill -SIGKILL copycat-format >/dev/null 2>&1
exit 0
fi
else
if [ "$ADD" = "yes" ]
then
if [ -d $MPnt/$NAME ]
then
yad --window-icon=$EICON --center --width=450 \
--image=$EICON --title="$TITLE" --text=$"
		<b>An Error has Occured</b>

     You have selected an existing name for the OS.

                      Please try again." \
--button=Quit!$CANCEL:1 \
--button=OK!$OK:0
if [ "$?" = "0" ] ; then
NAME=""
else
umount -q $MPnt
rm -rf $MPnt.*
pkill -SIGKILL copycat-format > /dev/null
exit 0
fi
fi
 fi
  fi
done
 }
get_size() {
# Check we have sufficient space
SIZE1=$(df -B M --output=avail $MPnt | sed '1d' | cut -d 'M' -f1)
SIZE2=$(du -B M "$ISO_FILE" | cut -d 'M' -f1)
SIZE2=$(($SIZE2+10))
if [ $SIZE2 -gt $SIZE1 ]; then
unmount_part
yad --window-icon=$EICON --width=475 --height=125 --fixed --on-top --center \
--image=$EICON \
--title=$"Error" --text=$"
	          <b>A Fatal Error has Occured</b>

There is Insufficient Room for the Installation.

                      This application will now abort!" \
--button=Close!$CANCEL:1
if [ $? = 1 ]; then
umount -q $MPnt
rm -rf $MPnt.*
pkill -SIGKILL copycat-format > /dev/null
exit 0
fi
 fi
}
get_size2() {
#-----------------------------------------------
# Check have sufficient space for Extracted Files 
#------------------------------------------------
SIZE1=$(df -B M --output=avail $MPnt | sed '1d' | cut -d 'M' -f1)
SIZEA=$(du -B M -s "$sqfs_full" | cut -d 'M' -f1)
if [ "$?" != "0" ] ; then
yad --window-icon=$EICON --width=475 --height=125 --fixed --on-top \
--center --image=$EICON \
--title=$"Error" --text=$"
	          <b>Cannot find your files</b>

       An ERROR has occurred so we are aborting.

          Please give feedback about this error.

                            Thank you!" \
--button=Close!$CANCEL:1
if [ $? = 1 ]; then
umount -q $MPnt
rm -rf $MPnt.* 
pkill -SIGKILL copycat-format > /dev/null
exit 0
fi
  fi
SIZEB=$(du -B M -s "$isolin_full" | cut -d 'M' -f1)
if [ "$?" != "0" ] ; then
yad --window-icon=$EICON --width=475 --height=125 --fixed --on-top \
--center --image=$EICON \
--title=$"Error" --text=$"
	          <b>Cannot find your files</b>

       An ERROR has occurred so we are aborting.

          Please give feedback about this error.

                            Thank you!" \
--button=Close!$CANCEL:1
if [ $? = 1 ]; then
umount -q $MPnt
rm -rf $MPnt.*
pkill -SIGKILL copycat-format >/dev/null 2>&1
exit 0
fi
 fi
SIZE2=$(($SIZEA+$SIZEB+10))
if [ $SIZE2 -gt $SIZE1 ]; then
unmount_part
yad --window-icon=$EICON --width=475 --height=125 --fixed --on-top \
--center --image=$EICON \
--title=$"Error" --text=$"
	          <b>An Fatal Error has Occured</b>

There is Insufficient Room for the Installation to Proceed.
You need either a larger device or else choose a smaller
OS to fit on this device.
            This application will now abort!" \
--button=Close!$CANCEL:1
if [ $? = 1 ]; then
umount -q $MPnt
rm -rf $MPnt.*
pkill -SIGKILL copycat-format >/dev/null 2>&1
exit 0
fi
 fi
}
wipe_part() {
rm -rf $MPnt.*
efi_wipe=$(fdisk -l $FDISK_GET -o Device,Type | grep EFI | tr -s ' ' | cut -d ' ' -f1)
if [ "$efi_wipe" != "" ]; then
rm -rf $MPnt.*
fi
}
copy_iso_files() {
if [ "$?" != "0" ] ; then
yad --window-icon=$EICON --width=475 --height=125 --fixed \
--on-top --center --image=$EICON \
--title=$"Error" --text=$"
	          <b>An Error has Occured</b>

       We were unable to create a directory on your partition.

           Please give feedback about this error.


                             Thank you!" \
--button=Close!$CANCEL:1
if [ $? = 1 ]; then
umount -q $MPnt
rm -rf $MPnt.* 
pkill -SIGKILL copycat-format >/dev/null 2>&1
exit 0
fi
 fi
#------------------------------
# Copy iso to USB Key
#------------------------------
# show progress 
USB_device="$install_usb"
iso_name=$(echo "$NAME" | sed 's/[|].*//')
    touch $MPnt/.temp 
    source="$ISO_FILE"
    sourcesize=$(du -m -s "$source" | cut -f1)         
    target=$MPnt/.temp                       
    targetsize=$(du -m -s $target | cut -f1)
    cp_target=$MPnt                               
    cp_sourcesize=$(du -m -s $source | cut -f1)              
    cp_targetsize=$(du -m -s $MPnt | cut -f1)
     rsync -av "/tmp/iso"/ "$MPnt"/ & 
    dd if=$source of=$target oflag=nocache &    
    sleep 0.1;
    while [ $cp_targetsize -lt $cp_sourcesize 2>/dev/null ]; do
    sleep 0.1;
    cp_targetsize=$(du -m -s $target | cut -f1)
    percent=$(("$cp_targetsize"*110/$cp_sourcesize))
    echo $percent 2>/dev/null 
    done | yad --window-icon=$ICON --image=$ICON \
    --on-top --width=550 --height=100 --center --fixed --progress \
    --title="$TITLE" --text=$"<b>Creating the Operating System on the Device</b>
    
    <span color=\"#e07b39\">Installing  $OSNAME $iso_name  to $usbinfo ( $usbdevice )</span>" \
    --auto-close --button=Cancel!$CANCEL:"5" 
    if [ $? = "5" ]; then
    killall "rsync" >/dev/null 2>&1 
    killall "dd" >/dev/null 2>&1 
    sleep 0.50
    umount /tmp/iso  
    rm -rf /tmp/iso  > /dev/null 2>&1 
    sleep 0.50 
    umount {$Install_To,$MPnt,$MPnt.*}
    rm -rf {$MPnt.*,$MPnt} > /dev/null 2>&1
    exit 0
     fi
 # Change name of ISO files  
if [ "$ADD" != "yes" ]
then
stat $MPnt/EFI 2>/dev/null
if [ "$?" = "0" ] ; then
exec $@
fi
 fi
}
copy_extracted_files() {
if [ "$?" != "0" ] ; then
yad --window-icon=$EICON --width=475 --height=125 --fixed \
--on-top --center --image=$EICON \
--title=$"Error" --text=$"
	          <b>An Error has Occured</b>

    We were unable to create a directory on your partition.

           Please give feedback about this error.


                             Thank you!" \
--button=Close!$CANCEL:1
if [ $? = 1 ]; then
umount -q $MPnt
rm -rf $MPnt.* 
pkill -SIGKILL copycat-format >/dev/null 2>&1
exit 0
fi
 fi
# Added the EFI directory to list
if [ "$ADD" != "yes" ]
then
stat $sqfs_dir/EFI
if [ "$?" = "0" ] ; then
cp -r $sqfs_dir/EFI $MPnt/EFI
fi
 fi
}
permissions() {
chmod 777 $MPnt
wait
}
unmount_part() {

if [ ! -d $MPnt/boot/grub ]
then
mkdir -p $MPnt/boot/grub
fi

find $MPnt/ -type d -name "casper_*" -execdir bash -c 'mv {} tmp' \;
sleep 1
#---------------------------------------------
# Check for DOS EFI and Install the bootloader 
#---------------------------------------------
mount $Install_To /mnt
if [[ "$DOS" = "dos" ]]
then
grub-install --target=i386-pc --root-directory=/mnt --recheck $usbdevice > /dev/null 2>&1
else
grub-install --target=x86_64-efi --recheck $usbdevice > /dev/null 2>&1
 fi
}

abort() {
if [ "$Install_To" != "" ]; then
umount -q $Install_To
fi
rm -rf $MPnt.*
kill $PID
exit
}
prepare_for_install() {
# Select EFI Partition
efi_Part=""
efi_Part=$(fdisk -l $FDISK_GET -o Device,Type | grep EFI | tr -s ' ' | cut -d ' ' -f1)
# Check for presence of bios_grub (BIOS boot) partition 
bios_grub=$(fdisk -l $FDISK_GET -o Device,Type | grep BIOS | tr -s ' ' | cut -d ' ' -f1)
# Only do the following IF the EFI partition exists 
if [ "$efi_Part" != "" ]; then
mount $efi_Part $efi_Mnt
   if [ "$ADD" = "no" ]
then
rm -rf $MPnt.*
mkdir -p $efi_Mnt/EFI
# Insert test to ensure we have EFI directory on the EFI partition  
if [ "$ADD" = "yes" ]
then
    stat "$efi_Mnt/EFI" 2>/dev/null
if [ "$?" != "0" ]
then
mkdir -p $efi_Mnt/EFI
fi
 fi
  fi
   fi 
}
permissions
usb_install() {
set_variables
get_device
get_device_type
create_mounts
write_label
get_uuid
mount_part
get_name
if [ "$LIVE" != "yes" ]
then
get_iso
fi
	(
echo ; sleep 1
if [ "$ADD" = "yes" ]; then
stat "$MPnt/boot/grub/grub.cfg"
 fi
if [ "$ADD" != "yes" ]
then
wipe_part
fi
if [ "$LIVE" != "yes" ]
then
get_size
copy_iso_files
else
get_size2
copy_extracted_files
fi
prepare_for_install
unmount_part
echo "Install Complete" 2>/dev/null
 )
finished
# Eject the device
eject $DRIVES
}
# Main Program
run_as_root
usb_install
rm -rf {$MPnt,$MPnt.*} >/dev/null 2>&1
exit 0