This repository has been archived by the owner on Nov 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·680 lines (620 loc) · 21.8 KB
/
install.sh
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
#!/usr/bin/env bash
# CONFIGCLOUD INSTALLER
#
# This script is a component of ConfigCloud
# https://github.com/robertpeteuil/configcloud
#
# This installer links or copies included files/dirs into the current user's home directory.
# It should be executed directly from the repo directory: ./install.sh -h (displays help)
#
# Robert Peteuil (c) 2018
#
scriptname="install.sh"
scriptbuildnum="2.0.3"
scriptbuilddate="2018-01-28"
################################################################
### VARIABLE INITS
os=$(uname | tr '[:upper:]' '[:lower:]')
settingsfilename="install_set"
logfilename="LOG-install.txt"
# MODE FLAGS
customconfig=false
forcemode=false
testmode=false
detailsmode=false
verbosemode=false
quietmode=false
test_overwrite_flag=false
overwrite_flag=false
copy_recursion=false
# STRING FLAGS
temp_src=""
remove_item_type=""
report_indent=" "
# COUNTERS
test_copies=0
test_links=0
test_removing=0
test_mkdir=0
test_errors=0
new_copies=0
new_links=0
new_removals=0
new_dirs=0
error_copies=0
error_links=0
error_removals=0
error_mkdirs=0
warning_skipped=0
warning_removals=0
# REPORT STRINGS
test_copies_names=""
test_links_names=""
test_removing_names=""
test_mkdir_names=""
test_errors_names=""
new_copies_names=""
new_links_names=""
new_removals_names=""
new_dirs_names=""
error_copies_names=""
error_links_names=""
error_removals_names=""
error_mkdirs_names=""
warning_skipped_names=""
warning_removals_names=""
############################################################
### PRE-EXECUTION
# ENABLE COLOR IF SUPPORTED AND SET THEME COLORS
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test "$ncolors" -ge 8; then
# SET TEMP COLOR VARS
bold="$(tput bold)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput sgr0)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
# SET COLOR THEME USED IN ECHO STATEMENTS
CLRnormal=${bold}${white}
CLRheading=${bold}${green}
CLRheading2=${bold}${blue}
CLRtitle=${bold}${cyan}
CLRtitle2=${bold}${magenta}
CLRsuccess=${bold}${green}
CLRwarning=${bold}${yellow}
CLRerror=${bold}${red}
fi
fi
################################################################
### FUNCTIONS
processExit () {
local var="$*"
if [[ -n "$EXITMESSAGE" ]]; then
echo -e "$EXITMESSAGE" >&2
fi
if [[ -n "$var" ]]; then
echo -e "$var" >&2
[[ "$EXITSTATUS" == 0 ]] && EXITSTATUS=1
fi
exit $EXITSTATUS
}
processAbort () {
local var=$*
[[ -n $var ]] && EXITMESSAGE="${CLRerror}ABORT${CLRnormal} - ${CLRtitle}${var}${CLRnormal}"
EXITSTATUS=2
processExit ""
}
remove_formatting () {
local var="$*"
if [[ -n "$var" ]]; then
var=${var//${CLRnormal}/}
var=${var//${CLRheading}/}
var=${var//${CLRheading2}/}
var=${var//${CLRtitle}/}
var=${var//${CLRtitle2}/}
var=${var//${CLRsuccess}/}
var=${var//${CLRwarning}/}
var=${var//${CLRerror}/}
echo "$var"
fi
}
display_ver() {
printed_title="${CLRheading}${scriptname}${CLRnormal} ver ${CLRtitle}${scriptbuildnum} ${CLRnormal}- ${CLRtitle}${scriptbuilddate}${CLRnormal}"
echo -e "$printed_title"
}
display_help_text () {
display_ver
echo
echo -e "Copies/links files and directories from the current dir to the user's home dir"
echo -e
echo -e "USAGE: install.sh [OPTIONS] [-c CONFIG-FILE] [SOURCE-DIR] [DEST-DIR]"
echo -e " SOURCE-DIR defaults to the current directory"
echo -e " DEST-DIR defaults to the current user's home directory"
echo -e
echo -e "OPTIONS (default to false):"
echo -e " -f (--force) : force mode - overwrite existing items"
echo -e " -d (--details) : details mode - display details results in categories"
echo -e " -q (--quiet) : quiet mode - don't display any output"
echo -e " -t (--test) : test mode - display changes but don't make any"
echo -e " -v (--verbose) : verbose mode - display exact commands to be performed"
echo -e
echo -e " -h (--help) : display help info and exit"
echo -e " -V (--version) : display version info and exit"
echo -e
echo -e " -c (--config) : specify a configuration file"
echo -e " (default configuration file is 'conf-settings')"
echo -e " Example config file contents:"
echo -e " # Settings (can use globs)"
echo -e " # ignore these files (modifies include)"
echo -e " ignore='Icon* *.md *.sh *.txt scripts'"
echo -e " # create dir (not contents), then sym-link children (contents)"
echo -e " link_children='config'"
echo -e " # copy these files"
echo -e " copitem_message=''"
echo -e " # sym-link these files"
echo -e " link='*'"
echo -e
echo -e " SOURCE-DIR : directory containing dotfiles to be copied and/or linked"
echo -e " (default is current directory)"
echo -e " files should NOT have leading '.'"
echo -e " example: '.bashrc' should be named 'bashrc' in SOURCE-DIR"
echo -e
echo -e " DEST-DIR : target directory where copies and links will be placed"
echo -e " (default is '~')"
}
print_output() {
if [ $verbosemode = true ]; then
echo "$@"
fi
return 0
}
list_contains() {
for word in $1; do
[ "$word" = "$2" ] && return 0
done
return 1
}
remove_dupes() {
unset new_list
for i in $1; do
list_contains "$2" "$i" || new_list="$new_list $i"
done
echo "$new_list"
}
remove_item() {
if [ "$testmode" = true ]; then
print_output "rm $1"
test_removing=$((test_removing=test_removing+1))
test_removing_names="$test_removing_names $1"
test_overwrite_flag=true
return 0
fi
if [ "$forcemode" = true ]; then
if [ -d "$1" ]; then
remove_command="rmdir $1"
remove_item_type="dir"
else
remove_command="rm $1"
remove_item_type="non-dir"
fi
if $($remove_command 2> /dev/null); then
print_output "REMOVAL SUCCESS: $1"
new_removals=$((new_removals=new_removals+1))
new_removals_names="$new_removals_names $1"
overwrite_flag=true
return 0
else
if [ "$remove_item_type" = "dir" ]; then
print_output "REMOVAL WARNING: $1"
warning_removals=$((warning_removals=warning_removals+1))
warning_removals_names="$warning_removals_names $1"
remove_item_type=""
return 1
fi
print_output "REMOVAL FAILED: $1"
error_removals=$((error_removals=error_removals+1))
error_removals_names="$error_removals_names $1"
return 1
fi
else # FORCE MODE not enabled
print_output "NOT OVERWRITTEN: $1"
warning_skipped_names="$warning_skipped_names $1"
warning_skipped=$((warning_skipped=warning_skipped+1))
return 1
fi
}
link_item() {
if [ "$testmode" = true ]; then
if [ "$prefail" = true ]; then
print_output "ERROR LINKING: $2"
test_errors=$((test_errors=test_errors+1))
test_errors_names="$test_errors_names Error_Linking:$2"
return 0
fi
print_output "ln -s $1 $2"
if [ "$test_overwrite_flag" = false ]; then
test_links=$((test_links=test_links+1))
test_links_names="$test_links_names $2"
fi
test_overwrite_flag=false
return 0
fi
if $(ln -s "$1" "$2" 2> /dev/null); then
print_output "LINK SUCCESS: $2"
if [ "$overwrite_flag" = false ]; then
new_links=$((new_links=new_links+1))
new_links_names="$new_links_names $2"
fi
overwrite_flag=false
return 0
else
print_output "ERROR LINKING: $2"
error_links=$((error_links=error_links+1))
error_links_names="$error_links_names $2"
return 1
fi
}
copy_item() {
if [ "$testmode" = true ]; then
if [ "$prefail" = true ]; then
print_output "ERROR COPYING: $2"
test_errors=$((test_errors=test_errors+1))
test_errors_names="$test_errors_names Error_Copying:$2"
return 0
fi
print_output "cp $1 $2"
if [ "$test_overwrite_flag" = false ]; then
test_copies=$((test_copies=test_copies+1))
test_copies_names="$test_copies_names $2"
fi
test_overwrite_flag=false
return 0
fi
if [ "$copy_recursion" = true ]; then
copy_command="cp -R $1 $2"
else
copy_command="cp $1 $2"
fi
if $($copy_command 2> /dev/null); then
print_output "COPY SUCCESS: $2"
if [ "$overwrite_flag" = false ]; then
new_copies=$((new_copies=new_copies+1))
new_copies_names="$new_copies_names $2"
fi
overwrite_flag=false
return 0
else
print_output "ERROR COPYING: $2"
error_copies=$((error_copies=error_copies+1))
error_copies_names="$error_copies_names $2"
return 1
fi
}
make_dir() {
if [ "$testmode" = true ]; then
print_output "mkdir -p $1"
if [ "$test_overwrite_flag" = false ]; then
test_mkdir=$((test_mkdir=test_mkdir+1))
test_mkdir_names="$test_mkdir_names $1"
fi
test_overwrite_flag=false
return 0
fi
if $(mkdir -p "$1" 2> /dev/null); then
print_output "MKDIR SUCCESS: $1"
if [ "$overwrite_flag" = false ]; then
new_dirs=$((new_dirs=new_dirs+1))
new_dirs_names="$new_dirs_names $1"
fi
overwrite_flag=false
return 0
else
print_output "ERROR MKDIR: $1"
error_mkdirs=$((error_mkdirs=error_mkdirs+1))
error_mkdirs_names="$error_mkdirs_names $1"
return 1
fi
}
make_links() {
for s in $1; do
target="$dest_dir/.$s"
src="$source_dir/$s"
if [ -e "$target" ]; then
remove_item "$target" && link_item "$src" "$target"
else
link_item "$src" "$target"
fi
done
}
make_copies () {
if [ -e "$dest_dir/.$1" ]; then
remove_item "$dest_dir/.$1" && copy_item "${temp_src}${1}" "$dest_dir/.$1"
else
copy_item "${temp_src}${1}" "$dest_dir/.$1"
fi
}
report_grammar () {
if [ "$1" = "1" ]; then
correctnoun="item"
dirnoun="directory"
lnnoun="link"
correctverb2="exists"
warntext="WARNING:"
errortext="ERROR:"
waswere="was"
else
correctnoun="items"
dirnoun="directories"
lnnoun="links"
correctverb2="exist"
warntext="WARNINGS:"
errortext="ERRORS:"
waswere="were"
fi
}
report_print () {
echo -e "$report_indent $item_message"
for temp_name in $item_names; do
[ "$detailsmode" = true ] && echo -e "${report_indent} ${report_indent} ${CLRtitle}${temp_name}${CLRnormal}"
done
[ "$detailsmode" = true ] && echo
return 0
}
report_data_test () {
case "$1" in
test_copies)
item_num=$test_copies; report_grammar $item_num; item_names=$test_copies_names
log_message="$item_num $correctnoun will be copied"
item_message="${CLRtitle2}$item_num $correctnoun${CLRnormal} ${CLRsuccess}will be copied${CLRnormal}" ;;
test_links)
item_num=$test_links; report_grammar $item_num; item_names=$test_links_names
log_message="$item_num $lnnoun will be created"
item_message="${CLRtitle2}$item_num $lnnoun${CLRnormal} ${CLRsuccess}will be created${CLRnormal}" ;;
test_mkdir)
item_num=$test_mkdir; report_grammar $item_num; item_names=$test_mkdir_names
log_message="$item_num $dirnoun will be created"
item_message="${CLRtitle2}$item_num $dirnoun${CLRnormal} ${CLRsuccess}will be created${CLRnormal}" ;;
test_removing)
item_num=$test_removing; report_grammar $item_num; item_names=$test_removing_names
log_message="$warntext $item_num $correctnoun already $correctverb2 and require '-f' or '--force' to overwrite"
item_message="${CLRwarning}$warntext ${CLRtitle2}$item_num $correctnoun${CLRnormal} ${CLRwarning}already $correctverb2 and require '-f' or '--force' to overwrite${CLRnormal}" ;;
test_errors)
item_num=$test_errors; report_grammar $item_num; item_names=$test_errors_names
log_message="$errortext $item_num $correctnoun will fail - see Error Details"
item_message="${CLRerror}$errortext ${CLRtitle2}$item_num $correctnoun${CLRnormal} ${CLRerror}will fail - see Error Details${CLRnormal}" ;;
esac
report_print
}
report_data () {
case "$1" in
error_copies)
item_num=$error_copies; report_grammar $item_num; item_names=$error_copies_names
log_message="$item_num $correctnoun encountered errors while copying"
item_message="${CLRtitle2}$item_num $correctnoun ${CLRerror}encountered errors while copying${CLRnormal}" ;;
error_links)
item_num=$error_links; report_grammar $item_num; item_names=$error_links_names
log_message="$item_num $correctnoun encountered errors while linking"
item_message="${CLRtitle2}$item_num $correctnoun ${CLRerror}encountered errors while linking${CLRnormal}" ;;
error_mkdirs)
item_num=$error_mkdirs; report_grammar $item_num; item_names=$error_mkdirs_names
log_message="$item_num $correctnoun encountered errors during mkdir"
item_message="${CLRtitle2}$item_num $correctnoun ${CLRerror}encountered errors during mkdir${CLRnormal}" ;;
error_removals)
item_num=$error_removals; report_grammar $item_num; item_names=$error_removals_names
log_message="$item_num $correctnoun encountered errors during removal"
item_message="${CLRtitle2}$item_num $correctnoun ${CLRerror}encountered errors during removal${CLRnormal}" ;;
warning_skipped)
item_num=$warning_skipped; report_grammar $item_num; item_names=$warning_skipped_names
log_message="$item_num $correctnoun already $correctverb2 and $waswere NOT overwritten (use '-f' or '--force' to overwrite)"
item_message="${CLRtitle2}$item_num $correctnoun ${CLRwarning}already $correctverb2 and $waswere NOT overwritten (use '-f' or '--force' to overwrite)${CLRnormal}" ;;
warning_removals)
item_num=$warning_removals; report_grammar $item_num; item_names=$warning_removals_names
log_message="$item_num $dirnoun $correctverb2 and $waswere NOT deleted - child items were still processed"
item_message="${CLRtitle2}$item_num $dirnoun ${CLRwarning}$correctverb2 and $waswere NOT deleted - child items were still processed${CLRnormal}" ;;
new_copies)
item_num=$new_copies; report_grammar $item_num; item_names=$new_copies_names
log_message="$item_num $correctnoun copied"
item_message="${CLRtitle2}$item_num $correctnoun ${CLRsuccess}copied${CLRnormal}" ;;
new_links)
item_num=$new_links; report_grammar $item_num; item_names=$new_links_names
log_message="$item_num $lnnoun created"
item_message="${CLRtitle2}$item_num $lnnoun ${CLRsuccess}created${CLRnormal}" ;;
new_dirs)
item_num=$new_dirs; report_grammar $item_num; item_names=$new_dirs_names
log_message="$item_num $dirnoun created"
item_message="${CLRtitle2}$item_num $dirnoun ${CLRsuccess}created${CLRnormal}" ;;
new_removals)
item_num=$new_removals; report_grammar $item_num; item_names=$new_removals_names
log_message="$item_num $correctnoun overwritten"
item_message="${CLRtitle2}$item_num $correctnoun ${CLRsuccess}overwritten${CLRnormal}" ;;
esac
report_print
}
################################################################
### PRE-EXECUTION
# PARSE COMMAND-TAIL ARGUMENTS
for arg in "$@"; do
case "$arg" in
-f|--force) forcemode=true; shift ;;
-d|--details) detailsmode=true; shift ;;
-t|--testing) testmode=true; forcemode=false; shift ;;
-h|--help) display_help_text; processExit ;;
-v|--verbose) verbosemode=true; shift ;;
-q|--quiet) quietmode=true; verbosemode=false; shift ;;
-c|--config-file) shift; . "$1"; shift; customconfig=true ;;
-V|--version) display_ver; processExit ;;
esac
done
# SET DEFAULT DIRS (MUST OCCUR AFTER COMMAND-TAIL PARSING)
source_dir="${1:-$(pwd)}"
dest_dir="${2:-$HOME}"
# READ SETTINGS FILE (MUST OCCUR AFTER COMMAND-TAIL PARSING)
settingsfile="${source_dir}/${settingsfilename}"
settingsfileOS="${settingsfile}-${os}"
if [ "$customconfig" = false ]; then
if [ -f "${settingsfileOS}" ]; then
. "${settingsfileOS}" 2>/dev/null
[[ "$?" != 0 ]] && processAbort "Cannot read ${settingsfileOS}"
elif [ -f "${settingsfile}" ]; then
. "${settingsfile}" 2>/dev/null
[[ "$?" != 0 ]] && processAbort "Cannot read ${settingsfile}"
else
processAbort "No settings file found"
fi
fi
# CONFIG FILE GLOB EXPANSION
link_sources="${link}"
ignore_sources="${ignore}"
copy_sources="${copy}"
link_children_sources="${link_children}"
link_sources=$(remove_dupes "$link_sources" "$ignore_sources")
link_sources=$(remove_dupes "$link_sources" "$copy_sources")
link_sources=$(remove_dupes "$link_sources" "$link_children_sources")
copy_sources=$(remove_dupes "$copy_sources" "$ignore_sources")
copy_sources=$(remove_dupes "$copy_sources" "$link_children_sources")
link_children_sources=$(remove_dupes "$link_children_sources" "$ignore_sources")
# CHECK IF DEST-DIR EXISTS AND IS A DIRECTORY
if [ ! -e "$dest_dir" ]; then
make_dir "$dest_dir"
if [ "$?" -eq "0" ]; then
print_output "Destination Dir: $dest_dir created"
else
processAbort "Destination Dir: $dest_dir didn't exist and cannot be created"
fi
elif [ ! -d "$dest_dir" ]; then
processAbort "Destination Dir: $dest_dir exists, but is not a directory"
fi
################################################################
### EXECUTION
# OUTPUT EXECUTION TYPE
if [ "$testmode" = true ]; then
print_output "TEST MODE - displaying changes but not making any"; print_output
elif [ "$forcemode" = true ]; then
print_output "FORCE MODE - overwriting existing items"; print_output
else
print_output "NORMAL MODE - will NOT overwritte existing items"; print_output
fi
# CREATE LINKS
make_links "$link_sources"
# CREATE COPIES (WITH RECURSION)
for s in $copy_sources; do
if [ ! -e "$s" ]; then
continue
fi
target="$dest_dir/.$s"
children=$(echo $s/*)
if [ -d "$s" ]; then
if [ ! -e "$target" ]; then
make_dir "$target"
elif [ ! -d "$target" ]; then
prefail=true
script_error_message="$script_error_message \tCopy Error: The item '$s' is a directory in the source.\n\tBut the target '$target' already exists and is NOT a directory.\n\tAttempts to create copy items to it will fail until it is removed.\n"
else
warning_removals=$((warning_removals=warning_removals+1))
warning_removals_names="$warning_removals_names $target"
fi
for t in $children; do
if [ "$t" = "$s/*" ]; then
continue
fi
temp_src="${source_dir}/"
copy_recursion=true
make_copies "$t"
copy_recursion=false
done
prefail=false
else
temp_src=""
make_copies "$s"
fi
done
# LINK CHILDREN (WITH RECURSION) AND MKDIR IF NEEDED
# manually perform recursive functions
# for 1st and 2nd levels to get error info & count
for s in $link_children_sources; do
if [ ! -e "$s" ]; then
continue
fi
target="$dest_dir/.$s"
children=$(echo $s/*)
# WILL NOT delete an existing DIR, if TARGET:
# 'exists as a DIR' - make links in it
# 'doesn't exist' - create it, then make links in it
# 'exists but not a DIR':
# log error, generate log of failures by attempting link creation
# note: failures not discoverable in test-mode
if [ ! -e "$target" ]; then
make_dir "$target"
elif [ ! -d "$target" ]; then
prefail=true
script_error_message="$script_error_message \tLink_Children Error: The item '$s' exists and is NOT a directory.\n\tAttempts to create links in it will fail until it is removed or renamed.\n"
fi
for t in $children; do
make_links "$t"
done
prefail=false
done
[ "$quietmode" = true ] && processExit # IF 'QUIET MODE' - EXIT WITHOUT REPORT
################################################################
### REPORT (POST EXECUTION)
[ "$verbosemode" = true ] && echo
if [ "$new_copies" -gt "0" ] || [ "$new_removals" -gt "0" ] || [ "$new_links" -gt "0" ] || [ "$new_dirs" -gt "0" ]; then
success_occured=true
fi
if [ "$error_copies" -gt "0" ] || [ "$error_links" -gt "0" ] || [ "$error_removals" -gt "0" ] || [ "$error_mkdirs" -gt "0" ]; then
errors_occured=true
fi
# TEST REULTS
if [ "$testmode" = true ]; then
echo "Test-mode results:"
if [ "$detailsmode" = true ]; then
echo -e "\n${CLRnormal}source dir:\t${CLRtitle}${source_dir}${CLRnormal}"
echo -e "${CLRnormal}dest dir:\t${CLRtitle}${dest_dir}${CLRnormal}\n"
fi
[ "$test_mkdir" -gt "0" ] && report_data_test "test_mkdir"
[ "$test_copies" -gt "0" ] && report_data_test "test_copies"
[ "$test_links" -gt "0" ] && report_data_test "test_links"
[ "$test_removing" -gt "0" ] && report_data_test "test_removing"
[ "$test_errors" -gt "0" ] && report_data_test "test_errors"
fi
# SUCCESSFUL REULTS
if [ "$success_occured" = true ]; then
echo "The following actions were sucessfull:"
[ "$detailsmode" = true ] && echo
[ "$new_dirs" -gt "0" ] && report_data "new_dirs"
[ "$new_copies" -gt "0" ] && report_data "new_copies"
[ "$new_links" -gt "0" ] && report_data "new_links"
[ "$new_removals" -gt "0" ] && report_data "new_removals"
fi
# WARNINGS
if [ "$warning_skipped" -gt "0" ] || [ "$warning_removals" -gt "0" ]; then
echo "The following warnings occured:"
[ "$detailsmode" = true ] && echo
[ "$warning_removals" -gt "0" ] && report_data "warning_removals"
[ "$warning_skipped" -gt "0" ] && report_data "warning_skipped"
fi
# ERRORS
if [ "$errors_occured" = true ]; then
echo "The following errors occured:"
[ "$detailsmode" = true ] && echo
[ "$error_mkdirs" -gt "0" ] && report_data "error_mkdirs"
[ "$error_copies" -gt "0" ] && report_data "error_copies"
[ "$error_links" -gt "0" ] && report_data "error_links"
[ "$error_removals" -gt "0" ] && report_data "error_removals"
fi
# ERROR DETAILS
if [ -n "$script_error_message" ]; then
echo "Error Details:"
echo "$script_error_message"
fi
processExit
# THIS SHOULD NEVER EXECUTE
exit 0