#!/bin/bash

# APSK ext2 Disk Image Maker
# by Apollia - http://apollia.org/


readonly Short_Command_Name="apsk-make-ext2-disk-img"
#readonly Short_Command_Name=$(basename "$0")


readonly Fillepath____This_Script=$(realpath "${BASH_SOURCE[0]}")
readonly Follpath____This_Script=$(dirname "$Fillepath____This_Script" )

Now_in_Console_Mode=false

#-------------------------------------------------------------------------------

readonly Follpath____Helpers="$Follpath____This_Script/Helpers"
	
	readonly Fillepath____Main_Library="$Follpath____Helpers/Main Library"
	
	readonly Fillepath____Message_Functions="$Follpath____Helpers/Message Functions"
	
	readonly Fillepath____Translation_Functions="$Follpath____Helpers/Translation Functions"
	readonly Fillepath____This_App_s_Translations="$Follpath____Helpers/This App's Translations"
	
	
		source "$Fillepath____Main_Library"
			
		source "$Fillepath____Message_Functions"
		
		source "$Fillepath____Translation_Functions"
		source "$Fillepath____This_App_s_Translations"

#-------------------------------------------------------------------------------

readonly Follpath____Temp_Files="/tmp/APSK/ext2 Disk Image Maker"
	readonly Follpath____Temp_Notes="$Follpath____Temp_Files/Notes"

		mkdir --parents "$Follpath____Temp_Notes"

			readonly Note_Fillepath____Filepath="$Follpath____Temp_Notes/APSK ext2 Disk Image Maker Filepath Note-$$"


readonly Fillepath____Default_for_New_Disk_Image="$Follpath____Temp_Files/ext2 Disk Image File"

	echo -n "$Fillepath____Default_for_New_Disk_Image" > "$Note_Fillepath____Filepath"

#-------------------------------------------------------------------------------


readonly Lowest_Allowed_Loop_Device_ID_Number=300
readonly Highest_Allowed_Loop_Device_ID_Number=400

readonly Mountpoint_Follpath____Temp="/apmnt/Temp_Mountpoint_for_ext2_Disk_Image_File"

#-------------------------------------------------------------------------------


Set_Exit_Trap



# 07:43:34 03/10/2018.  To change the language this script displays
# output in, run this command before running mkdirperms:
#
# 	export Language="Dog Language"
#
# 04:57:59 03/10/2018.  I don't understand any language other than English
# well enough to write a real translation, so the only other "language"
# available for now is Dog Language. :-)
#
#
# 01:13:14 03/30/2018.  No Dog Language in this app (yet?).
#
# See mkdirperms for an example of a complete Dog Language translation. :-)
#
# https://github.com/Apollia/mkdirperms

Figure_Out_Translation_To_Use

Declare_Paths____Translation_Related


Get_Translations_for____Exit_Trap

Get_Translations_for____GUI_Help

readonly Script_Title="APSK ext2 $I18n____Disk_Image_Maker"


Get_Translations_for____Console

if [ ! -z "$1" ]
then

	readonly Now_in_Console_Mode=true
	
	
	readonly Fillepath____This_App_s_Args="$Follpath____Helpers/This App's Args"	
		source "$Fillepath____This_App_s_Args"
		
	
	should_open_dest_folder_with_rox_filer=true
	
	
	declare -a Positional_Args

	Parse_Script_Options "$@"

	#printf 'pos arg %s\n' "${Positional_Args[@]}"

	Parse_Script_Positional_Args "${Positional_Args[@]}"
	
	Valicheck_Args__Then__If_Valid__Create_ext2_Disk_Image "$Arg____Filepath" "$Arg____Filesize"
	result_code="$?"
	
	if [ "$result_code" = 0 ]
	then
		echo
		echo "$I18n____Succeeded!"
		
		
		#!!!!
		exit 0
	fi
	
	
	#!!!!
	exit 1
fi


if [ "$Now_in_Console_Mode" = true ]
then


	#!!!!
	exit 2
fi


readonly Fillepath____Prepare_GUI="$Follpath____Helpers/Prepare GUI"
	source "$Fillepath____Prepare_GUI"