-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgui.bash
executable file
·1697 lines (1377 loc) · 42.1 KB
/
gui.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
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
#!/usr/bin/env bash
#
# GUI for dbwebb inspect.
#
VERSION="v2.12.0 (2023-09-06)"
# Messages
MSG_OK="\033[0;30;42mOK\033[0m"
MSG_DONE="\033[1;37;40mDONE\033[0m"
MSG_WARNING="\033[43mWARNING\033[0m"
MSG_FAILED="\033[0;37;41mFAILED\033[0m"
# ---------------------------- Functions ------------------
#
# Press enter to continue
#
pressEnterToContinue()
{
local void
if [[ ! $YES ]]; then
printf "\nPress enter to continue..."
read void
fi
}
#
# Read input from user supporting a default value for reponse.
#
# @arg1 string the message to display.
# @arg2 string the default value.
#
input()
{
read -r -p "$1: "
echo "${REPLY:-$2}"
}
#
# Read input from user replying with yY or nN.
#
# @arg1 string the message to display.
# @arg2 string the default value, y or n.
#
yesNo()
{
read -r -p "$1 (y/n) [$2]: "
echo "${REPLY:-$2}"
}
#
# Display information message and wait for user input to continue, exit if
# user presses 'q'.
#
# @arg1 string the message to display.
#
info()
{
echo -e "\n$1"
read -r -p ""
case "$REPLY" in
q)
exit 1
;;
esac
}
#
# Fail, die and present error message.
#
# @arg1 string the message to display.
# @arg2 string exit status (default 1).
#
die()
{
local message="$1"
local status="${2:1}"
printf "$MSG_FAILED $message\n" >&2
exit $status
}
#
# Set correct settings of the remote student files, populary called "potatoe".
#
# @arg1 string the acronym.
#
potatoe()
{
local acronym
local course="$COURSE"
if [[ $2 = "false" ]]; then
course=
fi
acronym=$( input "Uppdatera rättigheterna för denna student?" "$1" )
dbwebb run "sudo /usr/local/sbin/setpre-dbwebb-kurser.bash $acronym $course"
#dbwebb run "sudo /usr/local/sbin/setpre-dbwebb-kurser.bash $acronym"
}
#
# 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
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"
}
#
# Create a config file that are sourced each time the application starts.
#
createConfigFile()
{
local url="https://raw.githubusercontent.com/dbwebb-se/inspect-gui/master/gui_config.bash"
local source="/tmp/gui_config.bash$$"
local reply=
if [[ -f $DBWEBB_GUI_CONFIG_FILE ]]; then
reply=$( yesNo "Du har redan en konfigurationsfil, vill du skriva över den?" "n" )
case "$reply" in
[yY]) ;;
*) printf "Ignoring..." && return ;;
esac
fi
install -d "$( dirname $DBWEBB_GUI_CONFIG_FILE )"
getUrlToFile "$url" "$source" "overwrite" \
&& cp "$source" "$DBWEBB_GUI_CONFIG_FILE" \
&& printf "Konfigurationsfilen är nu skapad, redigera den i en texteditor.\n" \
&& ls -l "$DBWEBB_GUI_CONFIG_FILE"
# shellcheck source=$HOME/.dbwebb.gui_config.bash
[[ -f $DBWEBB_GUI_CONFIG_FILE ]] && source "$DBWEBB_GUI_CONFIG_FILE"
}
#
# Show and edit the configuration file.
#
showAndEditConfigFile()
{
local editor=${EDITOR:-vi}
$editor "$DBWEBB_GUI_CONFIG_FILE"
# shellcheck source=$HOME/.dbwebb.gui_config.bash
[[ -f $DBWEBB_GUI_CONFIG_FILE ]] && source "$DBWEBB_GUI_CONFIG_FILE"
}
#
# Goto directory and check its status on .git
# @arg1 string the path to move to.
#
check_dir_for_git()
{
pushd $1
if [ ! -d .git ]; then
echo "No git-repo on highest level: $1"
ls -l
return
fi
# Show details
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
echo "$1"
git remote -v
git tag
# Checkout version and set it up
TAG=$( input "Checkout tag" "" )
git checkout $TAG
npm install
popd
}
#
# Find the course repo file.
#
function findCourseRepoFile
{
dir="$( pwd )/."
while [ "$dir" != "/" ]; do
dir=$( dirname "$dir" )
found="$( find "$dir" -maxdepth 1 -name $DBW_COURSE_FILE_NAME )"
if [ "$found" ]; then
DBW_COURSE_DIR="$( dirname "$found" )"
break
fi
done
}
#
# Get the name of the course as $DBW_COURSE
#
function sourceCourseRepoFile
{
DBW_COURSE_FILE="$DBW_COURSE_DIR/$DBW_COURSE_FILE_NAME"
if [ -f "$DBW_COURSE_FILE" ]; then
# shellcheck source=$DBW_COURSE_DIR/$DBW_COURSE_FILE_NAME
source "$DBW_COURSE_FILE"
fi
}
#
# Check if all tools are available
#
function checkTool() {
if ! hash "$1" 2> /dev/null; then
printf "$MSG_FAILED Missing '$1'.\n$2\n"
exit -1
fi
}
#
# Open an url in the default browser
#
# @arg1 the url
#
function openUrl {
local url="$1"
printf "$url\n"
eval "$BROWSER" "$url" &
sleep 0.5
}
#
# Open an Git http or git@ url browser
#
# @arg1 the remote as https or [email protected]
#
function openGitUrl {
local url="$1"
#local re="^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git$"
local re="^git@(.+):(.+)\/(.+)(\.git)?$"
if [[ $url == https://* ]]; then
openUrl "$url"
elif [[ $url =~ $re ]]; then
hostname=${BASH_REMATCH[1]}
user=${BASH_REMATCH[2]}
repo=${BASH_REMATCH[3]}
gitUrl="https://$hostname/$user/$repo"
openUrl "$gitUrl"
fi
}
#
# Open a specific url in the default browser, but use a base url if it
# does not exists as a local relative path.
#
# @arg1 the base http adress
# @arg2 the base url to use
# @arg3 the specific url to try and use
#
function openSpecificUrl {
local base="$1"
local baseUrl="$2"
local specificUrl="$3"
local modified="$baseUrl/$specificUrl"
#echo "TRYING: -f $modified"
if [[ -f "$modified" || -d "$modified" ]]; then
#echo "FILE/DIR: $modified"
openUrl "$base/$modified"
return
fi
modified=${modified%/*}
#echo "TRYING: -d $modified"
if [[ -d $modified ]]; then
#echo "FOUND DIR: $modified"
openUrl "$base/$modified"
return
fi
#echo "USING BASE"
openUrl "$base/$baseUrl"
}
#
# Check if the git tag is between two versions
# >=@arg2 and <@arg3
#
# @arg1 string the path to the dir to check.
# @arg2 string the lowest version number to check.
# @arg3 string the highest version number to check.
#
hasGitTagBetween()
{
local where="$1"
local low=
local high=
local semTag=
low=$( getSemanticVersion "$2" )
high=$( getSemanticVersion "$3" )
#echo "Validate that tag exists >=$2 and <$3 ."
local success=false
local highestTag=0
local highestSemTag=0
if [ -d "$where" ]; then
while read -r tag; do
semTag=$( getSemanticVersion "$tag" )
#echo "trying tag $tag = $semTag"
if [ $semTag -ge $low -a $semTag -lt $high ]; then
#echo "success with $tag"
success=
if [ $semTag -gt $highestSemTag ]; then
highestTag=$tag
highestSemTag=$semTag
fi
fi
done < <( cd "$where" && git tag )
fi
if [ "$success" = "false" ]; then
printf "$MSG_FAILED Failed to validate tag exists >=%s and <%s." "$2" "$3"
fi
echo $highestTag
}
#
# Convert version to a comparable string
# Works for 1.0.0 and v1.0.0
#
# @arg1 string the version to check.
#
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); }'
}
# ---------------------------- Bootstrap ------------------
# Check needed utils is available
#
#
checkTool dialog "Install using your packet manager (apt-get|brew install dialog)."
#checkTool realpath "Install using your packet manager (brew install coreutils)."
# What is the directory of the current course repo, find recursivly up the tree
DBW_COURSE_FILE_NAME=".dbwebb.course"
findCourseRepoFile
[[ $DBW_COURSE_DIR ]] || die "You must run this command within a valid course repo."
DIR="$DBW_COURSE_DIR"
TENTAMEN_DIR="$DIR/exam"
# Get the name of the course as $DBW_COURSE
sourceCourseRepoFile
[[ $DBW_COURSE ]] || die "Your course repo does not seem to have a valid or correct '$DBW_COURSE_FILE_NAME'."
COURSE="$DBW_COURSE"
# Source the user config file if it exists
DBWEBB_GUI_CONFIG_FILE="$HOME/.dbwebb/gui_config.bash"
# shellcheck source=$HOME/.dbwebb.gui_config.bash
[[ -f $DBWEBB_GUI_CONFIG_FILE ]] && source "$DBWEBB_GUI_CONFIG_FILE"
# Save INSPECT_PID to be able to kill it
DBWEBB_INSPECT_PID=
# Preconditions
hash dialog 2>/dev/null \
|| die "You need to install 'dialog'."
# Preconditions
hash tree 2>/dev/null \
|| die "You need to install 'tree'."
# Where to store the logfiles
LOG_BASE_DIR="$DIR/.log/inspect"
install -d -m 0777 "$LOG_BASE_DIR"
LOG_DOCKER_REL=".log/inspect/docker.txt"
export LOG_DOCKER="$DIR/$LOG_DOCKER_REL"
LOGFILE="$LOG_BASE_DIR/gui-main.ansi"
LOGFILE_INSPECT="$LOG_BASE_DIR/gui-inspect.ansi"
LOGFILE_TEXT="$LOG_BASE_DIR/gui-feedback.ansi"
# Settings
BACKTITLE="dbwebb/$COURSE"
TITLE="Work with kmoms"
# OS specific default settings
BROWSER="firefox"
TO_CLIPBOARD="xclip -selection c"
OS_TERMINAL=""
if [[ "$(uname -r)" == *"microsoft"* ]]; then # WSl on Unix
OS_TERMINAL="wsl"
TO_CLIPBOARD="clip.exe"
BROWSER="wslview"
elif [[ "$OSTYPE" == "linux-gnu" ]]; then # Linux, use defaults
OS_TERMINAL="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then # Mac OSX
OS_TERMINAL="macOS"
TO_CLIPBOARD="iconv -t macroman | pbcopy"
BROWSER="open"
elif [[ "$OSTYPE" == "cygwin" ]]; then # Cygwin
OS_TERMINAL="cygwin"
TO_CLIPBOARD="cat - > /dev/clipboard"
BROWSER="/cygdrive/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe"
elif [[ "$OSTYPE" == "msys" ]]; then
:
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
fi
# Use defaults or overwrite from configuration/environment settings
BROWSER=${DBWEBB_BROWSER:-$BROWSER}
TO_CLIPBOARD=${DBWEBB_TO_CLIPBOARD:-$TO_CLIPBOARD}
TEACHER_SIGNATURE=${DBWEBB_TEACHER_SIGNATURE:-"// XXX"}
# Set source dir for scripts and feedback
INSPECT_SOURCE_DIR="$DIR/.dbwebb/inspect-src"
INSPECT_SOURCE_DIR=${DBWEBB_INSPECT_SOURCE_DIR:-$INSPECT_SOURCE_DIR}
INSPECT_SOURCE_CONFIG_FILE="$INSPECT_SOURCE_DIR/config.bash"
[[ -d "$INSPECT_SOURCE_DIR" ]] || die "The path to inspect source files does not exists:\n INSPECT_SOURCE_DIR='$INSPECT_SOURCE_DIR'."
# shellcheck source=$DIR/.dbwebb/inspect-src/config.bash
[[ -f $INSPECT_SOURCE_CONFIG_FILE ]] && source "$INSPECT_SOURCE_CONFIG_FILE"
# Useful defaults which are used within the application
# @TODO This is not really needed
dockerContainer="mysql"
# Remember last menu choice (or set defaults)
mainMenuSelected=1
# --------------------------- GUI functions ------------------------------
#
#
#
gui-firstpage()
{
local message
read -r -d "" message << EOD
README ($VERSION)
================================================
This is a graphical gui for working with inspect.
WARNING. All your files in 'me/' is overwritten on each download.
Prepare by this:
* dbwebb update
* dbwebb init-me
* make install # For local inspects
The output from inspect is written to files in '.log/inspect'.
Review the admin menu for customizing and creating a configuration file where you can store customized settings.
$DBWEBB_GUI_CONFIG_FILE
Basic feedback text is created from files in txt/kmom??.txt, add your own teacher signature through the configuration file (see Admin Menu).
/Mikael
EOD
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--msgbox "$message" \
24 80 \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
gui-show-configuration()
{
local message
read -r -d "" message << EOD
SETTINGS
================================================
These are your current settings that are currently used.
BROWSER="$BROWSER"
OS_TERMINAL="$OS_TERMINAL"
TEACHER_SIGNATURE="$TEACHER_SIGNATURE"
TO_CLIPBOARD="$TO_CLIPBOARD"
All these are set with default values (within the script) and you can override them by setting the following environment variabels, preferably using the configuration file.
DBWEBB_BROWSER="$DBWEBB_BROWSER"
DBWEBB_TEACHER_SIGNATURE="$DBWEBB_TEACHER_SIGNATURE"
DBWEBB_TO_CLIPBOARD="$DBWEBB_TO_CLIPBOARD"
These are default settings for opening the browser.
windows (cygwin): export BROWSER="/cygdrive/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"
macOs: export BROWSER="open /Applications/Firefox.app"
linux: export BROWSER="firefox"
These are the default settings for using the clipboard when the feedback text is available through ctrl-v/cmd-v.
windows (cygwin): export TO_CLIPBOARD="cat - > /dev/clipboard"
macOs: export TO_CLIPBOARD="iconv -t macroman | pbcopy"
linux: export TO_CLIPBOARD="xclip -selection c"
/Mikael
EOD
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--msgbox "$message" \
24 80 \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
gui-main-menu()
{
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--default-item "$mainMenuSelected" \
--menu "Main menu" \
24 80 \
20 \
"1" "Inspect kmom (download, docker)" \
"2" "Inspect kmom (docker)" \
"5" "Inspect kmom (download, local)" \
"6" "Inspect kmom (local)" \
"7" "Inspect tentamen (rsync, docker)" \
"8" "Inspect tentamen (docker)" \
"" "---" \
"c" "Course menu" \
"a" "Admin menu" \
"q" "Quit" \
3>&1 1>&2 2>&3 3>&-
# "3" "Inspect kmom (download, no-docker)" \
# "4" "Inspect kmom (no-docker)" \
# TODO Clean upp this and remove from script
#"" "---" \
#"d" "Download student me/" \
#"w" "Open student me/redovisa in browser" \
#"p" "Potatoe student" \
#"o" "Docker menu" \
}
#
#
#
gui-admin-menu()
{
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "Main » Admin menu" \
24 80 \
20 \
"c" "Create a default configuration file ~/.dbwebb/gui_config.bash" \
"e" "Show and edit the user configuration file ~/.dbwebb/gui_config.bash" \
"s" "Show configuration settings" \
"r" "View README" \
"b" "Back" \
3>&1 1>&2 2>&3 3>&-
}
# ----------------------------- stuff relates to database exam
#
#
#
gui-show-receipt()
{
local acronym="$1"
dialog \
--backtitle "$BACKTITLE" \
--title "Receipt for $acronym" \
--msgbox "$( get-receipt $acronym )" \
40 80 \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
get-receipt()
{
local acronym="$1"
local message=
message=$(< "$TENTAMEN_DIR/$acronym/RECEIPT.md" )
echo "$TENTAMEN_DIR/$acronym/RECEIPT.md"
[[ -z $message ]] && message="No RECEIPT.md found for $acronym"
echo "$message"
}
#
#
#
gui-read-seal-version()
{
local acronym="$1"
local path=
select=$( cd "$TENTAMEN_DIR" && find "$acronym" -maxdepth 1 -mindepth 1 -type d | tail -1 )
path="$TENTAMEN_DIR/$select"
dialog \
--backtitle "$BACKTITLE" \
--title "Select sealed version ($acronym)" \
--dselect "$path" \
24 80 \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
printReceipt()
{
local acronym="$1"
header "Receipt" | tee -a "$LOGFILE"
printf "\n%s\n\n" "$( get-receipt $acronym )" | tee -a "$LOGFILE"
}
#
# Make a validate using docker.
#
makeValidateDocker()
{
local target="$1"
header "dbwebb validate" "Do dbwebb validate in the background and write output to logfile." | tee -a "$LOGFILE"
#header "dbwebb inspect" | tee -a "$LOGFILE"
if [[ ! -z $DBWEBB_INSPECT_PID ]]; then
# echo "Killing $DBWEBB_INSPECT_PID" | tee "$LOGFILE_INSPECT"
kill -9 $DBWEBB_INSPECT_PID > /dev/null 2>&1
DBWEBB_INSPECT_PID=
fi
if [ $OS_TERMINAL == "linux" ]; then
setsid make docker-run what="make validate what=$target" > "$LOGFILE_INSPECT" 2>&1 &
DBWEBB_INSPECT_PID="$!"
else
make docker-run what="make validate what=$target" > "$LOGFILE_INSPECT" 2>&1 &
DBWEBB_INSPECT_PID="$!"
fi
# (cd "$COURSE_DIR" && make docker-run what="make validate what=$target" > "$LOGFILE_INSPECT" 2>&1 &)
#(cd "$COURSE_DIR" && make docker-run what="make validate what=$target/" 2>&1 | tee -a "$LOGFILE")
}
# ----------------------------- END OF DATABASE EXAM
# #
# #
# #
# gui-database-menu()
# {
# dialog \
# --backtitle "$BACKTITLE" \
# --title "$TITLE" \
# --menu "Main » Database menu" \
# 24 80 \
# 20 \
# "u" "Create users dbwebb:password and user:pass into docker mysql" \
# "l" "Load standard kmom database dump into docker mysql" \
# "1" "Load student skolan/reset_part1.bash into docker mysql" \
# "2" "Load student skolan/reset_part2.bash into docker mysql" \
# "3" "Load student skolan/reset_part3.bash into docker mysql" \
# "4" "Load student skolan/skolan.sql into docker mysql" \
# "b" "Back" \
# 3>&1 1>&2 2>&3 3>&-
# }
# #
# #
# #
# gui-docker-menu()
# {
# dialog \
# --backtitle "$BACKTITLE" \
# --title "$TITLE" \
# --menu "Main » Docker menu" \
# 24 80 \
# 20 \
# "u" "Docker up -d [$dockerContainer]" \
# "r" "Docker run [$dockerContainer] bash" \
# "s" "Docker start [$dockerContainer]" \
# "t" "Docker stop" \
# "b" "Back" \
# 3>&1 1>&2 2>&3 3>&-
# }
#
#
#
gui-read-kmom()
{
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--default-item "$kmom" \
--menu "Select kmom" \
24 80 \
20 \
"kmom01" "kmom01" \
"kmom02" "kmom02" \
"kmom03" "kmom03" \
"kmom04" "kmom04" \
"kmom05" "kmom05" \
"kmom06" "kmom06" \
"kmom10" "kmom10" \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
gui-read-acronym()
{
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--inputbox "Select student acronym (ctrl-u to clear)" \
24 80 \
"$1" \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
gui-read-docker-container()
{
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--inputbox "Select docker container" \
24 80 \
"$1" \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
main-admin-menu()
{
local output
while true; do
output=$( gui-admin-menu )
case $output in
c)
createConfigFile
pressEnterToContinue
;;
e)
showAndEditConfigFile
pressEnterToContinue
;;
s)
gui-show-configuration
;;
r)
gui-firstpage
;;
b|"")
return
;;
esac
done
}
#
#
#
gui-course-menu()
{
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "Main » Course menu" \
24 80 \
20 \
"d" "databas" \
"b" "Back" \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
main-course-menu()
{
local output
while true; do
output=$( gui-course-menu )
case $output in
d)
main-course-databas-menu
;;
b|"")
return
;;
esac
done
}
#
#
#
gui-course-databas-menu()
{
dialog \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "Main » Course » 'databas' menu" \
24 80 \
20 \
"u" "Create users dbwebb:pass and user:pass into docker mysql" \
"l" "Load standard kmom database dump into docker mysql" \
"1" "Load student skolan/reset_part1.bash into docker mysql" \
"2" "Load student skolan/reset_part2.bash into docker mysql" \
"3" "Load student skolan/reset_part3.bash into docker mysql" \
"4" "Load student skolan/skolan.sql into docker mysql" \
"b" "Back" \
3>&1 1>&2 2>&3 3>&-
}
#
#
#
main-course-databas-menu()
{
local output
local path
while true; do
output=$( gui-course-databas-menu )
case $output in
u)
runSqlScript "example/sql/create-user-dbwebb.sql"
runSqlScript "example/sql/create-user-user.sql" "dbwebb"
runSqlScript "example/sql/check-env.sql" "dbwebb"
pressEnterToContinue
;;
l)
kmom=$( gui-read-kmom $kmom )
[[ -z $kmom ]] && continue
for file in $INSPECT_SOURCE_DIR/kmom.d/$kmom/dump_*.sql; do
runSqlScript "$file" "dbwebb"
done
pressEnterToContinue
;;
1)
runSqlScript "example/sql/inspect/setup_skolan.sql" "dbwebb"
make docker-run what="bash me/skolan/reset_part1.bash"
pressEnterToContinue
;;
2)
runSqlScript "example/sql/inspect/setup_skolan.sql" "dbwebb"
make docker-run what="bash me/skolan/reset_part2.bash"
pressEnterToContinue
;;
3)
runSqlScript "example/sql/inspect/setup_skolan.sql" "dbwebb"
make docker-run what="bash me/skolan/reset_part3.bash"
pressEnterToContinue
;;
4)
path="me/skolan/skolan.sql"
if [[ -f "$path" ]]; then
runSqlScript "example/sql/inspect/setup_skolan.sql" "dbwebb"
runSqlScript "$path" "dbwebb" "" "skolan"
else
printf "The file '%s' does not exists.\n" "$path"
fi
pressEnterToContinue
;;
b|"")
return
;;
esac
done