#!/bin/bash

# Custom ISO Builder script can extract existing ISO image, 
# customize the file system and build a new ISO image.
# Created by Paweł "pavroo" Pijanowski <pavroo@onet.eu> 2014/07/21
# Copyright 2014-2024 under the GNU GPL2 License
# Last update 2024/08/25 by pavroo
#
# The script uses a part of Remastersys code created by Tony "Fragadelic" Brijeski
# Copyright 2007-2012 Under the GNU GPL2 License
#
# This script requires yad to run

# get default's locale file
DEFLOCDIR="/usr/share/sparky/custom-iso-builder"
if [ "`cat /etc/default/locale | grep LANG= | grep de`" != "" ]; then
. $DEFLOCDIR/de
elif [ "`cat /etc/default/locale | grep LANG= | grep el`" != "" ]; then
. $DEFLOCDIR/el
elif [ "`cat /etc/default/locale | grep LANG= | grep es`" != "" ]; then
	if [ "`cat /etc/default/locale | grep LANG= | grep es_AR`" != "" ]; then
. $DEFLOCDIR/es_AR
	else
. $DEFLOCDIR/es_ES
	fi
elif [ "`cat /etc/default/locale | grep LANG= | grep fi`" != "" ]; then
. $DEFLOCDIR/fi
elif [ "`cat /etc/default/locale | grep LANG= | grep fr`" != "" ]; then
. $DEFLOCDIR/fr
elif [ "`cat /etc/default/locale | grep LANG= | grep hu`" != "" ]; then
. $DEFLOCDIR/hu
elif [ "`cat /etc/default/locale | grep LANG= | grep id_ID`" != "" ]; then
. $DEFLOCDIR/id_ID
elif [ "`cat /etc/default/locale | grep LANG= | grep it`" != "" ]; then
. $DEFLOCDIR/it
elif [ "`cat /etc/default/locale | grep LANG= | grep ja`" != "" ]; then
. $DEFLOCDIR/ja
elif [ "`cat /etc/default/locale | grep LANG= | grep pl`" != "" ]; then
. $DEFLOCDIR/pl
elif [ "`cat /etc/default/locale | grep LANG= | grep pt_BR`" != "" ]; then
. $DEFLOCDIR/pt_BR
elif [ "`cat /etc/default/locale | grep LANG= | grep pt_PT`" != "" ]; then
. $DEFLOCDIR/pt_PT
elif [ "`cat /etc/default/locale | grep LANG= | grep ru`" != "" ]; then
. $DEFLOCDIR/ru
elif [ "`cat /etc/default/locale | grep LANG= | grep uk`" != "" ]; then
. $DEFLOCDIR/uk
else
. $DEFLOCDIR/en
fi

DIALOG400="yad --window-icon=media-cdrom --width=400 --height=200 --center"
DIALOG500="yad --window-icon=media-cdrom --width=500 --height=300 --center"
DIALOG700="yad --window-icon=media-cdrom --width=700 --height=500 --center"
DIALOG="yad --window-icon=media-cdrom --width=600 --height=350 --center"
TITLE="--always-print-result --dialog-sep --image=media-cdrom --title="
TEXT="--text="
ENTRY="--entry "
ENTRYTEXT="--entry-text "
MENU="--list --column=$LOCAL1 --column=$LOCAL2"
OKEXIT=" --button=Ok:0 --button=$LOCAL3:1 "
MSGBOX=" --button=Ok:0 "
FILESELECT="--file"
TITLETEXT="Custom ISO Builder"
DIRSELECT="--file --directory"
FILTER="--file-filter"
FIELD="--field"

testroot="`whoami`"
if [ "$testroot" != "root" ]; then
	$DIALOG400 $TITLE"$TITLETEXT" $MSGBOX $TEXT"$LOCAL4"
	exit 1
fi

rootmenu () {
CHOICES=`$DIALOG $TITLE"$TITLETEXT" $OKEXIT $MENU $TEXT"$LOCAL5" \
Rebuild "$LOCAL6" \
Build_New "$LOCAL7" \
About "$LOCAL8"`

if [ "$?" = "0" ]; then
	CHOICE=`echo $CHOICES | cut -d "|" -f 1`
else
	exit 0
fi

if [ "$CHOICE" = "Rebuild" ]; then
	/usr/lib/custom-iso-builder/bin/rebuild
elif [ "$CHOICE" = "Build_New" ]; then
	/usr/lib/custom-iso-builder/bin/build-new
elif [ "$CHOICE" = "About" ]; then
$DIALOG500 $TITLE"$TITLETEXT" $MSGBOX $TEXT"$LOCAL9 \n\
\n\
$LOCAL10 \n\
\n\
$LOCAL11 \n\
\n\
$LOCAL12"
rootmenu
else
	exit 0
fi
}

rootmenu
