bash
function showAll() {
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "--------------------------------------------------------------"
echo "---------------FIRST PATH-------------------------------------"
tragiko1=`cat ${arxikos}/first1.tmp`
for i in "${tragiko1[@]}"
do
echo "$i"
done
echo ""
echo "--------------------------------------------------------------"
echo "---------------SECOND PATH------------------------------------"
tragiko2=`cat ${arxikos}/second1.tmp`
for k in "${tragiko2[@]}"
do
echo "$k"
done
echo "Press enter to continue"
read
}
function show() {
dialog --fselect ${dir1}/ 20 40
dialog --fselect ${dir2}/ 20 40
}
function compare() {
cd $dir1
choice=0
while [ $choice -eq 0 ];do
dialog --title "Choose file" --clear \
--inputbox "Type name of file:" 0 0 2> ${arxikos}/choice1.tmp
choicetmp=`cat ${arxikos}/choice1.tmp`
if [ -s ${arxikos}/choice1.tmp ]; then
if [ -f $choicetmp ]; then
cd $dir2
if [ -f $choicetmp ]; then
choice=1
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "File doesn't exist in dir2"
echo "Press enter to continue"
read
fi
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "File doesn't exist in dir1"
echo "Press enter to continue"
read
fi
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "Prepei na epilekseis kati!"
echo "Press enter to continue"
read
fi
done
awk -v file1=${dir1}/$choicetmp -v file2=${dir2}/$choicetmp 'BEGIN{
while(line1 == line2) {
if(!getline line1 < file1) eof1 = 1;
if(!getline line2 < file2) eof2 = 1;
if( eof1 || eof2 ) break;
}
if(eof1 && eof2)
{
exit 0;
}
else
{
exit 1;
}
}'
var=$?
if [ $var -eq 0 ];then
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "Same"
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "Different"
fi
echo "Press enter to continue"
read
}
function compareD() {
test=1
countl=0
while read i; do
while [ $test -eq 1 ] && read j; do
if [ "$i" = "$j" ];then
test=0
fi
done < ${arxikos}/secondnames.tmp
if [ $test -eq 1 ];then
countl=$[ $countl + 1 ]
fi
test=1
done < ${arxikos}/firstnames.tmp
test=1
countr=0
while read i; do
while [ $test -eq 1 ] && read j; do
if [ "$i" = "$j" ];then
test=0
fi
done < ${arxikos}/firstnames.tmp
if [ $test -eq 1 ];then
countr=$[ $countr + 1 ]
fi
test=1
done < ${arxikos}/secondnames.tmp
countsame1=0
countdiff1=0
countsame2=0
countdiff2=0
while read line1; do
count1=0
while read line2; do
awk -v file1=${dir1}/$line1 -v file2=${dir2}/$line2 'BEGIN{
while(line1 == line2) {
if(!getline line1 < file1) eof1 = 1;
if(!getline line2 < file2) eof2 = 1;
if( eof1 || eof2 ) break;
}
if(eof1 && eof2)
{
exit 0;
}
else
{
exit 1;
}
}'
var=$?
if [ $var -eq 0 ];then
count1=$[ $count1 + 1 ]
break
fi
done < ${arxikos}/secondnames.tmp
if [ $count1 -eq 0 ];then
countdiff1=$[ $countdiff1 + 1 ]
else
countsame1=$[ $countsame1 + $count1 ]
fi
done < ${arxikos}/firstnames.tmp
while read line2; do
count2=0
while read line1; do
awk -v file1=${dir1}/$line1 -v file2=${dir2}/$line2 'BEGIN{
while(line1 == line2) {
if(!getline line1 < file1) eof1 = 1;
if(!getline line2 < file2) eof2 = 1;
if( eof1 || eof2 ) break;
}
if(eof1 && eof2)
{
exit 0;
}
else
{
exit 1;
}
}'
var=$?
if [ $var -eq 0 ];then
count2=$[ $count2 + 1 ]
break
fi
done < ${arxikos}/firstnames.tmp
if [ $count2 -eq 0 ];then
countdiff2=$[ $countdiff2 + 1 ]
else
countsame2=$[ $countsame2 + $count2 ]
fi
done < ${arxikos}/secondnames.tmp
dialog --msgbox "Ston ARISTERO fakelo iparxoun \n $countsame1 arxeia pou exoun idio periexomeno me ta arxeia tou deksi fakelou \n $countdiff1 arxeia me diaforetiko periexomeno kai \n $countl arxeia me monadiko onoma" 12 80
dialog --msgbox "Ston DEKSI fakelo iparxoun\n $countsame2 arxeia pou exoun idio periexomeno me arxeia tou aristerou fakelou \n $countdiff2 arxeia me diaforetiko periexomeno kai \n $countr arxeia me monadiko onoma" 12 80
}
function sortd() {
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
awk -v dirA=${dir1}/ -v dirb=${dir2}/ 'BEGIN {
for(i=1; ( " ls -l " dirA ) | getline LINE; i++ ) {
split(LINE,f," ");
#dimiourgountai pinakes gia ton prwto fakelo. O size1 exei to megethos tou arxeiou, o fname1 to onoma tou ktl
size1[i] = f[5];
date1[i] = f[6];
fname1[i] = f[8];
present_in_dir1[f[8]] = i;
}
#omoiws gia ton deftero fakelo
for(i=1; (" ls -l " dirb) | getline LINE; i++ ) {
split(LINE,f," ");
fname2[i] = f[8];
size2[i] = f[5];
date2[i] = f[6];
present_in_dir2[f[8]] = i;
}
#Dimioourgountai pinakes pou periexoun ta koina arxeia twn 2 fakelwn kai ta monadika.
for(j in fname1)
if( present_in_dir2[fname1[j]] )
common[fname1[j]] = 1;
else
only1[fname1[j]] = 1;
for(j in fname2)
if( !present_in_dir1[fname2[j]] )
only2[fname2[j]] = 1;
#EMfanisi mono twn monadikwn arxeiwn tou aristerou fakelou
for(fname in only1) {
i = present_in_dir1[fname];
printf("%-20s%-10s%-10s\t\n", fname, size1[i], date1[i]);
}
#Emfanisi twn koinwn fakelwn
for(fname in common) {
i = present_in_dir1[fname];
j = present_in_dir2[fname];
printf("%-20s%-10s%-10s\t\t%-20s%-10s%-10s\n", fname, size1[i], date1[i], fname, size2[j], date2[j]);
}
#Emfanisi mono twn monadikwn arxeiwn tou deksiou fakelou
for(fname in only2) {
j = present_in_dir2[fname];
printf("%-20s%-10s%-10s\t\t%-20s%-10s%-10s\n", "", "", "", fname, size2[j], date2[j]);
}
#Molis teleiwnei i awk ta apotelesmata tis dinontai ws eisodo sti sort
}' | sort
echo "Press enter to continue"
read
}
function copylr() {
choice=0
while [ $choice -eq 0 ];do
dialog --title "Choose file" --clear \
--inputbox "Type name of file:" 0 0 2> ${arxikos}/choice1.tmp
retval=$?
if [ $retval -eq 0 ];then
choicetmp=`cat ${arxikos}/choice1.tmp`
cd $dir1
if [ -f $choicetmp ]; then
cd $dir2
if [ -f $choicetmp ]; then
echo "File alrady exists in right folder"
echo "Press enter to continue"
read
else
choice=1
fi
else
echo "File doesn't exist in left folder"
echo "Press enter to continue"
read
fi
fi
done
if [ $choice -eq 1 ]; then
cp ${dir1}/$choicetmp ${dir2}/
retval=$?
if [ $retval -eq 0 ]; then
dialog --msgbox "cp ${dir1}/$choicetmp ${dir2}/ ... Done!" 5 80
else
echo "Error occured!"
fi
fi
}
function copyrl() {
choice=0
while [ $choice -eq 0 ];do
dialog --title "Choose file" --clear \
--inputbox "Type name of file:" 0 0 2> ${arxikos}/choice1.tmp
retval=$?
if [ $retval -eq 0 ];then
choicetmp=`cat ${arxikos}/choice1.tmp`
cd $dir2
if [ -f $choicetmp ]; then
cd $dir1
if [ -f $choicetmp ]; then
echo "File alrady exists in left folder"
echo "Press enter to continue"
read
else
choice=1
fi
else
echo "File doesn't exist in right folder"
echo "Press enter to continue"
read
fi
fi
done
if [ $choice -eq 1 ]; then
cp ${dir2}/$choicetmp ${dir1}/
retval=$?
if [ $retval -eq 0 ]; then
dialog --msgbox "cp ${dir2}/$choicetmp ${dir1}/ ... Done!" 5 80
else
echo "Error occured!"
echo "Press enter to continue"
read
fi
fi
}
function sync() {
dialog --title "Synchronization" \
--menu "Choose one of the following" 20 75 10 \
"SyncL" "Synchronize LEFT folder" \
"SyncR" "Synchronize RIGHT folder" \
"SyncA" "Synchronize BOTH folders" 2> ${arxikos}/syncchoice.tmp
retval=$?
if [ $retval -eq 0 ];then
choice=`cat ${arxikos}/syncchoice.tmp`
case $choice in
SyncL)
syncl;;
SyncR)
syncr;;
SyncA)
synca;;
esac
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "Problem occured... "
echo "Press enter to continue"
read
fi
read
}
function syncl(){
echo "Synchronization of left folder. All files existing in right folder and NOT existing in left, will now be copied!"
var1=`wc -l < ${arxikos}/firstnames.tmp`
var2=`wc -l < ${arxikos}/secondnames.tmp`
k=0
i=1
while [ $i -le $var2 ];
do
line2=`sed -n ${i}p ${arxikos}/secondnames.tmp`
j=1
w=0
while [ $j -le $var1 ];
do
line1=`sed -n ${i}p ${arxikos}/firstnames.tmp`
if [ "$line1" = "$line2" ]; then
w=1
fi
j=$[ $j + 1 ]
done
if [ $w -eq 0 ];then
k=$[ $k + 1 ]
only2[$k]=$line2
fi
i=$[ $i + 1 ]
done
i=1
for i in ${only2[@]};do
cp ${dir2}/$i ${dir1}
done
retval=$?
if [ $retval -eq 0 ];then
dialog --msgbox "Synchronization of LEFT folder is complete!" 5 80
fi
}
function syncr(){
var1=`wc -l < ${arxikos}/firstnames.tmp`
var2=`wc -l < ${arxikos}/secondnames.tmp`
k=0
cat ${arxikos}/firstnames.tmp | while read line1; do
w=0
cat ${arxikos}/secondnames.tmp | while read line2;do
if [ $line1 == $line2 ];then
w=1
fi
done
if [ $w -eq 0 ];then
k=$[ $k + 1 ]
only1[$k]=$line1
fi
done
for i in ${only2[@]};do
cp ${dir2}/$i ${dir1}
done && dialog --msgbox "Synchronization of LEFT folder is complete!" 5 80
}
function synca(){
syncl
syncr
}
main(){
arxikos=`pwd`
dir1=0
while [ ! -d $dir1 ];do
dialog --title "Folder choice" --clear \
--inputbox "Type the 1rst path:" 0 0 2> ${arxikos}/tempfile.tmp
retval=$?
case $retval in
0)
dir1=`cat ${arxikos}/tempfile.tmp`;;
1)
echo "Error1";;
255)
echo "Error2";;
esac
done
dir2=0
while [ ! -d $dir2 ];do
dialog --title "Folder choice" --clear \
--inputbox "Type second path:" 0 0 2> ${arxikos}/tempfile2.tmp
retval=$?
case $retval in
0)
dir2=`cat ${arxikos}/tempfile2.tmp`;;
1)
echo "Error1";;
255)
echo "Error2";;
esac
done
ls -lA $dir1 | grep ^- | awk '{print $5 "\t" $6 "\t" $7 "\t" $NF}' > ${arxikos}/first.tmp
ls -lA $dir2 | grep ^- | awk '{print $5 "\t" $6 "\t" $7 "\t" $NF}' > ${arxikos}/second.tmp
ls -lA $dir1 | grep ^- | sed 1d > ${arxikos}/first1.tmp
ls -lA $dir2 | grep ^- | sed 1d > ${arxikos}/second1.tmp
ls -l $dir1 | grep ^- | awk '{ print $NF }' > ${arxikos}/temp1.tmp
ls -l $dir2 | grep ^- | awk '{ print $NF }' > ${arxikos}/temp2.tmp
cat ${arxikos}/temp1.tmp > ${arxikos}/firstnames.tmp
cat ${arxikos}/temp2.tmp > ${arxikos}/secondnames.tmp
loop=1
while [ $loop -eq 1 ]; do
dialog --clear --title "Epiloges:" \
--menu "Choose what you want to do" 20 75 10 \
"Show" "Shows the folders that have been selected(Only Namefiles)" \
"ShowAll" "Shows the folders that have been selected(with file info)"\
"Compare" "Compare your selected files" \
"CompareD" "Compare directories" \
"Sort" "Sort content of folders" \
"CopyLR" "Select and copy file from left to right" \
"CopyRL" "Select and copy file from right to left" \
"Sync" "Synhronize" \
"Pathch" "Changes paths entered in the beginning" \
"Exit" "Exits program" 2> ${arxikos}/tempchoice.tmp
retval=$?
choice=`cat ${arxikos}/tempchoice.tmp`
case $retval in
0)
echo "You have chosen: '$choice'";;
1)
echo "Canceled!!";;
255)
echo "Exits... Problem ?";;
esac
if [ $retval -eq 0 ];then
case $choice in
Compare)
compare;;
CompareD)
compareD;;
Sort)
sortd;;
CopyLR)
copylr;;
CopyRL)
copyrl;;
Sync)
sync;;
Show)
show;;
ShowAll)
showAll;;
Pathch)
main;;
Exit)
loop=0;;
esac
else
loop=0
fi
done
}
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
dialog --yesno "Gia na treksei swsta afto to script tha prepei na exete energopoiimena ta dialogs!!" 7 60
function showAll() {
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "--------------------------------------------------------------"
echo "---------------FIRST PATH-------------------------------------"
tragiko1=`cat ${arxikos}/first1.tmp`
for i in "${tragiko1[@]}"
do
echo "$i"
done
echo ""
echo "--------------------------------------------------------------"
echo "---------------SECOND PATH------------------------------------"
tragiko2=`cat ${arxikos}/second1.tmp`
for k in "${tragiko2[@]}"
do
echo "$k"
done
echo "Press enter to continue"
read
}
function show() {
dialog --fselect ${dir1}/ 20 40
dialog --fselect ${dir2}/ 20 40
}
function compare() {
cd $dir1
choice=0
while [ $choice -eq 0 ];do
dialog --title "Choose file" --clear \
--inputbox "Type name of file:" 0 0 2> ${arxikos}/choice1.tmp
choicetmp=`cat ${arxikos}/choice1.tmp`
if [ -s ${arxikos}/choice1.tmp ]; then
if [ -f $choicetmp ]; then
cd $dir2
if [ -f $choicetmp ]; then
choice=1
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "File doesn't exist in dir2"
echo "Press enter to continue"
read
fi
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "File doesn't exist in dir1"
echo "Press enter to continue"
read
fi
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "Prepei na epilekseis kati!"
echo "Press enter to continue"
read
fi
done
awk -v file1=${dir1}/$choicetmp -v file2=${dir2}/$choicetmp 'BEGIN{
while(line1 == line2) {
if(!getline line1 < file1) eof1 = 1;
if(!getline line2 < file2) eof2 = 1;
if( eof1 || eof2 ) break;
}
if(eof1 && eof2)
{
exit 0;
}
else
{
exit 1;
}
}'
var=$?
if [ $var -eq 0 ];then
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "Same"
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "Different"
fi
echo "Press enter to continue"
read
}
function compareD() {
test=1
countl=0
while read i; do
while [ $test -eq 1 ] && read j; do
if [ "$i" = "$j" ];then
test=0
fi
done < ${arxikos}/secondnames.tmp
if [ $test -eq 1 ];then
countl=$[ $countl + 1 ]
fi
test=1
done < ${arxikos}/firstnames.tmp
test=1
countr=0
while read i; do
while [ $test -eq 1 ] && read j; do
if [ "$i" = "$j" ];then
test=0
fi
done < ${arxikos}/firstnames.tmp
if [ $test -eq 1 ];then
countr=$[ $countr + 1 ]
fi
test=1
done < ${arxikos}/secondnames.tmp
countsame1=0
countdiff1=0
countsame2=0
countdiff2=0
while read line1; do
count1=0
while read line2; do
awk -v file1=${dir1}/$line1 -v file2=${dir2}/$line2 'BEGIN{
while(line1 == line2) {
if(!getline line1 < file1) eof1 = 1;
if(!getline line2 < file2) eof2 = 1;
if( eof1 || eof2 ) break;
}
if(eof1 && eof2)
{
exit 0;
}
else
{
exit 1;
}
}'
var=$?
if [ $var -eq 0 ];then
count1=$[ $count1 + 1 ]
break
fi
done < ${arxikos}/secondnames.tmp
if [ $count1 -eq 0 ];then
countdiff1=$[ $countdiff1 + 1 ]
else
countsame1=$[ $countsame1 + $count1 ]
fi
done < ${arxikos}/firstnames.tmp
while read line2; do
count2=0
while read line1; do
awk -v file1=${dir1}/$line1 -v file2=${dir2}/$line2 'BEGIN{
while(line1 == line2) {
if(!getline line1 < file1) eof1 = 1;
if(!getline line2 < file2) eof2 = 1;
if( eof1 || eof2 ) break;
}
if(eof1 && eof2)
{
exit 0;
}
else
{
exit 1;
}
}'
var=$?
if [ $var -eq 0 ];then
count2=$[ $count2 + 1 ]
break
fi
done < ${arxikos}/firstnames.tmp
if [ $count2 -eq 0 ];then
countdiff2=$[ $countdiff2 + 1 ]
else
countsame2=$[ $countsame2 + $count2 ]
fi
done < ${arxikos}/secondnames.tmp
dialog --msgbox "Ston ARISTERO fakelo iparxoun \n $countsame1 arxeia pou exoun idio periexomeno me ta arxeia tou deksi fakelou \n $countdiff1 arxeia me diaforetiko periexomeno kai \n $countl arxeia me monadiko onoma" 12 80
dialog --msgbox "Ston DEKSI fakelo iparxoun\n $countsame2 arxeia pou exoun idio periexomeno me arxeia tou aristerou fakelou \n $countdiff2 arxeia me diaforetiko periexomeno kai \n $countr arxeia me monadiko onoma" 12 80
}
function sortd() {
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
awk -v dirA=${dir1}/ -v dirb=${dir2}/ 'BEGIN {
for(i=1; ( " ls -l " dirA ) | getline LINE; i++ ) {
split(LINE,f," ");
#dimiourgountai pinakes gia ton prwto fakelo. O size1 exei to megethos tou arxeiou, o fname1 to onoma tou ktl
size1[i] = f[5];
date1[i] = f[6];
fname1[i] = f[8];
present_in_dir1[f[8]] = i;
}
#omoiws gia ton deftero fakelo
for(i=1; (" ls -l " dirb) | getline LINE; i++ ) {
split(LINE,f," ");
fname2[i] = f[8];
size2[i] = f[5];
date2[i] = f[6];
present_in_dir2[f[8]] = i;
}
#Dimioourgountai pinakes pou periexoun ta koina arxeia twn 2 fakelwn kai ta monadika.
for(j in fname1)
if( present_in_dir2[fname1[j]] )
common[fname1[j]] = 1;
else
only1[fname1[j]] = 1;
for(j in fname2)
if( !present_in_dir1[fname2[j]] )
only2[fname2[j]] = 1;
#EMfanisi mono twn monadikwn arxeiwn tou aristerou fakelou
for(fname in only1) {
i = present_in_dir1[fname];
printf("%-20s%-10s%-10s\t\n", fname, size1[i], date1[i]);
}
#Emfanisi twn koinwn fakelwn
for(fname in common) {
i = present_in_dir1[fname];
j = present_in_dir2[fname];
printf("%-20s%-10s%-10s\t\t%-20s%-10s%-10s\n", fname, size1[i], date1[i], fname, size2[j], date2[j]);
}
#Emfanisi mono twn monadikwn arxeiwn tou deksiou fakelou
for(fname in only2) {
j = present_in_dir2[fname];
printf("%-20s%-10s%-10s\t\t%-20s%-10s%-10s\n", "", "", "", fname, size2[j], date2[j]);
}
#Molis teleiwnei i awk ta apotelesmata tis dinontai ws eisodo sti sort
}' | sort
echo "Press enter to continue"
read
}
function copylr() {
choice=0
while [ $choice -eq 0 ];do
dialog --title "Choose file" --clear \
--inputbox "Type name of file:" 0 0 2> ${arxikos}/choice1.tmp
retval=$?
if [ $retval -eq 0 ];then
choicetmp=`cat ${arxikos}/choice1.tmp`
cd $dir1
if [ -f $choicetmp ]; then
cd $dir2
if [ -f $choicetmp ]; then
echo "File alrady exists in right folder"
echo "Press enter to continue"
read
else
choice=1
fi
else
echo "File doesn't exist in left folder"
echo "Press enter to continue"
read
fi
fi
done
if [ $choice -eq 1 ]; then
cp ${dir1}/$choicetmp ${dir2}/
retval=$?
if [ $retval -eq 0 ]; then
dialog --msgbox "cp ${dir1}/$choicetmp ${dir2}/ ... Done!" 5 80
else
echo "Error occured!"
fi
fi
}
function copyrl() {
choice=0
while [ $choice -eq 0 ];do
dialog --title "Choose file" --clear \
--inputbox "Type name of file:" 0 0 2> ${arxikos}/choice1.tmp
retval=$?
if [ $retval -eq 0 ];then
choicetmp=`cat ${arxikos}/choice1.tmp`
cd $dir2
if [ -f $choicetmp ]; then
cd $dir1
if [ -f $choicetmp ]; then
echo "File alrady exists in left folder"
echo "Press enter to continue"
read
else
choice=1
fi
else
echo "File doesn't exist in right folder"
echo "Press enter to continue"
read
fi
fi
done
if [ $choice -eq 1 ]; then
cp ${dir2}/$choicetmp ${dir1}/
retval=$?
if [ $retval -eq 0 ]; then
dialog --msgbox "cp ${dir2}/$choicetmp ${dir1}/ ... Done!" 5 80
else
echo "Error occured!"
echo "Press enter to continue"
read
fi
fi
}
function sync() {
dialog --title "Synchronization" \
--menu "Choose one of the following" 20 75 10 \
"SyncL" "Synchronize LEFT folder" \
"SyncR" "Synchronize RIGHT folder" \
"SyncA" "Synchronize BOTH folders" 2> ${arxikos}/syncchoice.tmp
retval=$?
if [ $retval -eq 0 ];then
choice=`cat ${arxikos}/syncchoice.tmp`
case $choice in
SyncL)
syncl;;
SyncR)
syncr;;
SyncA)
synca;;
esac
else
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
echo "Problem occured... "
echo "Press enter to continue"
read
fi
read
}
function syncl(){
echo "Synchronization of left folder. All files existing in right folder and NOT existing in left, will now be copied!"
var1=`wc -l < ${arxikos}/firstnames.tmp`
var2=`wc -l < ${arxikos}/secondnames.tmp`
k=0
i=1
while [ $i -le $var2 ];
do
line2=`sed -n ${i}p ${arxikos}/secondnames.tmp`
j=1
w=0
while [ $j -le $var1 ];
do
line1=`sed -n ${i}p ${arxikos}/firstnames.tmp`
if [ "$line1" = "$line2" ]; then
w=1
fi
j=$[ $j + 1 ]
done
if [ $w -eq 0 ];then
k=$[ $k + 1 ]
only2[$k]=$line2
fi
i=$[ $i + 1 ]
done
i=1
for i in ${only2[@]};do
cp ${dir2}/$i ${dir1}
done
retval=$?
if [ $retval -eq 0 ];then
dialog --msgbox "Synchronization of LEFT folder is complete!" 5 80
fi
}
function syncr(){
var1=`wc -l < ${arxikos}/firstnames.tmp`
var2=`wc -l < ${arxikos}/secondnames.tmp`
k=0
cat ${arxikos}/firstnames.tmp | while read line1; do
w=0
cat ${arxikos}/secondnames.tmp | while read line2;do
if [ $line1 == $line2 ];then
w=1
fi
done
if [ $w -eq 0 ];then
k=$[ $k + 1 ]
only1[$k]=$line1
fi
done
for i in ${only2[@]};do
cp ${dir2}/$i ${dir1}
done && dialog --msgbox "Synchronization of LEFT folder is complete!" 5 80
}
function synca(){
syncl
syncr
}
main(){
arxikos=`pwd`
dir1=0
while [ ! -d $dir1 ];do
dialog --title "Folder choice" --clear \
--inputbox "Type the 1rst path:" 0 0 2> ${arxikos}/tempfile.tmp
retval=$?
case $retval in
0)
dir1=`cat ${arxikos}/tempfile.tmp`;;
1)
echo "Error1";;
255)
echo "Error2";;
esac
done
dir2=0
while [ ! -d $dir2 ];do
dialog --title "Folder choice" --clear \
--inputbox "Type second path:" 0 0 2> ${arxikos}/tempfile2.tmp
retval=$?
case $retval in
0)
dir2=`cat ${arxikos}/tempfile2.tmp`;;
1)
echo "Error1";;
255)
echo "Error2";;
esac
done
ls -lA $dir1 | grep ^- | awk '{print $5 "\t" $6 "\t" $7 "\t" $NF}' > ${arxikos}/first.tmp
ls -lA $dir2 | grep ^- | awk '{print $5 "\t" $6 "\t" $7 "\t" $NF}' > ${arxikos}/second.tmp
ls -lA $dir1 | grep ^- | sed 1d > ${arxikos}/first1.tmp
ls -lA $dir2 | grep ^- | sed 1d > ${arxikos}/second1.tmp
ls -l $dir1 | grep ^- | awk '{ print $NF }' > ${arxikos}/temp1.tmp
ls -l $dir2 | grep ^- | awk '{ print $NF }' > ${arxikos}/temp2.tmp
cat ${arxikos}/temp1.tmp > ${arxikos}/firstnames.tmp
cat ${arxikos}/temp2.tmp > ${arxikos}/secondnames.tmp
loop=1
while [ $loop -eq 1 ]; do
dialog --clear --title "Epiloges:" \
--menu "Choose what you want to do" 20 75 10 \
"Show" "Shows the folders that have been selected(Only Namefiles)" \
"ShowAll" "Shows the folders that have been selected(with file info)"\
"Compare" "Compare your selected files" \
"CompareD" "Compare directories" \
"Sort" "Sort content of folders" \
"CopyLR" "Select and copy file from left to right" \
"CopyRL" "Select and copy file from right to left" \
"Sync" "Synhronize" \
"Pathch" "Changes paths entered in the beginning" \
"Exit" "Exits program" 2> ${arxikos}/tempchoice.tmp
retval=$?
choice=`cat ${arxikos}/tempchoice.tmp`
case $retval in
0)
echo "You have chosen: '$choice'";;
1)
echo "Canceled!!";;
255)
echo "Exits... Problem ?";;
esac
if [ $retval -eq 0 ];then
case $choice in
Compare)
compare;;
CompareD)
compareD;;
Sort)
sortd;;
CopyLR)
copylr;;
CopyRL)
copyrl;;
Sync)
sync;;
Show)
show;;
ShowAll)
showAll;;
Pathch)
main;;
Exit)
loop=0;;
esac
else
loop=0
fi
done
}
echo -ne "\e[44m\e[37m\e[2J\e[2;0f"
dialog --yesno "Gia na treksei swsta afto to script tha prepei na exete energopoiimena ta dialogs!!" 7 60
retval=$?
if [ $retval -eq 0 ];then
main
elif [ $retval -eq 1 ];then
exit
else
echo "Program occured"
fi
retval=$?
if [ $retval -eq 0 ];then
main
elif [ $retval -eq 1 ];then
exit
else
echo "Program occured"
fi