-
Notifications
You must be signed in to change notification settings - Fork 3
/
dbwebb2-functions.bash
905 lines (716 loc) · 19.2 KB
/
dbwebb2-functions.bash
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
# --------------- DBWEBB FUNCTIONS PHASE START ---------------
#
# Get the time the script has executed since its start.
#
timeScript()
{
local end=
#end=$( date +%s.%N )
end=$( date +%s )
echo $(( end-START_TIMER ))
}
#
# Set correct mode on published file and dirs
#
publishChmod()
{
local dir="$1"
if [ -d "$dir" ]; then
find "$dir" -type d -name 'cache' -exec chmod -R a+rw {} \;
find "$dir" -type d -name 'db' -exec chmod a+rwx {} \;
find "$dir" -type d -name 'storage' -exec chmod -R a+rwx {} \;
find "$dir" -type d -name 'var' -exec chmod -R a+rwx {} \;
find "$dir" -type d -name 'web/assets' -exec chmod -R a+rwx {} \;
find "$dir" -type f -name '*.conf' -exec chmod go-r {} \;
find "$dir" -type f -name '*.py' -exec chmod go-r {} \;
find "$dir" -type f -name 'log.txt' -exec chmod go-r {} \;
find "$dir" -type f -name '*.sh' -exec chmod go-r {} \;
find "$dir" -type f -name '*.bash' -exec chmod go-r {} \;
find "$dir" -type f -name '*.cgi' -exec chmod a+rx {} \;
find "$dir" -type f -name '*.sqlite' -exec chmod a+rw {} \;
find "$dir" -type f -name '*.sql' -exec chmod go+r {} \;
case "$DBW_COURSE" in
databas)
find "$dir" -type d -path '*/me/kmom*' -exec chmod -R go-r {} \;
find "$dir" -type d -path '*/me/skolan' -exec chmod -R go-r {} \;
;;
# phpmvc)
# find "$dir" -type d -path '*/css/anax-grid' -exec chmod o+w {} \;
# find "$dir" -type f -path '*/css/anax-grid/style.css' -exec chmod o+w {} \;
# find "$dir" -type f -path '*/css/anax-grid/style.less.cache' -exec chmod o+w {} \;
# ;;
linux)
find "$dir" -type f -not -path '*/me/redovisa/*' -not -path '*/mysite/*' -name '*.js' -exec chmod go-r {} \;
find "$dir" -type f -name 'mazerunner' -exec chmod go-r {} \;
find "$dir" -type f -name '*.txt' -exec chmod go-r {} \;
find "$dir" -type f -name '*.json' -exec chmod go-r {} \;
;;
oopython \
| matmod)
find "$dir" -type f -path '*/db/*.json' -exec chmod go+w {} \;
find "$dir" -type f -name '*.py' -exec chmod go+r {} \;
find "$dir" -type f -path '*/me/kmom*/**/*.txt' -exec chmod go+rw {} \;
#find "$dir" -type f -name '*.py' -path '*/flask/*' -exec chmod go+r {} \;
#find "$dir" -type f -name '*.py' -path '*/my_app/*' -exec chmod go+r {} \;
;;
esac
fi
}
#
# realpath -f dows not work on Mac OS
#
function get_realpath()
{
# failure : file does not exist.
[[ ! -e "$1" ]] && return 1
# do symlinks.
[[ -n "$no_symlinks" ]] && local pwdp='pwd -P' || local pwdp='pwd'
# Path to dir, without eventual filename
local path="$( cd "$( echo "${1%/*}" )" 2>/dev/null; $pwdp )"
if [ -d "$1" ]; then
path="$( cd "$( echo "$1" )" 2>/dev/null; $pwdp )"
elif [ -f "$1" ]; then
path="$path/${1##*/}"
fi
echo "$path"
return 0
}
#
# Does key exists in array?
#
function exists() {
if [ "$2" != in ]; then
echo "Incorrect usage."
echo "Correct usage: exists {key} in {array}"
return
fi
eval '[ ${'$3'[$1]+muahaha} ]'
}
#
# Check if array contains a value
#
function contains() {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
#
# Join elements with separator
# join , a "b c" d #a,b c,d
# join / var local tmp #var/local/tmp
# join , "${FOO[@]}" #a,b,c
#
function join()
{
local IFS="$1";
shift;
echo "$*";
}
#
# Get the url to GitHub for a repo
#
function createGithubUrl()
{
local course="$1"
local extra="$2"
case $course in
"design")
course="design-v3"
;;
"js")
course="js-v2"
;;
esac
echo "https://github.com/dbwebb-se/$course$extra"
}
#
# Check for installed commands
#
function checkCommand
{
local COMMAND="$1"
if ! hash "$COMMAND" 2>/dev/null; then
printf "Command $COMMAND not found."
else
printf "$( which $COMMAND )"
fi
}
#
# Check command and version of it with nice string as result
#
function checkCommandWithVersion
{
local what="$1"
local version="$2"
local options="$3"
if ! hash "$what" 2>/dev/null; then
printf "%-10s Command '%s' not found." "-" "$what"
else
if [ ! -z "$version" ]; then
printf "%-10s %s" "$( eval $what $version $options )" "$( which $what )"
else
printf "%-10s %s" "?" "$( which $what )"
fi
fi
}
#
# Use command (wget, curl, lynx) to download url and output to stdout.
#
function getUrlToStdout
{
local cmd=
local url="$1"
local filename="/tmp/dbwebb.curl.$$"
local exitCode=
veryVerbose "Saving url in '$filename'."
getUrlToFile "$url" "$filename"
exitCode=$?
cat "$filename" \
|| die "Failed to echo content from downloaded file."
rm -f "$filename"
( exit $exitCode )
}
#
# Use command (wget, curl, lynx) to download url and output to file.
# The variable OPTION_WITH_WGET_ALT can be used to specify the tool
# to use, wget is default and options are curl and lynx.
#
function getUrlToFile
{
local cmd=
local verbose=
local url="$1"
local filename="$2"
local overwrite="$3"
if [ -z "$OPTION_WITH_WGET_ALT" ] && hash wget 2>/dev/null; then
verbose="--quiet"
[[ $VERY_VERBOSE ]] && verbose="--verbose"
cmd="wget $verbose -O \"$filename\" \"$url\""
elif ([ -z "$OPTION_WITH_WGET_ALT" ] || [ "$OPTION_WITH_WGET_ALT" = "curl" ]) && hash curl 2>/dev/null; then
cmd="curl --fail --silent $verbose \"$url\" -o \"$filename\""
elif ([ -z "$OPTION_WITH_WGET_ALT" ] || [ "$OPTION_WITH_WGET_ALT" = "lynx" ]) && hash lynx 2>/dev/null; then
cmd="lynx -source \"$url\" > \"$filename\""
fi
veryVerbose "Command: $cmd"
if [ -f "$filename" ] && [ -z "$overwrite" ]; then
die "The file '$filename' already exists, please remove it before you download a new."
fi
[[ $OPTION_DRY ]] || bash -c "$cmd"
}
#
# Press enter to continue
#
pressEnterToContinue()
{
if [[ ! $YES ]]; then
printf "\nPress enter to continue..."
read void
fi
}
#
# Answer yes or no to proceed
#
answerYesOrNo()
{
local answer="y"
local default="$1"
if [[ ! $YES ]]; then
read answer
answer=${answer:-$default}
fi
echo "$answer"
}
##
# Print confirmation message with default values.
#
# @param string $1 the message to display or use default.
# @param string $2 the default value for the response.
#
confirm()
{
[[ $YES ]] && return 0
read -r -p "${1:-Are you sure? [yN]} "
case "${REPLY:-$2}" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
##
# Read input from user supporting a default value for reponse.
#
# @param string $1 the message to display.
# @param string $1 the default value.
#
input()
{
read -r -p "$1 [$2]: "
echo "${REPLY:-$2}"
}
#
# Execute a command in a controlled manner
#
function executeCommandInSubShell
{
executeCommand "$1" "$2" "$3" "$4" "subshell"
}
#
# Execute a command in a controlled manner
#
function executeCommand
{
local introText="$1"
local subshell="$5"
# Introduction text for the command
echo "$introText"
REALLY="$4"
if [ ! -z $REALLY ]
then
printf "\nAre you really sure? [yN] "
read answer
default="n"
answer=${answer:-$default}
if [ ! \( "$answer" = "y" -o "$answer" = "Y" \) ]
then
printf "Exiting...\n"
exit 0
fi
fi
COMMAND="$2"
if [[ $VERY_VERBOSE ]]
then
printf "\nExecuting command:"
printf "\n$COMMAND"
printf "\n-----------------------------------------"
printf "\n"
fi
if [ "$subshell" = "subshell" ]; then
( "$COMMAND" )
else
bash -c "$COMMAND"
fi
STATUS=$?
if [[ $VERY_VERBOSE ]]
then
printf "\n-----------------------------------------"
printf "\n"
fi
MESSAGE=$3
if [[ ! $SILENT ]]; then
if [ $STATUS = 0 ]
then
printf "$MSG_DONE $MESSAGE"
else
printf "$MSG_FAILED $MESSAGE"
fi
printf "\n"
fi
return $STATUS
}
#
# Convert version to a compareble string
# Works for 1.0.0 and v1.0.0
#
function getSemanticVersion
{
#local version=${1:1}
local version=$( echo $1 | sed s/^[vV]// )
echo "$version" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'
}
#
# Check if current version of dbwebb-cli matches minimum required version.
#
function checkMinimumVersionRequirementOrExit
{
if [[ $DBW_VERSION_REQUIREMENT ]]; then
local required current
required=$( getSemanticVersion $DBW_VERSION_REQUIREMENT )
current=$( getSemanticVersion $DBW_VERSION )
if [ "$current" -lt "$required" ]; then
printf "$MSG_FAILED You need to upgrade dbwebb-cli to work with this course repo.\nDo a 'dbwebb selfupdate'.\n"
printf "Your current version is: %s\n" "$DBW_VERSION"
printf "Minimum required version is: %s\n" "$DBW_VERSION_REQUIREMENT"
exit 1
fi
fi
}
#
# Check if within a valid course repo or exit
#
function checkIfValidCourseRepoOrExit
{
if [ "$DBW_COURSE_REPO_VALID" != "yes" ]; then
printf "$MSG_FAILED Could not find file '%s', this is not a valid course repo." "$DBW_COURSE_FILE_NAME"
printf "\nThis command must be executed within a valid course repo."
printf "\n"
exit 1
fi
checkMinimumVersionRequirementOrExit
}
#
# Check if config file or exit
#
function checkIfValidConfigOrExit()
{
if [ ! -f "$DBW_CONFIG_FILE" ]; then
printf "$MSG_FAILED Could not find the configuration file '$DBW_CONFIG_FILE', this is needed for this operation."
printf "\n"
exit 1
fi
}
#
# Check if valid combination of course and target.
#
function checkIfValidCombination()
{
local res="$1"
local target="$2"
if [ -z "$res" ]; then
printf "$MSG_FAILED Not a valid combination of '$DBW_COURSE' and target '$target'.\n"
exit 2
fi
}
#
# Check if subdir to me/ exists or propose to run init.
#
checkIfSubdirExistsOrProposeInit()
{
local dir="$1"
if [ ! -d "$dir" ]; then
printf "$MSG_FAILED The target directory '$dir' is missing.\nPerhaps, did you run the command 'dbwebb init' or misspelled the command?\n"
exit 2
fi
}
#
# Fail, die and present error message.
#
die()
{
local message="$1"
local status="${2:-1}"
printf "$MSG_FAILED $message\n" >&2
exit $status
}
#
# Print out information details in standard verbose mode.
#
verboseDone()
{
[[ $SILENT ]] || printf "$MSG_DONE $1\\n"
}
#
# Print out information details that command partly failed.
#
verboseWarning()
{
[[ $SILENT ]] || printf "$MSG_WARNING $1\\n"
}
#
# Print out information details that command has failed.
#
verboseFail()
{
[[ $SILENT ]] || printf "$MSG_FAILED $1\\n"
}
#
# Print out information details in standard verbose mode.
#
verbose()
{
[[ $SILENT ]] || printf "$1\\n"
}
#
# Print out details in very verbose mode.
#
veryVerbose()
{
[[ $VERY_VERBOSE ]] && printf "$1\\n" >&2
}
#
# Read the version of the labs used, from configuration file.
#
readLabVersionFromConfig()
{
[ -f "$DBW_COURSE_DIR/.dbwebb/lab.version" ] \
&& cat "$DBW_COURSE_DIR/.dbwebb/lab.version"
}
#
# Set proper rights for files and directories
# OBSOLETE to be replaced by rsync --chmod
#
setChmod()
{
if [[ $VERY_VERBOSE ]]; then
printf "Ensuring that all files and directories are readable for all, below $DBW_COURSE_DIR.\n"
fi
find "$DBW_COURSE_DIR" -type d -exec chmod u+rwx,go+rx {} \;
find "$DBW_COURSE_DIR" -type f -exec chmod u+rw,go+r {} \;
}
#
# Convert course specific module to path on disk
#
mapCmdToDir()
{
local CMD="$1"
local RES=""
if [ -z "$CMD" ]; then
return
fi
case "$CMD" in
example) RES="example" ;;
me) RES="me" ;;
redovisa) RES="me/redovisa" ;;
kmom01) RES="me/kmom01" ;;
kmom02) RES="me/kmom02" ;;
kmom03) RES="me/kmom03" ;;
kmom04) RES="me/kmom04" ;;
kmom05) RES="me/kmom05" ;;
kmom06) RES="me/kmom06" ;;
kmom10) RES="me/kmom10" ;;
esac
[ ! -z $RES ] && echo "$RES" && return
# Check for known pathes in course repo config file
local mapFile="$DBW_COURSE_DIR/.dbwebb.map"
local item=
if [ -f "$mapFile" ]; then
while IFS= read -r path
do
item=$( basename "$path" )
if [ "$CMD" = "$item" -a -d "$path" ]; then
echo "$path"
return
fi
done < <(grep "^[^#]" "$mapFile")
fi
# Check for existing directories below me/
[ -d "$DBW_COURSE_DIR/me/$CMD" ] && echo "me/$CMD" && return
# Check me/* for match
RES=$( cd "$DBW_COURSE_DIR" && find me -mindepth 2 -maxdepth 2 -name "$CMD" -type d | head -n 1 )
echo "$RES"
return
}
#
# Get path to dir to check, use both parts of courses and fallback
# to absolute and relative paths.
#
function createDirsInMeFromMapFile
{
local mapFile="$DBW_COURSE_DIR/.dbwebb.map"
if [ -f "$mapFile" ]; then
while IFS= read -r path
do
echo "$path"
install -d "$DBW_COURSE_DIR/$path"
done < <(grep "^[^#]" "$mapFile")
fi
}
#
# Get path to dir to check, use both parts of courses and fallback
# to absolute and relative paths.
#
function getPathToDirectoryFor
{
local dir="$( mapCmdToDir $1 )"
if [ -z "$command" ]; then
echo "$DBW_CURRENT_DIR"
elif [ -z "$dir" -a -d "$command" ]; then
echo "$command"
elif [ -z "$dir" -a -d "$DBW_CURRENT_DIR/$command" ]; then
echo "$DBW_CURRENT_DIR/$command"
elif [ ! -z "$dir" -a -d "$DBW_COURSE_DIR" -a -d "$DBW_COURSE_DIR/$dir" ]; then
echo "$DBW_COURSE_DIR/$dir"
else
printf "\n$MSG_FAILED The item '$command' was mapped to directory '$dir' which is not a valid directory.\n"
exit 1
fi
}
#
# Validate the uploaded files
#
createUploadDownloadPaths()
{
local ignoreSubdir="$1"
SUBDIR="$( mapCmdToDir $ITEM )"
if [ -z "$WHAT" -o -z "$WHERE" ]; then
printf "$MSG_FAILED Missing argument for source or destination. Perhaps re-create the config-file?"
printf "\n\n"
exit 1
fi
#if [ -d "$DBW_CURRENT_DIR/$ITEM" ]; then
# SUBDIR="${ITEM%/}"
#elif [ ! -z "$ITEM" -a -z "$SUBDIR" ]; then
if [ ! -z "$ITEM" -a -z "$SUBDIR" ]; then
printf "\n$MSG_FAILED Not a valid combination course: '$DBW_COURSE' and item: '$ITEM'."
printf "\n\n"
exit 1
fi
if [ ! -z "$ignoreSubdir" ]; then
WHAT="$WHAT/"
WHERE="$WHERE/"
elif [ ! -z "$SUBDIR" ]; then
WHAT="$WHAT/$SUBDIR/"
WHERE="$WHERE/$SUBDIR/"
else
WHAT="$WHAT/"
WHERE="$WHERE/"
fi
#echo "WHAT=$WHAT"
#echo "WHERE=$WHERE"
if [ ! -d "$WHAT" ]; then
printf "\n$MSG_FAILED Target directory is not a valid directory: '$WHAT'"
printf "\n\n"
exit 1
fi
}
#
# Selfupdate
#
selfupdate()
{
local what="$1"
local version=${2:-master}
local target="$DBW_EXECUTABLE_PATH"
local remote=
local silent="--quiet"
local repo="https://raw.githubusercontent.com/mosbth/dbwebb-cli/$version"
if [[ $VERY_VERBOSE ]]; then
silent=""
fi
case $what in
dbwebb)
remote="$repo/dbwebb2"
;;
dbwebb-validate)
remote="$repo/dbwebb2-validate"
;;
dbwebb-inspect)
remote="$repo/dbwebb2-inspect"
;;
esac
printf "Your current version is: "
$what --version
echo "Selfupdating '$what' from $repo"
# Downloading
# printf '\nDownloading... '; wget $silent $remote -O /tmp/$$;
if hash wget 2> /dev/null; then
local dli="Downloading using wget... "
local dlc="wget $silent $remote -O /tmp/$$"
else
echo "Failed. Did not find wget. Please install wget."
exit 1
fi
local dlm="to download."
executeCommand "$dli" "$dlc" "$dlm"
[[ $STATUS > 0 ]] && echo "Could not download the remote file, check the download link if its correct." && exit 1
# Installing
# printf '\nInstalling... '; install /tmp/$$ $target;
local ini="Installing... "
local inc="install /tmp/$$ $target"
local inm="to install."
executeCommand "$ini" "$inc" "$inm"
local ins=$?
# Cleaning up
# printf '\nCleaning up... '; rm /tmp/$$;
local cli="Cleaning up... "
local clc="rm /tmp/$$"
local clm="to clean up."
executeCommand "$cli" "$clc" "$clm"
if [ $ins != 0 ]; then
exit 1
fi
printf "The updated version is now: "
$what --version
}
#
# Perform an assert
#
function assert()
{
EXPECTED=$1
TEST=$2
MESSAGE=$3
ASSERTS=$(( $ASSERTS + 1 ))
local onlyExitStatus=$4
local error=
local status=
bash -c "$TEST" &> "$TMPFILE"
status=$?
if [ \( -z "$onlyExitStatus" \) -o \( ! $status -eq $EXPECTED \) ]; then
error=$( cat "$TMPFILE" )
fi
rm -f "$TMPFILE"
if [ \( ! $status -eq $EXPECTED \) -o \( ! -z "$error" \) ]; then
FAULTS=$(( $FAULTS + 1 ))
printf "\n\n$MSG_WARNING %s\n" "$MESSAGE"
[ -z "$error" ] || printf "%s\n\n" "$error"
ASSERTS_SUMMARY="$ASSERTS_SUMMARY\n $MSG_WARNING $MESSAGE\n"
else
ASSERTS_SUMMARY="$ASSERTS_SUMMARY."
fi
return $status
}
#
# Add details to the assert summary, for example when a new section is
# started, to visualise and greoup the asserts into sections.
#
function assertSummaryAdd()
{
local message="$1"
local space=" "
# ten=" "
# forty="$ten$ten$ten$ten"
# y="very short text"
# y="${y:0:40}${forty:0:$((40 - ${#y}))}"
# echo "'${y}'"
message="${message:0:12}${space:0:$((12 - ${#message}))}"
ASSERTS_SUMMARY="$ASSERTS_SUMMARY\n# $message"
}
# #
# # Perform an assert on exit value returned
# # TODO Check if this is really needed by python inspect
# # OBSOLETE Not used
# #
# assertExit()
# {
# EXPECTED=$1
# TEST=$2
# MESSAGE=$3
# ASSERTS=$(( $ASSERTS + 1 ))
#
# bash -c "$TEST" &> "$TMPFILE"
# STATUS=$?
# ERROR=$( cat "$TMPFILE" )
# rm -f "$TMPFILE"
#
# if [ $STATUS -ne $EXPECTED ]; then
# FAULTS=$(( $FAULTS + 1 ))
#
# printf "\n$TEST"
# printf "\n\n$MSG_FAILED $MESSAGE\n"
# [ -z "$ERROR" ] || printf "$ERROR\n\n"
#
# return 1
# fi
#
# return 0
#
# }
#
# Clean up and output results from asserts
# TODO Seems to be used by validate
#
function assertResults()
{
if [ $FAULTS -gt 0 ]; then
printf "\n\n$MSG_FAILED"
printf " Asserts: $ASSERTS Faults: $FAULTS\n\n"
exit 1
fi
printf "\n$MSG_OK"
printf " Asserts: $ASSERTS Faults: $FAULTS\n"
exit 0
}
# --------------- DBWEBB FUNCTIONS PHASE END ---------------