#!/bin/bash
#------------------------------------------------------------------------|
#                   PCLinuxOS Distro Choice                              |
#------------------------------------------------------------------------|
#                   PCLinuxOS (c) 2024 - GPL V3                          |
#------------------------------------------------------------------------|
# This program 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 3 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.                           |
#------------------------------------------------------------------------|
Version=3.0
Encoding=UTF-8
CONF="$HOME/.pdc"
ICON="/usr/share/pdc/icons/pdc.png"
EICON="/usr/share/pdc/icons/error.svg"
#------------------------------------
# Clean up if any files remains 
# Kill stale notification icon if any 
#------------------------------------
rm -rf $CONF > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 &
#-----------------------------------------
# Create a temp folder
#---------------------
if ! test -d $CONF; then
   mkdir -p $CONF
fi
#-----------------------------
# Test for network connection
#-----------------------------
wget -q --tries=3 --timeout=10 \
--delete-after "https://www.google.com/"  
if [[ $? -eq 0 ]]; then
exec 
else
`yad --text="\n<b>No network or website down</b>.\n \
PDC cannot operate properly!" \
--title='PCLinuxOS Distro Choice' \
--width=400 --height=100 --fixed \
--window-icon=$EICON \
--image=$EICON \
--button=Ok!/usr/share/pdc/icons/ok.svg:0`
exit 0
fi
# Main repo change if needed
action=$(yad \
--width=475 \
--height=100 \
--image=$ICON \
--center --fixed \
--window-icon=$ICON \
--title='PDC' \
--entry \
--column="Icon"  \
--column="Size" \
--text=$'Choose a Repository From the List Below' \
'http://mirror.math.princeton.edu' 'http://ftp.fau.de' 'http://ftp.jaist.ac.jp' 'https://ftp.nluug.nl' \
--button="Cancel"!/usr/share/pdc/icons/cancel.svg:1 \
--button="Ok"!/usr/share/pdc/icons/ok.svg:0) 
[[ $? = "1" ]] && 
exit 0
if [ -n "${action}" ]; then
case $action in
'http://mirror.math.princeton.edu')
REPO="https://mirror.math.princeton.edu/pub/pclinuxos/pclinuxos/iso/"
echo "REPO"
;;
'http://ftp.fau.de')
REPO="https://ftp.fau.de/pclinuxos/pclinuxos/iso/"
echo "REPO"
 ;;
'http://ftp.jaist.ac.jp')
REPO="http://ftp.jaist.ac.jp/pub/Linux/PCLinuxOS/pclinuxos/iso/"
echo "REPO"
 ;;
'https://ftp.nluug.nl')
REPO="https://ftp.nluug.nl/pub/os/Linux/distr/pclinuxos/pclinuxos/iso/"
echo "REPO"
 ;;
esac
fi

#-------------------------------------------------------------------------------------------------
# Get the locations of the ISOs in the mirror selected in Synaptic and apply them to variables
#-------------------------------------------------------------------------------------------------
Mirror64=$(cat /etc/apt/sources.list | grep -v '#' | cut -d ' ' -f2 | sed 's|apt|iso|') #; echo $Mirror64

# If the mirror URL does not begin with "http:" then delete it and use nluug instead
# (A user might be using a local mirror which begins with "file://")
TEST=$(echo $Mirror64 | sed '/^[^http:]/ d'); sleep 1
if [ "$TEST" = "" ]; then
Mirror64="$REPO"
fi

# Get the ISOs at the selected location and put their names in the specified file
curl -s $Mirror64 | grep ".iso" | grep -oP '(?<=href=")[^"]*' | sed '/^\./ d' > $CONF/iso-versions
if grep ".md5sum" $CONF/iso-versions > /dev/null
then
sed -i '4d' $CONF/iso-versions
fi
#---------------------------
# Create a stop/kill file
#--------------------------- 
echo \
'#!/bin/bash
EICON="/usr/share/pdc/icons/error.svg"
$(yad --text="\nAre you sure you want to stop the download?\nThis will also delete the current files" \
--title="PCLinuxOS Distro Choice" \
--width=425 --height=100 --center --fixed \
--window-icon=$EICON \
--image=$EICON \
--button=Yes!/usr/share/pdc/icons/ok.svg:1 \
--button=No!/usr/share/pdc/icons/cancel.svg:0) 
if [[ $? -eq 1 ]]; then
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL axel > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1
exit 0
fi' | awk '{print $0}' > $CONF/stop
chmod a+x "$CONF/stop"
#------------------------------------
# Get all the iso info file, print it
#------------------------------------

A1=`cat $CONF/iso-versions | awk 'NR==1{print $0}'| sed 's/\.iso$//g'` #kde5
A2=`cat $CONF/iso-versions | awk 'NR==2{print $0}'| sed 's/\.iso$//g'` #kde5-darkstar
A3=`cat $CONF/iso-versions | awk 'NR==3{print $0}'| sed 's/\.iso$//g'` #MATE
A4=`cat $CONF/iso-versions | awk 'NR==4{print $0}'| sed 's/\.iso$//g'` #xfce

#
#--------------------
# PCLOS flavor select
#--------------------
SELECT=$(yad \
--width=450 --height=100 --fixed \
--image=$ICON \
--button=Cancel!/usr/share/pdc/icons/cancel.svg:1 \
--button=Ok!/usr/share/pdc/icons/ok.svg:0 \
--window-icon=$ICON \
--entry \
--title="PCLinuxOS Distro Choice" \
--text="Select a PCLinuxOS Distribution" \
--entry-text="$A1" "$A2" "$A3" "$A4"  "Community iso reference site")
if [ -n "${SELECT}" ]; then
case "$SELECT" in
"$A1")
#------------------------------------------------------------------
# KDE5
#------------------------------------------------------------------
# Create a progress info file 
echo \
'#!/bin/bash
CONF="$HOME/.pdc" 
ICON="/usr/share/pdc/icons/pdc.png" 
A1=`cat $CONF/iso-versions | awk NR==1{print} | sed 's/\.iso$//g'`
while true; do 
CONF="$HOME/.pdc"
PROGRESS=("`cut -f 2 -d [ $CONF/pdc.log | cut -f 1 -d ]| tail -n 1`")
AB=$(cat $CONF/iso-versions | awk NR==1{print} > $CONF/iso)
echo "Downloading... "$PROGRESS"  completed" 2>/dev/null >> $CONF/iso; 
sleep 3
done'| awk '{print $0}' > $CONF/progress
chmod a+x "$CONF/progress"
echo \
'#!/bin/bash
if [ $? = "0" ]; then
CONF="$HOME/.pdc"
ICON="/usr/share/pdc/icons/pdc.png"
A1=`cat $CONF/iso-versions | awk NR==1{print} | sed 's/\.iso$//g'`
while true; do
CONF="$HOME/.pdc/pdc.log"
PERCENT=("%")
COUNT=("`grep -E "$PERCENT" $HOME/.pdc/pdc.log|sed 's/^.//'|sed 's/]$//'|sed "s/["]"].*//"|sed 's/.$//'|awk 'END{print}'`")
sleep 0.50;
for ((i=$COUNT; i<="$COUNT"; i++)); do { echo $i; sleep 0.10; } done 
done|yad --window-icon="$ICON" --image="$ICON" --on-top --width=575 --height=100 \
--fixed --center --progress --title="PCLinuxOS Distro Choice" --text=$"\nDownloading  <span color=\"#D95548\">"$A1".iso</span>   Please wait!" \
--button=gtk-close --auto-close
fi'| awk '{print $0}' > $CONF/progressbar
chmod a+x "$CONF/progressbar"
A1=`cat $CONF/iso-versions | awk 'NR==1{print $0}'`
MD5=`cat $CONF/iso-versions | awk 'NR==1{print $0}' | sed 's/\.iso$//g'`
ISONAME="$A1"
DIRNAME=`cat $CONF/iso-versions | awk 'NR==1{print $0}' | sed 's/\.iso$//g'`
ISO_name=`cat $CONF/iso-versions | awk 'NR==1{print}' | sed s/.iso$//g > $CONF/iso`
md5sumdownload=""$REPO"$MD5.md5sum"
urlsource=""$REPO"$ISONAME"
   ENTRY=$(yad --width=400 --window-icon=$ICON --center \
        --form --title="PCLinuxOS Distro Choice" \
        --field="Save in:DIR" "$HOME/Desktop" \
--text='\nSelected Official PCLinuxOS KDE5 Release' \
--button=Cancel!/usr/share/pdc/icons/cancel.svg:1 --button=Ok!/usr/share/pdc/icons/ok.svg:0)
ret=$?
[[ $ret -eq 1 ]] && exit &&
PID=`ps -eaf | grep yad | grep -v grep | awk '{print $2}'`
if [[ "" !=  "$PID" ]]; then
kill -9 $PID > /dev/null 2>&1 
fi
if [[ $ret -eq 0 ]]; then
A1=`cat $CONF/iso-versions | awk 'NR==1{print $0}'`
    RET=$?

    OIFS=$IFS 
    IFS="|" 
    i=0
    retChoice=()

    for ret in $ENTRY;do 
        retChoice[$i]="$ret"
        i=$(($i+1))
    done

    IFS=$OIFS 
    SAVEDIR=${retChoice[0]} # directory path
mkdir -p $SAVEDIR/$DIRNAME 
cd $SAVEDIR/$DIRNAME
# Get a notify menu 
python3 "/usr/share/pdc/notify/PDC" &
exec $HOME/.pdc/progress &
axel -n 5 $urlsource > $CONF/pdc.log 
echo "Downloading..."
cd $SAVEDIR/$DIRNAME
axel -n 1 $md5sumdownload
# checking md5sum
MD5SUM_IS=`md5sum $ISONAME`
echo $MD5SUM_IS
MD5SUM_SH=`cat $MD5.md5sum`
echo $MD5SUM_SH
if [ "$MD5SUM_IS" = "$MD5SUM_SH" ];then
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 | notify-send -t 35000 -i $ICON "$A1" "Download Completed!" &
sleep 1
pw-play "/usr/share/pdc/sounds/complete.mp3"
# Repeat sound file
pw-play "/usr/share/pdc/sounds/complete.mp3"
else
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 | notify-send -t 10000 -i $EICON "$A1" "Download incomplete error!\nFiles will be deleted!" &
pw-play "/usr/share/pdc/sounds/dialog-warning.mp3"
# Repeat sound file
pw-play "/usr/share/pdc/sounds/dialog-warning.mp3"
rm -rf "$SAVEDIR/$DIRNAME" 2>/dev/null
 fi
   fi
rm -rf $CONF 2>/dev/null 
;;
#---------
# END KDE5
#---------
"$A2")
#---------------------------------------------------------------------------
# KDE5 Darkstar
#---------------------------------------------------------------------------
# Create a progress info file 
echo \
'#!/bin/bash
CONF="$HOME/.pdc" 
ICON="/usr/share/pdc/icons/pdc.png" 
B2=`cat $CONF/iso-versions | awk NR==2{print} | sed 's/\.iso$//g'`
while true; do 
CONF="$HOME/.pdc"
PROGRESS=("`cut -f 2 -d [ $CONF/pdc.log | cut -f 1 -d ]| tail -n 1`")
BA=$(cat $CONF/iso-versions | awk NR==2{print} > $CONF/iso)
echo "Downloading... "$PROGRESS"  completed" 2>/dev/null >> $CONF/iso; 
sleep 3
done'| awk '{print $0}' > $CONF/progress
chmod a+x "$CONF/progress"
echo \
'#!/bin/bash
if [ $? = "0" ]; then
CONF="$HOME/.pdc"
ICON="/usr/share/pdc/icons/pdc.png"
B2=`cat $CONF/iso-versions | awk NR==2{print} | sed 's/\.iso$//g'`
while true; do
CONF="$HOME/.pdc/pdc.log"
PERCENT=("%")
COUNT=("`grep -E "$PERCENT" $HOME/.pdc/pdc.log|sed 's/^.//'|sed 's/]$//'|sed "s/["]"].*//"|sed 's/.$//'|awk 'END{print}'`")
sleep 0.50;
for ((i=$COUNT; i<="$COUNT"; i++)); do { echo $i; sleep 0.10; } done 
done|yad --window-icon="$ICON" --image="$ICON" --on-top --width=575 --height=100 \
--fixed --center --progress --title="PCLinuxOS Distro Choice" --text=$"\nDownloading  <span color=\"#D95548\">"$B2".iso</span>   Please wait!" \
--button=gtk-close --auto-close
fi'| awk '{print $0}' > $CONF/progressbar
chmod a+x "$CONF/progressbar"
A2=`cat $CONF/iso-versions | awk 'NR==2{print $0}'`
   ENTRY=$(yad --width=400 --window-icon=$ICON --center \
        --form --title="PCLinuxOS Distro Choice" \
        --field="Save in:DIR" "$HOME/Desktop" \
--text='\nSelected Official PCLinuxOS Darkstar Release' \
--button=Cancel!/usr/share/pdc/icons/cancel.svg:1 --button=Ok!/usr/share/pdc/icons/ok.svg:0)
ret=$?
[[ $ret -eq 1 ]] && exit &&
pkill -SIGKILL yad 2>/dev/null
if [[ $ret -eq 0 ]]; then
ISONAME="$A2"
DIRNAME=`cat $CONF/iso-versions | awk 'NR==2{print $0}' | sed 's/\.iso$//g'`
    RET=$?

    OIFS=$IFS 
    IFS="|" 
    i=0
    retChoice=()

    for ret in $ENTRY;do 
        retChoice[$i]="$ret"
        i=$(($i+1))
    done

    IFS=$OIFS 
    SAVEDIR=${retChoice[0]} # directory path
MD5=`cat $CONF/iso-versions | awk 'NR==2{print $0}' | sed 's/\.iso$//g'`
md5sumdownload=""$REPO"$MD5.md5sum"
urlsource=""$REPO"$ISONAME"
DIRNAME=`cat $CONF/iso-versions | awk 'NR==2{print $0}' | sed 's/\.iso$//g'`
ISO_name=`cat $CONF/iso-versions | awk 'NR==2{print}' | sed s/.iso$//g > $CONF/iso`
mkdir -p $SAVEDIR/$DIRNAME	
cd $SAVEDIR/$DIRNAME
# Get a notify menu 
python3 "/usr/share/pdc/notify/PDC" &
exec $HOME/.pdc/progress &
axel -n 5 $urlsource > $CONF/pdc.log 
echo "Downloading..."
cd $SAVEDIR/$DIRNAME
axel -n 1 $md5sumdownload
# checking md5sum
MD5SUM_IS=`md5sum $ISONAME`
echo $MD5SUM_IS
MD5SUM_SH=`cat $MD5.md5sum`
echo $MD5SUM_SH
if [ "$MD5SUM_IS" = "$MD5SUM_SH" ];then
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 | notify-send -t 35000 -i $ICON "$A2" "Download Completed!" &
sleep 1
pw-play "/usr/share/pdc/sounds/complete.mp3"
# Repeat sound file
pw-play "/usr/share/pdc/sounds/complete.mp3"
else
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 | notify-send -t 10000 -i $EICON "$A2" "Download incomplete error!
Files will be deleted!" &
pw-play "/usr/share/pdc/sounds/dialog-warning.mp3"
# Repeat sound file
pw-play "/usr/share/pdc/sounds/dialog-warning.mp3"
rm -rf "$SAVEDIR/$DIRNAME" 2>/dev/null
fi
  fi
rm -rf $CONF 2>/dev/null 

#---------
# END KDE5 Darkstar
#---------
;;
"$A3")
#------------------------------------------------------------------
# MATE
#------------------------------------------------------------------
# Create a progress info file 
echo \
'#!/bin/bash
CONF="$HOME/.pdc" 
ICON="/usr/share/pdc/icons/pdc.png" 
A3=`cat $CONF/iso-versions | awk NR==3{print} | sed s/.iso$//g`
while true; do 
CONF="$HOME/.pdc"
PROGRESS=("`cut -f 2 -d [ $CONF/pdc.log | cut -f 1 -d ]| tail -n 1`")
AD=$(cat $CONF/iso-versions | awk NR==3{print} > $CONF/iso)
echo "Downloading... "$PROGRESS"  completed" 2>/dev/null >> $CONF/iso; 
sleep 3
done '| awk '{print $0}' > $CONF/progress
chmod a+x "$CONF/progress"
echo \
'#!/bin/bash
if [ $? = "0" ]; then
CONF="$HOME/.pdc"
ICON="/usr/share/pdc/icons/pdc.png"
A3=`cat $CONF/iso-versions | awk NR==3{print} | sed s/.iso$//g`
while true; do
CONF="$HOME/.pdc/pdc.log"
PERCENT=("%")
COUNT=("`grep -E "$PERCENT" $HOME/.pdc/pdc.log|sed 's/^.//'|sed 's/]$//'|sed "s/["]"].*//"|sed 's/.$//'|awk 'END{print}'`")
sleep 0.50;
for ((i=$COUNT; i<="$COUNT"; i++)); do { echo $i; sleep 0.10; } done 
done|yad --window-icon="$ICON" --image="$ICON" --on-top --width=575 --height=100 \
--fixed --center --progress --title="PCLinuxOS Distro Choice" --text=$"\nDownloading  <span color=\"#D95548\">"$A3".iso</span>   Please wait!" \
--button=gtk-close --auto-close
fi'| awk '{print $0}' > $CONF/progressbar
chmod a+x "$CONF/progressbar"
A3=`cat $CONF/iso-versions | awk 'NR==3{print}'`
SNAME=`cat $CONF/iso-versions | awk 'NR==3{print}'`
MD5=`cat $CONF/iso-versions | awk 'NR==3{print}' | sed 's/\.iso$//g'`
ISONAME="$A3"
DIRNAME=`cat $CONF/iso-versions | awk 'NR==3{print $0}' | sed 's/\.iso$//g'`
md5sumdownload=""$REPO"$MD5.md5sum"
urlsource=""$REPO"$ISONAME"
ENTRY=$(yad --width=400 --window-icon=$ICON --center \
        --form --title="PCLinuxOS Distro Choice" \
        --field="Save in:DIR" "$HOME/Desktop" \
--text='\nSelected PCLinuxOS MATE Release' \
--button=Cancel!/usr/share/pdc/icons/cancel.svg:1 --button=Ok!/usr/share/pdc/icons/ok.svg:0)
ret=$?
[[ $ret -eq 1 ]] && exit &&
pkill -SIGKILL yad 2>/dev/null
if [[ $ret -eq 0 ]]; then
    RET=$?

    OIFS=$IFS 
    IFS="|" 
    i=0
    retChoice=()

    for ret in $ENTRY;do 
        retChoice[$i]="$ret"
        i=$(($i+1))
    done

    IFS=$OIFS 
    SAVEDIR=${retChoice[0]} # directory path
DIRNAME=`cat $CONF/iso-versions | awk 'NR==3{print}' | sed 's/\.iso$//g'`
ISO_name=`cat $CONF/iso-versions | awk 'NR==3{print}' | sed s/.iso$//g > $CONF/iso`
mkdir -p $SAVEDIR/$DIRNAME 
cd $SAVEDIR/$DIRNAME
# Get a notify menu 
python3 "/usr/share/pdc/notify/PDC" &
exec $HOME/.pdc/progress &
axel -n 5 $urlsource > $CONF/pdc.log 
echo "Downloading..."
cd $SAVEDIR/$DIRNAME
axel -n 1 $md5sumdownload
# checking md5sum
MD5SUM_IS=`md5sum $ISONAME`
echo $MD5SUM_IS
MD5SUM_SH=`cat $MD5.md5sum`
echo $MD5SUM_SH
if [ "$MD5SUM_IS" = "$MD5SUM_SH" ];then
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 | notify-send -t 35000 -i $ICON "$A3" "Download Completed!" &
sleep 1
pw-play "/usr/share/pdc/sounds/complete.mp3"
# Repeat sound file
pw-play "/usr/share/pdc/sounds/complete.mp3"
else
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 | notify-send -t 10000 -i $EICON "$A3" "Download incomplete error!\nFiles will be deleted!" &
pw-play "/usr/share/pdc/sounds/dialog-warning.mp3"
# Repeat sound file
pw-play "/usr/share/pdc/sounds/dialog-warning.mp3"
rm -rf "$SAVEDIR/$DIRNAME" 2>/dev/null
fi
 fi
rm -rf $CONF 2>/dev/null 
#-------------------------------------
# END MATE
#-------------------------------------
;;
"$A4")
#------------------------------------------------------------------
# XFCE
#------------------------------------------------------------------
# Create a progress info file 
echo \
'#!/bin/bash
CONF="$HOME/.pdc" 
ICON="/usr/share/pdc/icons/pdc.png" 
A4=`cat $CONF/iso-versions | awk NR==4{print} | sed s/.iso$//g`
while true; do 
CONF="$HOME/.pdc"
PROGRESS=("`cut -f 2 -d [ $CONF/pdc.log | cut -f 1 -d ]| tail -n 1`")
AE=$(cat $CONF/iso-versions | awk NR==4{print} > $CONF/iso)
echo "Downloading... "$PROGRESS"  completed" 2>/dev/null >> $CONF/iso; 
sleep 3
done '| awk '{print $0}' > $CONF/progress
chmod a+x "$CONF/progress"
echo \
'#!/bin/bash
if [ $? = "0" ]; then
CONF="$HOME/.pdc"
ICON="/usr/share/pdc/icons/pdc.png"
A4=`cat $CONF/iso-versions | awk NR==4{print} | sed s/.iso$//g`
while true; do
CONF="$HOME/.pdc/pdc.log"
PERCENT=("%")
COUNT=("`grep -E "$PERCENT" $HOME/.pdc/pdc.log|sed 's/^.//'|sed 's/]$//'|sed "s/["]"].*//"|sed 's/.$//'|awk 'END{print}'`")
sleep 0.50;
for ((i=$COUNT; i<="$COUNT"; i++)); do { echo $i; sleep 0.10; } done 
done|yad --window-icon="$ICON" --image="$ICON" --on-top --width=575 --height=100 \
--fixed --center --progress --title="PCLinuxOS Distro Choice" --text=$"\nDownloading  <span color=\"#D95548\">"$A4".iso</span>  Please wait!" \
--button=gtk-close --auto-close
fi'| awk '{print $0}' > $CONF/progressbar
chmod a+x "$CONF/progressbar"
A4=`cat $CONF/iso-versions | awk 'NR==4{print}'`
SNAME=`cat $CONF/iso-versions | awk 'NR==4{print}'`
MD5=`cat $CONF/iso-versions | awk 'NR==4{print}' | sed 's/\.iso$//g'`
ISONAME="$A4"
DIRNAME=`cat $CONF/iso-versions | awk 'NR==4{print}' | sed 's/\.iso$//g'`
md5sumdownload=""$REPO"$MD5.md5sum"
urlsource=""$REPO"$ISONAME"
ENTRY=$(yad --width=400 --window-icon=$ICON --center \
        --form --title="PCLinuxOS Distro Choice" \
        --field="Save in:DIR" "$HOME/Desktop" \
--text='\nSelected PCLinuxOS Xfce Release' \
--button=Cancel!/usr/share/pdc/icons/cancel.svg:1 --button=Ok!/usr/share/pdc/icons/ok.svg:0)
ret=$?
[[ $ret -eq 1 ]] && exit &&
pkill -SIGKILL yad 2>/dev/null
if [[ $ret -eq 0 ]]; then
   RET=$?
    OIFS=$IFS 
    IFS="|" 
    i=0
    retChoice=()

    for ret in $ENTRY;do 
        retChoice[$i]="$ret"
        i=$(($i+1))
    done

    IFS=$OIFS 
    SAVEDIR=${retChoice[0]} # directory path
DIRNAME=`cat $CONF/iso-versions | awk 'NR==4{print}' | sed 's/\.iso$//g'`
ISO_name=`cat $CONF/iso-versions | awk 'NR==4{print}' | sed 's/.iso$//g' > $CONF/iso`
mkdir -p $SAVEDIR/$DIRNAME 
cd $SAVEDIR/$DIRNAME
# Get a notify menu 
python3 "/usr/share/pdc/notify/PDC" &
exec $HOME/.pdc/progress & 
axel -n 5 $urlsource > $CONF/pdc.log 
echo "Downloading..."
cd $SAVEDIR/$DIRNAME
axel -n 1 $md5sumdownload
# checking md5sum
MD5SUM_IS=`md5sum $ISONAME`
echo $MD5SUM_IS
MD5SUM_SH=`cat $MD5.md5sum`
echo $MD5SUM_SH
if [ "$MD5SUM_IS" = "$MD5SUM_SH" ];then
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 | notify-send -t 35000 -i $ICON "$A4" "Download Completed!" &
sleep 1
pw-play "/usr/share/pdc/sounds/complete.mp3"
# Repeat sound file
pw-play "/usr/share/pdc/sounds/complete.mp3"
else
pkill -f PDC > /dev/null 2>&1
pkill -SIGKILL progress > /dev/null 2>&1 
pkill -SIGKILL yad > /dev/null 2>&1 | notify-send -t 10000 -i $EICON "$A4" "Download incomplete error!\nFiles will be deleted!" &
pw-play "/usr/share/pdc/sounds/dialog-warning.mp3"
# Repeat sound file
pw-play "/usr/share/pdc/sounds/dialog-warning.mp3"
rm -rf "$SAVEDIR/$DIRNAME" 2>/dev/null
fi
 fi
rm -rf $CONF 2>/dev/null 
#-------------------------------------
# END XFCE
#-------------------------------------
;;
#---------
# Community iso's
#---------
"Community iso reference site")
exec xdg-open "https://pclosusers.com/communityiso/"
;;
esac
 fi 
rm -rf $CONF > 2>&1 /dev/null 
rm -f /tmp/tmp* > 2>&1 /dev/null
exit 0

 




