aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/usr/bin/drive-sync
blob: d56a655b110afb1f22591d14a9dc34c3afd1c441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
#!/bin/bash
###################################################################################################
# drive-sync
###################################################################################################
# Copyright 2017-2023 Jean-Christophe Manciot <jcmanciot@sdxlive.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 
# in compliance with the License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# This script is using a project hosted at https://github.com/odeke-em/drive, originally developed 
# by Burcu Dogan while working on the Google Drive team and now maintained by Emmanuel T Odeke.
#
# Attribution — You must give appropriate credit, provide a link to the license, and indicate if 
#               changes were made. You may do so in any reasonable manner, but not in any way that 
#               suggests the licensor endorses you or your use.
###################################################################################################

###################################################################################################
#
# Listing then syncing all files/folders (objects) which are not synced between your local & remote 
# Google Drive recursively from the directory where the call is made.
#
# There are 3 modes of operation:
# - Fully-Automated: it does **not** ask for user confirmation & offers 3 different types of master:
#       + None: all local & remote modified objects are synced, but trashed/deleted 
#               objects are not synced
#               * all objects fresher locally are pushed
#               * all objects fresher remotely are pulled
#               * all objects missing locally are ignored
#               * all objects missing remotely are ignored
#       + Local: your remote Google Drive is mirrored from your local GD
#               * all objects missing remotely are pushed
#               * all objects fresher locally are pushed
#               * all objects missing locally are trashed remotely
#       + Remote: your local Google Drive is mirrored from your remote GD
#               * all objects missing locally are pulled
#               * all objects fresher remotely are pulled
#               * all objects missing remotely are trashed locally
# - Semi-Automated: it asks for user confirmation & offers 3 different types of master:
#       + None: all local & remote modified objects are synced, but trashed/deleted 
#               objects are not synced
#               * all objects fresher locally are pushed
#               * all objects fresher remotely are pulled
#               * all objects missing locally are ignored
#               * all objects missing remotely are ignored
#       + Local: your remote Google Drive is mirrored from your local GD folder
#               * all objects missing remotely are pushed
#               * all objects fresher locally are pushed
#               * all objects missing locally are trashed remotely
#       + Remote: your local Google Drive is mirrored from your remote GD
#               * all objects missing locally are pulled
#               * all objects fresher remotely are pulled
#               * all objects missing remotely are trashed locally
# - Manual: it asks for user confirmation & offers a choice of one or a correct combination of 8 
#           commands; in case of conflict, the first choice will be tried first. 
#           In this mode, all push & pull operations are **forced**, meaning that the 
#           selected objects are pushed or pulled even if their local and remote contents are
#           identical, but their destination date/time comes from their source. 
#               * Push remotely all objects present only locally
#               * Push remotely all objects older locally to revert all remote fresher objects
#               * Push remotely all objects fresher locally to update older remote objects
#               * Push remotely all selected local objects to create/update remote objects
#               * Pull locally all objects present only remotely
#               * Pull locally all objects fresher remotely to update older local objects
#               * Pull locally all objects older remotely to revert all local fresher objects
#               * Pull locally all selected remote objects to create/update local objects
#               * Trash locally all objects present only locally
#               * Trash remotely all objects present only remotely
#
# Each operation is performed once the following lists are discovered:
#       - Objects which are only present locally, i.e missing remotely
#       - Objects which are only present remotely, i.e missing locally
#       - Objects which are fresher locally 
#       - Objects which are fresher remotely
#
# For the last 2 categories, depending on the value of ignore-checksum option in 
# <google_drive_folder>/.driverc:
#       - true:  only the dates/times of all objects present both locally and remotely are
#                UTC-converted and compared. 
#                This means that if their content is identical but their dates/times are different,
#                they will be considered as **unsynced**.
#                This is the default value & behavior.
#       - false: the MD5 checksums of all objects present both locally and remotely are  
#                compared and in case they are different, their respective dates/times are 
#                UTC-converted and compared. 
#                This means that if their content is identical (same MD5 checksum) but their 
#                dates/times are different, they will be considered as **synced**. 
# 
# All objects not listed are already synced or there has been a connection error to 
# https://www.googleapis.com/drive/v2/files and/or https://accounts.google.com/o/oauth2/token 
# during the process preventing the operation to complete correctly.
#
# Once an operation has been selected, it is executed in the same folder as the one where 
# 'drive-sync' has been called, selecting files/folders (objects) using configuration found in all
# following files:
#       - <google_drive_folder>/.driverc
#       - <google_drive_folder>/.driveignore
#       - ./.driveselect.
#
# By default, all your objects recursively found below the current working directory are affected 
# by the chosen drive command. 
#
# You may modify the default scale of each operation using depth setting(s) in your 
# <google_drive_folder>/.driverc, **except** when trashing folders.
#
# The list of objects affected by this operation can be optionnaly also filtered by:
#       - <google_drive_folder>/.driveignore
#       - ./.driveselect
#
###################################################################################################
#
# Requirements:
# ------------
#
# - We assume that:
#       + drive-google package is already installed, including all drive-* scripts.
#       + leap-year & convert-date-time-to-utc utilities are available.
#       + coreutils, grep, perl-base, sed, trash-cli & zenity packages are already installed.
#
# - This command must be called from within your local Google drive folder(s).
#
# - <google_drive_folder>/.driverc:it must be properly setup, either manually or with drive-setup,
#                                  with the following settings:
#       * depth=
#               + -1: an infinite traversal depth, i.e recursive traversal from the current working  
#                     directory until there is no more child folder
#               + non-zero number: a fixed traversal depth
#       * ignore-checksum=
#               + true: objects checksum is not verified, including during the process listing all
#                       objects which are fresher locally & remotely
#               + false: objects checksum is verified, including during the process listing all
#                       objects which are fresher locally & remotely
#       * encryption-password="<your_secret>": drive optionally encrypts all pushed objects at rest
#                                              on your Google Drive
#       * decryption-password="<your_secret>": drive optionally decrypts all pulled objects which 
#                                              are encrypted at rest on your Google Drive online.
#       * ...: cf. https://github.com/odeke-em/drive for a complete list of available  
#              options. They can only be set manually through .driverc or through drive-setup for
#              the sake of simplicity.
#              Cf. /etc/drive-google/.driverc for some examples.
#
# - <google_drive_folder>/.driveignore: it may be used to exclude/include some objects from the 
#                                       scope of the current drive-<command> by using regular
#                                       expressions.
#                                       Cf. /etc/drive-google/.driveignore for its format & some 
#                                       examples.
#
# - ./.driveselect: it may be used to include/exclude the objects from the scope of the current 
#                   drive-<command>. 
#                   Cf. /etc/drive-google/.driveselect for its format & some examples.
#
###################################################################################################
#
# Parameters:
# ----------
#
# - <anything> will display this help message
#
###################################################################################################
#
# Notes:
# -----
#
# - One must be **cautious** with this command: a list of potentially affected objects will be
#   printed before each actual operation.
#   I recommend to perform a backup of your local Google Drive folder before running this command.
#
# - Its performance is proportional to: 
#       + the chosen operation
#       + the number of all the objects recursively found locally and on your remote Google Drive
#       + the size of all the objects that need to be synced (pulled and/or pushed)
#       + the end-to-end bandwidth, latency & quality of your current Internet connection to your 
#         Google Drive online.
#
# - In order to **drastically** improve its performances, you can:
#       + restrict the number of objects affected by the chosen operation by setting:
#               * <google_drive_folder>/.driverc: depth
#               * <google_drive_folder>/.driveignore: filter
#               * ./.driveselect: list of objects under the right [<command>] section.
#       + and/or move to the deepest folder which recursively contains the affected objects
#         before calling drive-sync.
#       + **remove, i.e comment** in <google_drive_folder>/.driverc some settings:
#               * checksum verification: # ignore-checksum=false
#               * any sorting: # --sort=name,version,modt,size_r...
#
###################################################################################################
#
# Usage example:
# -------------
#
# cd ~/<google_drive_folder>/any/sub/folder
# drive-sync
#
###################################################################################################
if [[ $LOG_DRIVE_SYNC == ON ]]; then
        # Getting the last existing file descriptor of ~/.drive-google/logs/drive-google.log
        fd=$(ls -al /proc/$$/fd | grep ~/.drive-google/logs/drive-google.log | sed -E 's|^.* ([0-9]+) -> .*$|\1|g' | sort -V | tail -n 1)

        # Case where fd is unset, i.e the file ~/.drive-google/logs/drive-google.log has not yet been opened
        if [[ -z $fd ]]; then
                lowest_unused_fd () 
                {
                        local fd=0
                        while [ -e /proc/$$/fd/${fd} ]; do
                                fd=$((fd+1))
                        done
                        echo $fd
                }
                fd=$(lowest_unused_fd)

                # Opening ~/.drive-google/logs/drive-google.log as file descriptor $fd for appending
                eval "exec $fd>> ~/.drive-google/logs/drive-google.log"
        fi

        # Writing the trace output generated when set -x is enabled to file descriptor $fd 
        eval "BASH_XTRACEFD=$fd"
        # Logging line numbers - We could also use ${0} for ${BASH_SOURCE}
        BASH_SOURCE_BASENAME=$(basename ${BASH_SOURCE})
        export PS4='${BASH_SOURCE_BASENAME}.${LINENO}+ '
        # Expanding all variables and prints the full commands before output of the command
        set -x
fi

# Preventing globbing (pathname expansion)
set -o noglob
# Allowing extended globbing
shopt -s extglob
# Expanding aliases
shopt -s expand_aliases

# Including alias definitions to sed/grep/awk/perl commands for readability sake
. /usr/include/drive-google/aliases

#------------------------------------list-objects-present-locally----------------------------
# Listing recursively all objects present locally
# Usage: readarray -t objects_present_locally < <(list-objects-present-locally)
# Error code: '§' in first element of single element array
function list-objects-present-locally ()
{
        local objects_present_locally=()
        readarray -t objects_present_locally < <(.drive-select-objects 'local_fs' 'sync')

        if [[ "${objects_present_locally[0]}" =~ 'Connection error accessing your Google Drive online in' ]]; then
                # Nothing can be done
                zenity --error --title "Fatal Error" --text="Operation cancelled" --width 800
                echo '§'
        elif [[ ${#objects_present_locally[@]} -ne 0 ]]; then
                # Child shells cannot modify anything in parent
                printf '%s\n' "${objects_present_locally[@]}"
        fi    
}

#------------------------------------list-objects-present-remotely---------------------------
# Listing recursively all objects present remotely
# Usage: readarray -t objects_present_remotely < <(list-objects-present-remotely)
# Error code: '§' in first element of single element array
function list-objects-present-remotely ()
{
        local objects_present_remotely=()
        readarray -t objects_present_remotely < <(.drive-select-objects 'remote_fs' 'sync')

        if [[ "${objects_present_remotely[0]}" =~ 'Connection error accessing your Google Drive online in' ]]; then
                # Nothing can be done
                zenity --error --title "Fatal Error" --text="Operation cancelled" --width 800
                echo '§'
        elif [[ ${#objects_present_remotely[@]} -ne 0 ]]; then
                # Child shells cannot modify anything in parent
                printf '%s\n' "${objects_present_remotely[@]}"
        fi              
}

#------------------------------------list-objects-absent-locally-----------------------------
# Listing recursively all objects missing locally
# Usage: readarray -t unsynced_objects_absent_locally < <(list-objects-absent-locally)
# Error code: '§' in first element of single element array
# The function uses the global array variables:
# - "${objects_present_remotely[@]}"
# - "${objects_present_locally[@]}"
function list-objects-absent-locally ()
{
	# Reading all lines listing all remote objects
        local unsynced_objects_absent_locally=()
        local unsynced_objects_absent_locally_index=0

        # Comparing both arrays with comm would lead to erratic resultss, whatever the output-delimiter is, including '\0'
        # We have to perform this comparison manually
        # Bash incorrectly continues the inner loop even though the first array is empty - so the following test is necessary
        if [[ ${#objects_present_remotely[@]} -ne 0 ]]; then
                for object_present_remotely in "${objects_present_remotely[@]}"
                do
                        # Removing leading object stats
                        remote_object=$(echo "$object_present_remotely" | rm_object_stats)

                        # Searching the $object_present_remotely name inside objects_present_locally[@]
                        for object_present_locally in "${objects_present_locally[@]}"
                        do
                                # Removing leading object stats
                                local_object=$(echo "$object_present_locally" | rm_object_stats)

                                if [[ "$local_object" == "$remote_object" ]]; then
                                        # Found: moving on to the next object_present_remotely in ${objects_present_remotely[@]}
                                        continue 2
                                fi
                        done
                        # Not found
                        unsynced_objects_absent_locally[$unsynced_objects_absent_locally_index]="$object_present_remotely"
                        ((unsynced_objects_absent_locally_index++))
                done
        fi

        if [[ ${#unsynced_objects_absent_locally[@]} -eq 0 ]]; then
                # No objects are missing locally        
                zenity --warning --title "Listing 0 Google Drive objects missing locally in ${noamp_local_folder}" --text="None is missing locally" --width=1400
        else
                printf '%s\n' "${unsynced_objects_absent_locally[@]}" | zenity --text-info --title "Listing ${#unsynced_objects_absent_locally[@]} Google Drive objects missing locally in ${noamp_local_folder}" --width 1800 --height 800
                if [[ ${PIPESTATUS[1]} -ne 0 ]]; then
                        # Cancel has been selected
                        zenity --warning --title "Syncing selected local/remote objects" --text="Operation cancelled" --width=800
                        echo '§'
                elif [[ ${#unsynced_objects_absent_locally[@]} -ne 0 ]]; then
                        # Child shells cannot modify anything in parent
                        printf '%s\n' "${unsynced_objects_absent_locally[@]}"
                fi
        fi
}

#------------------------------------list-objects-absent-remotely----------------------------
# Listing recursively all objects missing remotely
# Usage: readarray -t unsynced_objects_absent_remotely < <(list-objects-absent-remotely)
# Error code: '§' in first element of single element array
# The function uses the global array variables:
# - "${objects_present_locally[@]}"
# - "${objects_present_remotely[@]}"
function list-objects-absent-remotely ()
{
	# Reading all lines listing all local objects
        local unsynced_objects_absent_remotely=()
        local unsynced_objects_absent_remotely_index=0

        # Comparing both arrays with comm would lead to erratic resultss, whatever the output-delimiter is, including '\0'
        # We have to perform this comparison manually
        # Bash incorrectly continues the inner loop even though the first array is empty - so the following test is necessary
        if [[ ${#objects_present_locally[@]} -ne 0 ]]; then
                for object_present_locally in "${objects_present_locally[@]}"
                do
                        # Removing leading object stats
                        local_object=$(echo "$object_present_locally" | rm_object_stats)

                        # Searching the $object_present_locally name inside objects_present_remotely[@]
                        for object_present_remotely in "${objects_present_remotely[@]}"
                        do
                                # Removing leading object stats
                                remote_object=$(echo "$object_present_remotely" | rm_object_stats)

                                if [[ "$local_object" == "$remote_object" ]]; then
                                        # Found: moving on to the next object_present_locally in ${objects_present_locally[@]}
                                        continue 2
                                fi
                        done
                        # Not found
                        unsynced_objects_absent_remotely[$unsynced_objects_absent_remotely_index]="$object_present_locally"
                        ((unsynced_objects_absent_remotely_index++))
                done
        fi

        if [[ ${#unsynced_objects_absent_remotely[@]} -eq 0 ]]; then
                # No objects are missing remotely        
                zenity --warning --title "Listing 0 Google Drive objects missing remotely in ${noamp_local_folder}" --text="None is missing remotely" --width=1400
        else
                printf '%s\n' "${unsynced_objects_absent_remotely[@]}" | zenity --text-info --title "Listing ${#unsynced_objects_absent_remotely[@]} Google Drive objects missing remotely in ${noamp_local_folder}" --width 1800 --height 800
                if [[ ${PIPESTATUS[1]} -ne 0 ]]; then
                        # Cancel has been selected
                        zenity --warning --title "Syncing selected local/remote objects" --text="Operation cancelled" --width=800
                        echo '§'
                elif [[ ${#unsynced_objects_absent_remotely[@]} -ne 0 ]]; then
                        # Child shells cannot modify anything in parent
                        printf '%s\n' "${unsynced_objects_absent_remotely[@]}"
                fi
        fi
}

#------------------------------------list-unsynced-objects-fresher---------------------------
# Listing recursively all objects unsynced present locally & remotely
# Usage: readarray -t unsynced_objects_fresher < <(list-unsynced-objects-fresher)
# Since we need to return 2 arrays but only one is allowed:
# - "${unsynced_objects_fresher_locally[@]}" & "${unsynced_objects_fresher_remotely[@]}" are concatenated 
#   into "${unsynced_objects_fresher[@]}"
# - 2 elements are added at the end of the resulting array:
#       + penultimate element:  size of ${unsynced_objects_fresher_locally[@]}
#       + last element:         size of ${unsynced_objects_fresher_remotely[@]}
# Error code: '§' in first element of single element array
# The function uses the global array variables:
# - "${objects_present_remotely[@]}"
function list-unsynced-objects-fresher ()
{
        # Array containing the list of objects for which the date_time need to be compared
        # Objects listed in ${objects[@]} does NOT contain their type
        local objects=()

        # Reading ignore-checksum option value from .driverc
        ignore_checksum=$(.drive-read-driverc ignore-checksum sync)

#-------MD5 checksum is ON: listing all objects present both locally and remotely with a different MD5sum
        if [[ $ignore_checksum == 'false' ]]; then
                # Comparing all MD5 hashes netween local & remote objects
                local md5sum_compared_objects=()

                # Comparing the MD5sum of all objects which are present both locally and remotely
                for object in "${objects_present_remotely[@]}"
                do
                        # Removing leading object stats
                        object=$(echo "$object" | rm_object_stats)

                        # Checking if object is present locally
                        if [[ (-f "${object}") || (-d "${object}") ]]; then
                                # This $object is present both locally and remotely
                                # - Computing the md5sum of remote $object 
                                # - fixing the object name in the result
                                # - comparing it with its local equivalent
                                # - storing the resulting line in array ${md5sum_compared_objects[@]}
                                line=$((drive md5sum -depth 0 "$object" | cut -d ' ' -f 1 | echo "$(cat -) ${object}" | md5sum -c) 2>&1)
                                md5sum_compared_objects=("${md5sum_compared_objects[@]}" "$line")
                        else
                                # The object is not present locally, continue
                                continue
                        fi
                done

	        # Listing all objects which have a different MD5sum and so are considered unsynced
                # Objects listed in ${unsynced_objects[@]} does not contain their type
                local unsynced_objects=()
                local unsynced_objects_index=0
                for line in "${md5sum_compared_objects[@]}"
                do
                        # Searching the lines containing "FAILED md5sum", 
                        if [[ $line =~ FAILED[[:blank:]]md5sum ]]; then
                                unsynced_objects[$unsynced_objects_index]=$(echo $line | cut -d ':' -f 1)
                                ((unsynced_objects_index++))
                        fi
                done

                # Initializing the array for date_time comparison
                objects=("${unsynced_objects[@]}")

#-------MD5 checksum is OFF by default: listing all objects present both locally and remotely
        else
                # Gathering all objects present both locally and remotely
                # Objects listed in ${objects_present_locally_and_remotely[@]} does not contain their type
                local objects_present_locally_and_remotely=()
                for object in "${objects_present_remotely[@]}"
                do
                        # Removing leading object stats
                        object=$(echo "$object" | rm_object_stats)

                        # Checking if object is present locally
                        if [[ (-f "${object}") || (-d "${object}") ]]; then
                                # This $object is present both locally and remotely
                                objects_present_locally_and_remotely=("${objects_present_locally_and_remotely[@]}" "$object")
                        else
                                # The object is not present locally, continue
                                continue
                        fi
                done

                # Initializing the array for date_time comparison
                objects=("${objects_present_locally_and_remotely[@]}")
        fi

#-------Comparing both date_time of previously listed objects after conversion to UTC--------
        local unsynced_objects_fresher_locally=()
        local unsynced_objects_fresher_remotely=()
        local unsynced_objects_fresher=()
        local unsynced_objects_fresher_locally_index=0
        local unsynced_objects_fresher_remotely_index=0
        for object in "${objects[@]}"
	do
                if [[ -f "$object" ]]; then
                        # Getting locally modified date & time of $object
                        local_modify_date_time=$(stat -L -c %y "$object")

                        # Removing all occurrences of '&' in $object as a workaround to a markup ampersand issue with zenity
                        noamp_object=$(echo "${object}" | rm_ampersand)

                        # While there is a connection error and the user wants to continue trying
                        while :
                        do
                                # Getting remotely modified date & time of $object
                                remote_modify_date_time=$(drive stat -depth 0 "$object" 2>&1 | grep ModTime | extract_modtime)

                                if [[ -z $remote_modify_date_time ]]; then
                                        check-internet-connectivity
                                        if [[ $? -ne 0 ]]; then
                                                # Connection error
                                                # Displaying the error
                                                zenity --error --title "Connection error accessing your Google Drive online in ${noamp_local_folder}" --text="${noamp_object}\n\nCould not connect to https://www.googleapis.com/drive/v2/files or/nor to https://accounts.google.com/o/oauth2/token" --width 1400
                                                zenity --question --title "Connection error accessing your Google Drive online in ${noamp_local_folder}" --text="${noamp_object}\n\nDo you want to abort current drive operation?" --width 1400
        
                                                if [[ $? -eq 1 ]]; then
                                                        # Continuing trying
                                                        continue
                                                elif [[ $? -eq 0 ]]; then
                                                        # Aborting
                                                        exit 9
                                                fi
                                        else
                                                # There is Internet connectivity
                                                # The object has disappeared - deleted or moved - online in the meantime
                                                continue
                                        fi
                                else
                                        # No connection error
                                        break
                                fi
                        done

                        # Converting both date_time to UTC and rounding up/down the seconds
                        local_modify_utc_date_time="$(convert-date-time-to-utc "$local_modify_date_time")"
                        remote_modify_utc_date_time="$(convert-date-time-to-utc "$remote_modify_date_time")"

                        # Converting both date_time to seconds since epoch
                        local_modify_utc_date_time_seconds=$(date -u -d"$local_modify_utc_date_time" +%s)
                        if [[ $? -ne 0 ]]; then
                                zenity --error --title "Date error in drive-sync" --text="\tUnknown date format: $local_modify_utc_date_time\n${noamp_local_folder}/${noamp_object}\nPlease report that issue to: https://gitlab.com/jean-christophe-manciot/Drive/issues" --width 1200
                        fi
                        remote_modify_utc_date_time_seconds=$(date -u -d"$remote_modify_utc_date_time" +%s)
                        if [[ $? -ne 0 ]]; then
                                zenity --error --title "Date error in drive-sync" --text="\tUnknown date format: $remote_modify_utc_date_time\n${noamp_local_folder}/${noamp_object}\nPlease report that issue to: https://gitlab.com/jean-christophe-manciot/Drive/issues" --width 1200
                        fi

                        # Comparing both
                        # There may be 1 second of difference when pushing/pulling a file
                        if [[ `expr $local_modify_utc_date_time_seconds - $remote_modify_utc_date_time_seconds` -gt 1 ]]; then
                                object=$(.drive-prepend-object-type-size "$object")
                                unsynced_objects_fresher_locally[$unsynced_objects_fresher_locally_index]="$object"
                                ((unsynced_objects_fresher_locally_index++))
                        elif [[ `expr $remote_modify_utc_date_time_seconds - $local_modify_utc_date_time_seconds` -gt 1 ]]; then
                                object=$(.drive-prepend-object-type-size "$object")
                                unsynced_objects_fresher_remotely[$unsynced_objects_fresher_remotely_index]="$object"
                                ((unsynced_objects_fresher_remotely_index++))
                        # else both date_time are identical: we move on to the next $object
                        fi
                elif [[ -d "$object" ]]; then
                        # We cannot compare locally modified date & time with remote ModTime of $object
                        # Due to issue https://github.com/odeke-em/drive/issues/842#issuecomment-276114937
                        continue
                else
                        # The object is not present locally, continue
                        # It must have been deleted or moved in the meantime 
                        continue
                fi
        done

        if [[ ${#unsynced_objects_fresher_locally[@]} -eq 0 ]]; then
                # No objects are fresher locally        
                zenity --warning --title "Listing 0 Google Drive objects fresher locally in ${noamp_local_folder}" --text="None is fresher locally" --width=1400
        else
                printf '%s\n' "${unsynced_objects_fresher_locally[@]}" | zenity --text-info --title "Listing ${#unsynced_objects_fresher_locally[@]} Google Drive objects fresher locally in ${noamp_local_folder}" --width 1800 --height 800
                if [[ ${PIPESTATUS[1]} -ne 0 ]]; then
                        # Cancel has been selected
                        zenity --warning --title "Syncing selected local/remote objects" --text="Operation cancelled" --width=800
                        echo '§'
                        return
                fi
        fi

        if [[ ${#unsynced_objects_fresher_remotely[@]} -eq 0 ]]; then
                # No objects are fresher remotely        
                zenity --warning --title "Listing 0 Google Drive objects fresher remotely in ${noamp_local_folder}" --text="None is fresher remotely" --width=1400
        else
                printf '%s\n' "${unsynced_objects_fresher_remotely[@]}" | zenity --text-info --title "Listing ${#unsynced_objects_fresher_remotely[@]} Google Drive objects fresher remotely in ${noamp_local_folder}" --width 1800 --height 800
                if [[ ${PIPESTATUS[1]} -ne 0 ]]; then
                        # Cancel has been selected
                        zenity --warning --title "Syncing selected local/remote objects" --text="Operation cancelled" --width=800
                        echo '§'
                        return
                fi
        fi

        if [[ (${#unsynced_objects_fresher_locally[@]} -ne 0) || (${#unsynced_objects_fresher_remotely[@]} -ne 0) ]]; then
                # Concatenating for return:
                #       - unsynced_objects_fresher_locally
                #       - unsynced_objects_fresher_remotely
                unsynced_objects_fresher=("${unsynced_objects_fresher_locally[@]}" "${unsynced_objects_fresher_remotely[@]}")

                # Adding their respective size at the end of the resulting array to be able to fetch each one at the return of this function
                unsynced_objects_fresher[`expr ${#unsynced_objects_fresher_locally[@]} + ${#unsynced_objects_fresher_remotely[@]}`]=${#unsynced_objects_fresher_locally[@]}
                unsynced_objects_fresher[`expr ${#unsynced_objects_fresher_locally[@]} + ${#unsynced_objects_fresher_remotely[@]} + 1`]=${#unsynced_objects_fresher_remotely[@]}

                # Child shells cannot modify anything in parent
                printf '%s\n' "${unsynced_objects_fresher[@]}"
        fi
}

#------------------------------------drive-sync----------------------------------------------------
# Checking for no parameter
if [[ $# -eq 0 ]]; then
        local_folder="$(pwd)"

        # Removing all occurrences of '&' in $object as a workaround to a markup ampersand issue with zenity
        noamp_local_folder="$(echo "${local_folder}" | rm_ampersand)"

        # Finding local root Google Drive folder
        gd_root_folder="$(.drive-find-gd)"
        return_code=$?

        # Removing all occurrences of '&' in $gd_root_folder as a workaround to a markup ampersand issue with zenity
        noamp_gd_root_folder="$(echo "${gd_root_folder}" | rm_ampersand)"

        case $return_code in
                0)
                        # Everything is fine - we continue
                        ;;
                7)
                        zenity --warning --title "Drive context found in $noamp_gd_root_folder" --text="We have moved to $noamp_gd_root_folder\n\nIf you prefer to select another Google Drive folder:\n\t--> 'Change working directory' in drive-menu" --width 1400

                        cd "$gd_root_folder"

                        local_folder="$(pwd)"

                        # Removing all occurrences of '&' in $object as a workaround to a markup ampersand issue with zenity
                        noamp_local_folder="$(echo "${local_folder}" | rm_ampersand)"
                        ;;
                8)
                        zenity --error --title "No drive context found below and above $noamp_local_folder" --text="- either drive has not been initialized properly (at least one hop away from '/') with:\n\t--> '# drive init google_drive_folder' within a terminal\n- or we are not located below your google_drive_folder top level branch:\n\t--> 'Change working directory' in drive-menu" --width 1400
                        exit $return_code
                        ;;
                *)
                        # Something is fatally wrong
                        zenity --error --title "Fatal error in drive-menu" --text="\tUnknown return code from .drive-find-gd: $return_code\n\nPlease report that issue to: https://gitlab.com/jean-christophe-manciot/Drive/issues" --width 1200
                        exit 99
                        ;;
        esac

        local_folder_path_from_gd_root="${local_folder#$gd_root_folder}"

        printf "Help is available through 'Cancel/OK/Help/Sync...'\n\nThe following searches of unsynced objects are automatically launched each time a fully/semi-automated or manual sync is called:\n\t- objects missing remotely\n\t- objects missing locally\n\t- objects fresher remotely\n\t- objects fresher locally\nThe total delay depends on many factors, please be patient.\nYou may choose 'Cancel/OK/Help/Sync.../Notes' to check all types of potential delays and different ways to improve them\n\nWe assume that the following optional configuration files are correctly set up:\n\t- ${gd_root_folder}/.driverc\n\t- ${gd_root_folder}/.driveignore\n\t- ${local_folder}/.driveselect\nMore details are available in 'Cancel/OK/Select...' for their respective expected format." | zenity --text-info --title "Do you confirm syncing recursively all unsynced objects between your local and remote Google Drive?" --width=1450 --height=500

        if [[ ! (${PIPESTATUS[1]} -eq 0) ]]; then
                # Cancel has been selected
                zenity --warning --title "Do you confirm syncing recursively all unsynced objects between your local and remote Google Drive?" --text="Operation cancelled" --width=1250
                
                exit 3
        fi

        while :
        do
                sync=$(zenity --list  \
                              --radiolist \
                              --height=250 \
                              --width=800 \
                              --title "Selecting type of Google Drive Sync" \
                              --column "Pick" \
                              --column "Google Drive Sync" FALSE Fully-Automated TRUE Semi-Automated FALSE Manual FALSE Exit)
                case $sync in
                        Fully-Automated)
                                zenity --warning --title "Fully-Automated Syncing in ${noamp_local_folder}" --text="It will be implemented in the next release" --width=1400
                                ;;
                        Semi-Automated)
                                master=$(zenity --list  \
                                                --radiolist \
                                                --height=250 \
                                                --width=800 \
                                                --title "Selecting type of Google Drive Master" \
                                                --column "Pick" \
                                                --column "Google Drive Master" FALSE None TRUE Local FALSE Remote FALSE Exit)

                                case $master in
                                        None)
                                                unset objects_present_remotely
                                                objects_present_remotely=()
                                                unset unsynced_objects_fresher
                                                unsynced_objects_fresher=()
                                                unset unsynced_objects_fresher_locally
                                                unsynced_objects_fresher_locally=()
                                                unset unsynced_objects_fresher_remotely
                                                unsynced_objects_fresher_remotely=()
                                                unset objects_to_push
                                                objects_to_push=()

                                                readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t unsynced_objects_fresher < <(list-unsynced-objects-fresher)
                                                if [[ "${unsynced_objects_fresher[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                if [[ ${#unsynced_objects_fresher[@]} -ne 0 ]]; then
                                                        # Separating the returned array into 2 original arrays
                                                        unsynced_objects_fresher_locally=("${unsynced_objects_fresher[@]:0:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 2`]}}")
                                                        unsynced_objects_fresher_remotely=("${unsynced_objects_fresher[@]:${#unsynced_objects_fresher_locally[@]}:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 1`]}}")
                                                fi

                                                # Concatenating for push:
                                                #       - objects fresher locally
                                                objects_to_push=("${unsynced_objects_fresher_locally[@]}")

                                                if [[ ${#objects_to_push[@]} -eq 0 ]]; then
                                                        # No objects need to be pushed       
                                                        zenity --warning --title "Pushing 0 Google Drive objects fresher locally in ${noamp_local_folder}" --text="None need to be pushed" --width=1400
                                                else
                                                        # Formatting the file .driveselect for the command 'push'
                                                        .drive-write-driveselect push "${objects_to_push[@]}" 

                                                        # Pushing the objects
                                                        .drive-push-unsynced "Google Drive objects fresher locally in ${noamp_local_folder}"
                                                fi

                                                unset objects_to_pull
                                                objects_to_pull=()

                                                # Concatenating for pull:
                                                #       - objects fresher remotely
                                                objects_to_pull=("${unsynced_objects_fresher_remotely[@]}")

                                                if [[ ${#objects_to_pull[@]} -eq 0 ]]; then
                                                        # No objects need to be pulled       
                                                        zenity --warning --title "Pulling 0 Google Drive objects fresher remotely in ${noamp_local_folder}" --text="None need to be pulled" --width=1400
                                                else
                                                        # Formatting the file .driveselect for the command 'pull'
                                                        .drive-write-driveselect pull "${objects_to_pull[@]}" 

                                                        # Pulling the objects
                                                        .drive-pull-unsynced "Google Drive objects fresher remotely in ${noamp_local_folder}"
                                                fi
                                                ;;
                                        Local)
                                                unset objects_present_locally
                                                objects_present_locally=()
                                                unset objects_present_remotely
                                                objects_present_remotely=()
                                                unset unsynced_objects_absent_locally
                                                unsynced_objects_absent_locally=()
                                                unset unsynced_objects_absent_remotely
                                                unsynced_objects_absent_remotely=()
                                                unset unsynced_objects_fresher
                                                unsynced_objects_fresher=()
                                                unset unsynced_objects_fresher_locally
                                                unsynced_objects_fresher_locally=()
                                                unset objects_to_push
                                                objects_to_push=()

                                                readarray -t objects_present_locally < <(list-objects-present-locally)
                                                if [[ "${objects_present_locally[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t unsynced_objects_absent_locally < <(list-objects-absent-locally)
                                                if [[ "${unsynced_objects_absent_locally[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t unsynced_objects_absent_remotely < <(list-objects-absent-remotely)
                                                if [[ "${unsynced_objects_absent_remotely[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t unsynced_objects_fresher < <(list-unsynced-objects-fresher)
                                                if [[ "${unsynced_objects_fresher[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                if [[ ${#unsynced_objects_fresher[@]} -ne 0 ]]; then
                                                        unsynced_objects_fresher_locally=("${unsynced_objects_fresher[@]:0:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 2`]}}")
                                                fi

                                                # Concatenating for push:
                                                #       - objects missing remotely
                                                #       - objects fresher locally
                                                objects_to_push=("${unsynced_objects_absent_remotely[@]}" "${unsynced_objects_fresher_locally[@]}")

                                                if [[ ${#objects_to_push[@]} -eq 0 ]]; then
                                                        # No objects need to be pushed       
                                                        zenity --warning --title "Pushing 0 Google Drive objects missing remotely & fresher locally in ${noamp_local_folder}" --text="None need to be pushed" --width=1400
                                                else
                                                        # Formatting the file .driveselect for the command 'push'
                                                        .drive-write-driveselect push "${objects_to_push[@]}" 

                                                        # Pushing the objects
                                                        .drive-push-unsynced "Google Drive objects missing remotely & fresher locally in ${noamp_local_folder}"
                                                fi

                                                # Trashing remotely objects missing locally
                                                if [[ ${#unsynced_objects_absent_locally[@]} -eq 0 ]]; then
                                                        # No objects need to be trashed remotely       
                                                        zenity --warning --title "Trashing remotely 0 Google Drive objects missing locally in ${noamp_local_folder}" --text="None need to be trashed remotely" --width=1400
                                                else
                                                        # Formatting the file .driveselect for the command 'trash'
                                                        .drive-write-driveselect trash "${unsynced_objects_absent_locally[@]}" 

                                                        # Trashing the objects
                                                        .drive-trash-unsynced-remote "remote Google Drive objects missing locally (objects included in listed folders are not listed) in ${noamp_local_folder}"
                                                fi
                                                ;;
                                        Remote)
                                                unset objects_present_locally
                                                objects_present_locally=()
                                                unset objects_present_remotely
                                                objects_present_remotely=()
                                                unset unsynced_objects_absent_locally
                                                unsynced_objects_absent_locally=()
                                                unset unsynced_objects_absent_remotely
                                                unsynced_objects_absent_remotely=()
                                                unset unsynced_objects_fresher
                                                unsynced_objects_fresher=()
                                                unset unsynced_objects_fresher_locally
                                                unsynced_objects_fresher_locally=()
                                                unset unsynced_objects_fresher_remotely
                                                unsynced_objects_fresher_remotely=()
                                                unset objects_to_pull
                                                objects_to_pull=()

                                                readarray -t objects_present_locally < <(list-objects-present-locally)
                                                if [[ "${objects_present_locally[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t unsynced_objects_absent_locally < <(list-objects-absent-locally)
                                                if [[ "${unsynced_objects_absent_locally[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t unsynced_objects_absent_remotely < <(list-objects-absent-remotely)
                                                if [[ "${unsynced_objects_absent_remotely[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                readarray -t unsynced_objects_fresher < <(list-unsynced-objects-fresher)
                                                if [[ "${unsynced_objects_fresher[0]}" == '§' ]]; then
                                                        continue
                                                fi
                                                if [[ ${#unsynced_objects_fresher[@]} -ne 0 ]]; then
                                                        # Separating the returned array into 2 original arrays
                                                        unsynced_objects_fresher_locally=("${unsynced_objects_fresher[@]:0:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 2`]}}")
                                                        unsynced_objects_fresher_remotely=("${unsynced_objects_fresher[@]:${#unsynced_objects_fresher_locally[@]}:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 1`]}}")
                                                fi

                                                # Concatenating for pull:
                                                #       - objects missing locally
                                                #       - objects fresher remotely
                                                objects_to_pull=("${unsynced_objects_absent_locally[@]}" "${unsynced_objects_fresher_remotely[@]}")

                                                if [[ ${#objects_to_pull[@]} -eq 0 ]]; then
                                                        # No objects need to be pulled       
                                                        zenity --warning --title "Pulling 0 Google Drive objects missing locally & fresher remotely in ${noamp_local_folder}" --text="None need to be pulled" --width=1400
                                                else
                                                        # Formatting the file .driveselect for the command 'pull'
                                                        .drive-write-driveselect pull "${objects_to_pull[@]}" 

                                                        # Pulling the objects
                                                        .drive-pull-unsynced "Google Drive objects missing locally & fresher remotely in ${noamp_local_folder}"
                                                fi

                                                # Trashing locally objects missing remotely
                                                if [[ ${#unsynced_objects_absent_remotely[@]} -eq 0 ]]; then
                                                        # No objects need to be trashed locally       
                                                        zenity --warning --title "Trashing locally 0 Google Drive objects missing remotely in ${noamp_local_folder}" --text="None need to be trashed locally" --width=1400
                                                else
                                                        # Formatting the file .driveselect for the command 'trash'
                                                        .drive-write-driveselect trash "${unsynced_objects_absent_remotely[@]}" 

                                                        # Trashing the objects
                                                        .drive-trash-unsynced-local "local Google Drive objects missing remotely (objects included in listed folders are not listed) in ${noamp_local_folder}"
                                                fi
                                                ;;
                                        *)
                                                ;;
                                esac
                                ;;
                        Manual)
                                operations=$(zenity --list  \
                                                    --checklist \
                                                    --separator=":" \
                                                    --height=450 \
                                                    --width=1150 \
                                                    --title "Selecting type(s) of Google Drive Sync operation(s)" \
                                                    --column "Pick" \
                                                    --column "One or any **correct** combination: in case of conflict, the first choice will be tried first" FALSE "Push remotely all objects present only locally" FALSE "Push remotely all objects older locally to revert all remote fresher objects" FALSE "Push remotely all objects fresher locally to update older remote objects" FALSE "Push remotely all selected local objects to create/update remote objects" FALSE "Pull locally all objects present only remotely" FALSE "Pull locally all objects fresher remotely to update older local objects" FALSE "Pull locally all objects older remotely to revert all local fresher objects" FALSE "Pull locally all selected remote objects to create/update local objects" FALSE "Trash locally all objects present only locally" FALSE "Trash remotely all objects present only remotely" FALSE Exit)
                                
                                while :
                                do
                                        # Processing each command one by one in order
                                        # $operations is formatted with "command1:command2:command3:..." from previous choices
                                        if [[ "$operations" =~ : ]]; then
                                                # There are at least 2 commands
                                                command="$(echo $operations | cut -d ':' -f 1)"
                                        else
                                                command="$operations"
                                        fi

                                        case $command in
                                                "Push remotely all objects present only locally")
                                                        unset objects_present_locally
                                                        objects_present_locally=()
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()
                                                        unset unsynced_objects_absent_remotely
                                                        unsynced_objects_absent_remotely=()

                                                        readarray -t objects_present_locally < <(list-objects-present-locally)
                                                        if [[ "${objects_present_locally[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        readarray -t unsynced_objects_absent_remotely < <(list-objects-absent-remotely)
                                                        if [[ "${unsynced_objects_absent_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        if [[ ${#unsynced_objects_absent_remotely[@]} -eq 0 ]]; then
                                                                # No objects need to be pushed       
                                                                zenity --warning --title "Pushing remotely 0 Google Drive objects present only locally in ${noamp_local_folder}" --text="None need to be pushed" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'push'
                                                                .drive-write-driveselect push "${unsynced_objects_absent_remotely[@]}" 

                                                                # Pushing the objects
                                                                .drive-push-unsynced "Google Drive objects present only locally in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Push remotely all objects older locally to revert all remote fresher objects")
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()
                                                        unset unsynced_objects_fresher
                                                        unsynced_objects_fresher=()
                                                        unset unsynced_objects_fresher_locally
                                                        unsynced_objects_fresher_locally=()
                                                        unset unsynced_objects_fresher_remotely
                                                        unsynced_objects_fresher_remotely=()

                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        readarray -t unsynced_objects_fresher < <(list-unsynced-objects-fresher)
                                                        if [[ "${unsynced_objects_fresher[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        if [[ ${#unsynced_objects_fresher[@]} -ne 0 ]]; then
                                                                # Separating the returned array into 2 original arrays
                                                                unsynced_objects_fresher_locally=("${unsynced_objects_fresher[@]:0:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 2`]}}")
                                                                unsynced_objects_fresher_remotely=("${unsynced_objects_fresher[@]:${#unsynced_objects_fresher_locally[@]}:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 1`]}}")
                                                        fi

                                                        if [[ ${#unsynced_objects_fresher_remotely[@]} -eq 0 ]]; then
                                                                # No objects need to be pushed       
                                                                zenity --warning --title "Pushing remotely 0 Google Drive objects older locally in ${noamp_local_folder}" --text="None need to be pushed" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'push'
                                                                .drive-write-driveselect push "${unsynced_objects_fresher_remotely[@]}" 

                                                                # Pushing the objects
                                                                .drive-push-unsynced "Google Drive objects older locally to revert all remote updated objects in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Push remotely all objects fresher locally to update older remote objects")
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()
                                                        unset unsynced_objects_fresher
                                                        unsynced_objects_fresher=()
                                                        unset unsynced_objects_fresher_locally
                                                        unsynced_objects_fresher_locally=()
                                                        unset unsynced_objects_fresher_remotely
                                                        unsynced_objects_fresher_remotely=()

                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        readarray -t unsynced_objects_fresher < <(list-unsynced-objects-fresher)
                                                        if [[ "${unsynced_objects_fresher[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        if [[ ${#unsynced_objects_fresher[@]} -ne 0 ]]; then
                                                                # Separating the returned array into 2 original arrays
                                                                unsynced_objects_fresher_locally=("${unsynced_objects_fresher[@]:0:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 2`]}}")
                                                                unsynced_objects_fresher_remotely=("${unsynced_objects_fresher[@]:${#unsynced_objects_fresher_locally[@]}:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 1`]}}")
                                                        fi

                                                        if [[ ${#unsynced_objects_fresher_locally[@]} -eq 0 ]]; then
                                                                # No objects need to be pushed       
                                                                zenity --warning --title "Pushing remotely 0 Google Drive objects fresher locally in ${noamp_local_folder}" --text="None need to be pushed" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'push'
                                                                .drive-write-driveselect push "${unsynced_objects_fresher_locally[@]}" 

                                                                # Pushing the objects
                                                                .drive-push-unsynced "Google Drive objects fresher locally to update remote objects in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Push remotely all selected local objects to create/update remote objects")
                                                        unset objects_present_locally
                                                        objects_present_locally=()

                                                        readarray -t objects_present_locally < <(list-objects-present-locally)
                                                        if [[ "${objects_present_locally[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        if [[ ${#objects_present_locally[@]} -eq 0 ]]; then
                                                                # No objects need to be pushed       
                                                                zenity --warning --title "Pushing remotely 0 Google Drive selected local objects in ${noamp_local_folder}" --text="None need to be pushed" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'push'
                                                                .drive-write-driveselect push "${objects_present_locally[@]}" 

                                                                # Pushing the objects
                                                                .drive-push-unsynced "Google Drive selected local objects to create/update remote objects in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Pull locally all objects present only remotely")
                                                        unset objects_present_locally
                                                        objects_present_locally=()
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()
                                                        unset unsynced_objects_absent_locally
                                                        unsynced_objects_absent_locally=()

                                                        readarray -t objects_present_locally < <(list-objects-present-locally)
                                                        if [[ "${objects_present_locally[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        readarray -t unsynced_objects_absent_locally < <(list-objects-absent-locally)
                                                        if [[ "${unsynced_objects_absent_locally[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        if [[ ${#unsynced_objects_absent_locally[@]} -eq 0 ]]; then
                                                                # No objects need to be pulled       
                                                                zenity --warning --title "Pulling locally 0 Google Drive objects present only remotely in ${noamp_local_folder}" --text="None need to be pulled" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'pull'
                                                                .drive-write-driveselect pull "${unsynced_objects_absent_locally[@]}" 

                                                                # Pulling the objects
                                                                .drive-pull-unsynced "Google Drive objects present only remotely in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Pull locally all objects fresher remotely to update older local objects")
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()
                                                        unset unsynced_objects_fresher
                                                        unsynced_objects_fresher=()
                                                        unset unsynced_objects_fresher_locally
                                                        unsynced_objects_fresher_locally=()
                                                        unset unsynced_objects_fresher_remotely
                                                        unsynced_objects_fresher_remotely=()

                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        readarray -t unsynced_objects_fresher < <(list-unsynced-objects-fresher)
                                                        if [[ "${unsynced_objects_fresher[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        if [[ ${#unsynced_objects_fresher[@]} -ne 0 ]]; then
                                                                # Separating the returned array into 2 original arrays
                                                                unsynced_objects_fresher_locally=("${unsynced_objects_fresher[@]:0:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 2`]}}")
                                                                unsynced_objects_fresher_remotely=("${unsynced_objects_fresher[@]:${#unsynced_objects_fresher_locally[@]}:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 1`]}}")
                                                        fi

                                                        if [[ ${#unsynced_objects_fresher_remotely[@]} -eq 0 ]]; then
                                                                # No objects need to be pulled       
                                                                zenity --warning --title "Pulling locally 0 Google Drive objects fresher remotely in ${noamp_local_folder}" --text="None need to be pulled" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'pull'
                                                                .drive-write-driveselect pull "${unsynced_objects_fresher_remotely[@]}" 

                                                                # Pulling the objects
                                                                .drive-pull-unsynced "Google Drive objects fresher remotely to update local objects in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Pull locally all objects older remotely to revert all local fresher objects")
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()
                                                        unset unsynced_objects_fresher
                                                        unsynced_objects_fresher=()
                                                        unset unsynced_objects_fresher_locally
                                                        unsynced_objects_fresher_locally=()

                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        readarray -t unsynced_objects_fresher < <(list-unsynced-objects-fresher)
                                                        if [[ "${unsynced_objects_fresher[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        if [[ ${#unsynced_objects_fresher[@]} -ne 0 ]]; then
                                                                # Extracting ${unsynced_objects_fresher_locally[@]} from returned array
                                                                unsynced_objects_fresher_locally=("${unsynced_objects_fresher[@]:0:${unsynced_objects_fresher[`expr ${#unsynced_objects_fresher[@]} - 2`]}}")
                                                        fi

                                                        if [[ ${#unsynced_objects_fresher_locally[@]} -eq 0 ]]; then
                                                                # No objects need to be pulled       
                                                                zenity --warning --title "Pulling locally 0 Google Drive objects older remotely in ${noamp_local_folder}" --text="None need to be pulled" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'pull'
                                                                .drive-write-driveselect pull "${unsynced_objects_fresher_locally[@]}" 

                                                                # Pulling the objects
                                                                .drive-pull-unsynced "Google Drive objects older remotely to revert all local updated objects in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Pull locally all selected remote objects to create/update local objects")
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()

                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        if [[ ${#objects_present_remotely[@]} -eq 0 ]]; then
                                                                # No objects need to be pulled       
                                                                zenity --warning --title "Pulling locally 0 Google Drive selected remote objects in ${noamp_local_folder}" --text="None need to be pulled" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'pull'
                                                                .drive-write-driveselect pull "${objects_present_remotely[@]}" 

                                                                # Pulling the objects
                                                                .drive-pull-unsynced "Google Drive selected remote objects to create/update local objects in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Trash locally all objects present only locally")
                                                        unset objects_present_locally
                                                        objects_present_locally=()
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()
                                                        unset unsynced_objects_absent_remotely
                                                        unsynced_objects_absent_remotely=()

                                                        readarray -t objects_present_locally < <(list-objects-present-locally)
                                                        if [[ "${objects_present_locally[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        readarray -t unsynced_objects_absent_remotely < <(list-objects-absent-remotely)
                                                        if [[ "${unsynced_objects_absent_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        if [[ ${#unsynced_objects_absent_remotely[@]} -eq 0 ]]; then
                                                                # No objects need to be trashed locally       
                                                                zenity --warning --title "Trashing locally 0 Google Drive objects present only locally in ${noamp_local_folder}" --text="None need to be trashed locally" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'trash'
                                                                .drive-write-driveselect trash "${unsynced_objects_absent_remotely[@]}" 

                                                                # Trashing the objects
                                                                .drive-trash-unsynced-local "Google Drive objects present only locally (objects included in listed folders are not listed) in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                "Trash remotely all objects present only remotely")
                                                        unset objects_present_locally
                                                        objects_present_locally=()
                                                        unset objects_present_remotely
                                                        objects_present_remotely=()
                                                        unset unsynced_objects_absent_locally
                                                        unsynced_objects_absent_locally=()

                                                        readarray -t objects_present_locally < <(list-objects-present-locally)
                                                        if [[ "${objects_present_locally[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        readarray -t objects_present_remotely < <(list-objects-present-remotely)
                                                        if [[ "${objects_present_remotely[0]}" == '§' ]]; then
                                                                continue
                                                        fi
                                                        readarray -t unsynced_objects_absent_locally < <(list-objects-absent-locally)
                                                        if [[ "${unsynced_objects_absent_locally[0]}" == '§' ]]; then
                                                                continue
                                                        fi

                                                        if [[ ${#unsynced_objects_absent_locally[@]} -eq 0 ]]; then
                                                                # No objects need to be trashed remotely       
                                                                zenity --warning --title "Trashing remotely 0 Google Drive objects present only remotely in ${noamp_local_folder}" --text="None need to be trashed remotely" --width=1400
                                                        else
                                                                # Formatting the file .driveselect for the command 'trash'
                                                                .drive-write-driveselect trash "${unsynced_objects_absent_locally[@]}" 

                                                                # Trashing the objects
                                                                .drive-trash-unsynced-remote "Google Drive objects present only remotely (objects included in listed folders are not listed) in ${noamp_local_folder}"
                                                        fi
                                                        ;;
                                                *)
                                                        break
                                                        ;;
                                        esac

                                        # Removing $command from $operations
                                        if [[ "$operations" =~ : ]]; then
                                                # There are at least 2 commands
                                                operations="${operations#${command}:}"
                                        else
                                                operations="${operations#${command}}"
                                        fi
                                done
                                ;;
                        *)
                                break
                                ;;
                esac
        done

        exit 0
else
        # Any parameter
        end_of_help_message_line_number=$(awk '/^if \[\[ \$LOG_/{ print NR; exit }' $(which drive-sync))
        ((end_of_help_message_line_number--))
        awk -v var=$end_of_help_message_line_number 'NR >= 20 && NR <= var' $(which drive-sync) | zenity --text-info --title "drive-sync help" --width 1150 --height 1000
        exit 1
fi