forked from informatici/openhospital-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oh.sh
1732 lines (1576 loc) · 53.7 KB
/
oh.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
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
#!/bin/bash
#
# Open Hospital (www.open-hospital.org)
# Copyright © 2006-2024 Informatici Senza Frontiere ([email protected])
#
# Open Hospital is a free and open source software for healthcare data management.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# https://www.gnu.org/licenses/gpl-3.0-standalone.html
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#################### Script info and configuration - Do not edit #####################
# set script DEBUG mode
# saner programming env: these switches turn some bugs into errors
#set -o errexit -o pipefail -o noclobber -o nounset
######## get name of this shell script
SCRIPT_NAME=$(basename "$0")
######################## Script configuration #######################
#
# set WRITE_CONFIG_FILES=on "on" to force generation / overwriting of configuration files:
# data/conf/my.cnf and oh/rsc/*.properties files will be regenerated from the original .dist files
# with the settings defined in this script.
#
# Default is set to "off": configuration files will not be regenerated or overwritten if already present.
#
WRITE_CONFIG_FILES="off"
############## OH general configuration - change at your own risk :-) ##############
# OH_PATH is the directory where Open Hospital files are located
# OH_PATH=/usr/local/OpenHospital/oh
# set OH mode to PORTABLE | CLIENT | SERVER - default set to PORTABLE
#OH_MODE="PORTABLE"
# language setting - default set to en
OH_LANGUAGE_LIST=("ar" "de" "en" "es" "fr" "it" "pt" "sq")
OH_LANGUAGE_LIST_INFO=("Arabic" "German" "English" "Spanish" "French" "Italian" "Portuguese" "Albanian")
# single / multiuser - set "yes" for single user configuration
#OH_SINGLE_USER="no"
# set log level to INFO | DEBUG - default set to INFO
LOG_LEVEL="INFO"
# set DEMO_DATA to on to enable demo database loading - default set to off
# ---> Warning <--- __requires deletion of all portable data__
DEMO_DATA="off"
DEMO_DATABASE="ohdemo"
# set JAVA_BIN
# Uncomment this if you want to use system wide JAVA
#JAVA_BIN=`which java`
##################### Database configuration #######################
DATABASE_SERVER="localhost"
DATABASE_PORT="3306"
DATABASE_ROOT_PW="tmp2021oh111"
DATABASE_NAME="oh"
DATABASE_USER="isf"
DATABASE_PASSWORD="isf123"
####################### OH configuration #########################
# path and directories
OH_DIR="."
OH_DOC_DIR="doc"
CONF_DIR="data/conf"
DATA_DIR="data/db"
PHOTO_DIR="data/photo"
BACKUP_DIR="data/dump"
LOG_DIR="data/log"
SQL_DIR="sql"
SQL_EXTRA_DIR="sql/extra"
TMP_DIR="tmp"
# imaging / dicom
DICOM_MAX_SIZE="4M"
DICOM_STORAGE="FileSystemDicomManager" # SqlDicomManager
DICOM_DIR="data/dicom_storage"
# logging
LOG_FILE="startup.log"
OH_LOG_FILE="openhospital.log"
API_LOG_FILE="api.log"
# SQL creation files
#DB_CREATE_SQL="create_all_en.sql" # default to en
DB_DEMO="create_all_demo.sql"
######################## Other settings ########################
# date format
DATE=`date +%Y-%m-%d_%H-%M-%S`
# downloaded file extension
EXT="tar.gz"
# mysql configuration file
MYSQL_CONF_FILE="my.cnf"
# OH configuration files
OH_SETTINGS="settings.properties"
DATABASE_SETTINGS="database.properties"
EXAMINATION_SETTINGS="examination.properties"
IMAGING_SETTINGS="dicom.properties"
LOG4J_SETTINGS="log4j2-spring.properties"
PRINTER_SETTINGS="txtPrinter.properties"
SMS_SETTINGS="sms.properties"
TELEMETRY_SETTINGS="telemetry.properties"
XMPP_SETTINGS="xmpp.properties"
API_SETTINGS="application.properties"
CRED_SETTINGS="default_credentials.properties"
DEMO_CRED_SETTINGS="default_demo_credentials.properties"
# OH jar bin files
OH_GUI_JAR="OH-gui.jar"
OH_API_JAR="openhospital-api-0.1.0.jar"
# help file
HELP_FILE="OH-readme.txt"
# set default database name
DEFAULT_DATABASE_NAME="$DATABASE_NAME"
# set default data base_dir
DEFAULT_DATADIR="$DATA_DIR"
# default database admin/root user
DATABASE_ROOT_USER="root"
# activate expert mode - set to "on" to enable advanced functions - use at your own risk!
EXPERT_MODE="off"
OH_UI_URL="http://localhost:8080"
OH_API_PID="../tmp/oh-api.pid"
################ Architecture and external software ################
######## MariaDB/MySQL Software
# MariaDB version
MYSQL_VERSION="10.6.16"
MYSQL32_VERSION="10.5.23"
PACKAGE_TYPE="systemd"
######## define system and software architecture
ARCH=`uname -m`
case $ARCH in
x86_64|amd64|AMD64)
JAVA_ARCH=64
MYSQL_ARCH=x86_64
MYSQL_PACKAGE_ARCH=$MYSQL_ARCH
JAVA_PACKAGE_ARCH=x64
;;
i[3456789]86|x86|i86pc)
JAVA_ARCH=32
MYSQL_ARCH=i686
MYSQL_VERSION=$MYSQL32_VERSION;
MYSQL_PACKAGE_ARCH=x86
JAVA_PACKAGE_ARCH=i686
;;
*)
echo "Unknown architecture: $ARCH. Exiting."
exit 1
;;
esac
# set MariaDB download URL / package
MYSQL_URL="https://archive.mariadb.org/mariadb-$MYSQL_VERSION/bintar-linux-$PACKAGE_TYPE-$MYSQL_PACKAGE_ARCH"
MYSQL_DIR="mariadb-$MYSQL_VERSION-linux-$PACKAGE_TYPE-$MYSQL_ARCH"
MYSQL_NAME="MariaDB" # For console output - MariaDB/MYSQL_NAME
######## JAVA Software
######## JAVA 64bit - default architecture
### JRE 11 - openjdk distribution
#JAVA_URL="https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.11%2B9"
#JAVA_DISTRO="OpenJDK11U-jre_x64_linux_hotspot_11.0.11_9"
#JAVA_DIR="jdk-11.0.11+9-jre"
### JRE 17 - zulu distribution
#JAVA_DISTRO="zulu11.68.17-ca-jre11.0.21-linux_$JAVA_PACKAGE_ARCH"
JAVA_DISTRO="zulu17.48.15-ca-jre17.0.10-linux_$JAVA_PACKAGE_ARCH"
JAVA_URL="https://cdn.azul.com/zulu/bin"
JAVA_DIR=$JAVA_DISTRO
######################## DO NOT EDIT BELOW THIS LINE ########################
########################### Functions ###########################
###################################################################
function script_menu {
# show help / user options
echo " -----------------------------------------------------------------"
echo "| |"
echo "| Open Hospital - $OH_VERSION |"
echo "| |"
echo " -----------------------------------------------------------------"
echo " arch $ARCH | lang $OH_LANGUAGE | mode $OH_MODE | log level $LOG_LEVEL | Demo $DEMO_DATA"
echo " -----------------------------------------------------------------"
if [ "$EXPERT_MODE" == "on" ]; then
echo " EXPERT MODE activated"
echo " API server set to $API_SERVER"
echo " -----------------------------------------------------------------"
fi
echo ""
echo " Usage: $SCRIPT_NAME -[OPTION] "
echo ""
echo " -C set OH in CLIENT mode"
echo " -P set OH in PORTABLE mode"
echo " -S set OH in SERVER mode (portable)"
echo " -l set language -> [ ${OH_LANGUAGE_LIST[*]} ]"
echo " -E toggle EXPERT MODE - show advanced options"
echo " -h show help"
echo " -q quit"
echo ""
if [ "$EXPERT_MODE" == "on" ]; then
script_menu_advanced;
fi
}
###################################################################
function script_menu_advanced {
# show help / user options
echo " -------------------------------- "
echo " EXPERT MODE - advanced options"
echo ""
echo " -A toggle API server - EXPERIMENTAL"
echo " -e export/save OH database"
echo " -r restore OH database"
echo " -d toggle log level INFO/DEBUG"
echo " -G setup GSM"
echo " -D initialize OH with Demo data"
echo " -i initialize/install OH database"
echo " -m configure database connection manually"
echo " -s save OH configuration"
echo " -t test database connection (CLIENT mode only)"
echo " -u create Desktop shortcut"
echo " -v show configuration"
echo " -V check for latest OH version"
echo " -X clean/reset OH installation"
echo ""
}
###################################################################
function interactive_menu {
until [[ "$OPTSTRING" != *"$option"* ]]
do
clear;
script_menu;
echo ""
#IFS=
read -n 1 -p "Please select an option or press enter to start OH: " option
if [[ $option != "" ]]; then
parse_user_input $option 1; # interactive
else
break # if enter pressed exit from loop and start OH
fi
done
# OPTIND=1
}
###################################################################
function get_confirmation {
# if arg = 1 go back to interactive menu
read -p "(y/n) ? " choice
case "$choice" in
y|Y ) echo "yes"
;;
n|N ) echo "Exiting.";
if [[ ${#COMMAND_LINE_ARGS} -eq 0 ]] && [[ $1 -eq 1 ]]; then
option="";
interactive_menu;
else
exit 1;
fi
;;
* ) echo "Invalid choice. Press any key to continue.";
read;
if [[ ${#COMMAND_LINE_ARGS} -eq 0 ]] && [[ $1 -eq 1 ]]; then
option="";
interactive_menu;
else
exit 1;
fi
exit 0;
esac
}
###################################################################
function set_path {
# get current directory
CURRENT_DIR=$PWD
# set OH_PATH if not defined
if [ -z ${OH_PATH+x} ]; then
echo "Info: OH_PATH not defined - setting to script path"
# set OH_PATH to script path
OH_PATH=$(dirname "$(realpath "$0")")
if [ ! -f "$OH_PATH/$SCRIPT_NAME" ]; then
echo "Error - $SCRIPT_NAME not found in the current PATH. Please browse to the directory where Open Hospital was unzipped or set up OH_PATH properly."
exit 1
fi
fi
}
###################################################################
function read_settings {
# check and read OH version file
if [ -f ./$OH_DIR/rsc/version.properties ]; then
source "./$OH_DIR/rsc/version.properties"
OH_VERSION=$VER_MAJOR.$VER_MINOR.$VER_RELEASE
else
echo "Error: Open Hospital not found! Exiting."
exit 1;
fi
# check for OH settings file and read values
if [ -f ./$OH_DIR/rsc/$OH_SETTINGS ]; then
echo "Reading OH settings file..."
. ./$OH_DIR/rsc/$OH_SETTINGS
OH_MODE=$MODE
OH_LANGUAGE=$LANGUAGE
OH_SINGLE_USER=$SINGLE_USER
OH_DOC_DIR=$OH_DOC_DIR
DEMO_DATA=$DEMODATA
API_SERVER=$APISERVER
fi
# check for database settings file and read values
if [ -f ./$OH_DIR/rsc/$DATABASE_SETTINGS ]; then
echo "Reading database settings file..."
# source "./$OH_DIR/rsc/$DATABASE_SETTINGS"
DATABASE_SERVER=$(cat $OH_DIR/rsc/$DATABASE_SETTINGS | grep "jdbc.url" | cut -d"/" -f3 | cut -d":" -f1)
DATABASE_PORT=$(cat $OH_DIR/rsc/$DATABASE_SETTINGS | grep "jdbc.url" | cut -d"/" -f3 | cut -d":" -f2)
DATABASE_NAME=$(cat $OH_DIR/rsc/$DATABASE_SETTINGS | grep "jdbc.url" | cut -d"/" -f4)
DATABASE_USER=$(cat $OH_DIR/rsc/$DATABASE_SETTINGS | grep "jdbc.username" | cut -d"=" -f2)
DATABASE_PASSWORD=$(cat $OH_DIR/rsc/$DATABASE_SETTINGS | grep "jdbc.password" | cut -d"=" -f2)
else
echo "Warning: configuration file $DATABASE_SETTINGS not found."
fi
}
###################################################################
function set_defaults {
# set default values for script variables
# config file generation - set default to off
##### if [ -n ${WRITE_CONFIG_FILES+x} ]; then
if [ -z "$WRITE_CONFIG_FILES" ]; then
WRITE_CONFIG_FILES="off"
fi
# OH mode - set default to PORTABLE
if [ -z "$OH_MODE" ]; then
OH_MODE="PORTABLE"
fi
# OH language - set default to en
if [ -z "$OH_LANGUAGE" ]; then
OH_LANGUAGE="en"
fi
# OH DOC DIR - set default to "doc" (../doc for oh)
if [ -z "$OH_DOC_DIR" ]; then
OH_DOC_DIR="doc"
fi
# set database creation script in chosen language
if [ -z "$DB_CREATE_SQL" ]; then
DB_CREATE_SQL="create_all_$OH_LANGUAGE.sql"
fi
# log level - set default to INFO
if [ -z "$LOG_LEVEL" ]; then
LOG_LEVEL="INFO"
fi
# single / multiuser - set "yes" for single user configuration
if [ -z "$OH_SINGLE_USER" ]; then
OH_SINGLE_USER="no"
fi
# demo data - set default to off
if [ -z "$DEMO_DATA" ]; then
DEMO_DATA="off"
fi
# api server - set default to off
if [ -z "$API_SERVER" ]; then
API_SERVER="off"
fi
# UI interface - set default to off
if [ -z "$UI_INTERFACE" ]; then
UI_INTERFACE="off"
fi
# EXPERT_MODE features - set default to off
if [ -z "$EXPERT_MODE" ]; then
EXPERT_MODE="off"
fi
# set escaped path (/ in place of \)
OH_PATH_ESCAPED=$(echo $OH_PATH | sed -e 's/\//\\\//g')
DICOM_DIR_ESCAPED=$(echo $DICOM_DIR | sed -e 's/\//\\\//g')
PHOTO_DIR_ESCAPED=$(echo $PHOTO_DIR | sed -e 's/\//\\\//g')
LOG_DIR_ESCAPED=$(echo $LOG_DIR | sed -e 's/\//\\\//g')
TMP_DIR_ESCAPED=$(echo $TMP_DIR | sed -e 's/\//\\\//g')
}
###################################################################
function set_db_name {
# set DATA_DIR with db name
DATA_DIR=$DEFAULT_DATADIR/$DATABASE_NAME
# set escaped values
DATA_DIR_ESCAPED=$(echo $DATA_DIR | sed -e 's/\//\\\//g')
}
###################################################################
function set_oh_mode {
# if $OH_SETTINGS is present set OH mode
if [ -f ./$OH_DIR/rsc/$OH_SETTINGS ]; then
echo "Configuring OH mode..."
######## $OH_SETTINGS OH mode configuration
echo "Setting OH mode to $OH_MODE in OH configuration file -> $OH_SETTINGS..."
sed -e "/^"MODE="/c"MODE=$OH_MODE"" -i ./$OH_DIR/rsc/$OH_SETTINGS
else
echo ""
echo ""
echo "Warning: $OH_SETTINGS file not found."
fi
echo "OH mode set to $OH_MODE"
}
###################################################################
function set_demo_data {
# set database name for demo data
case "$DEMO_DATA" in
*on*)
DATABASE_NAME=$DEMO_DATABASE
;;
*off*)
DATABASE_NAME="$DEFAULT_DATABASE_NAME"
;;
esac
}
###################################################################
function check_language {
# check for valid language selection
for lang in "${OH_LANGUAGE_LIST[@]}"; do
if [[ $lang == $OH_LANGUAGE ]]; then
echo ""
echo "Language set to $OH_LANGUAGE"
return 0;
fi
done
echo ""
echo "Invalid language option [$OH_LANGUAGE]: setting to default [en]"
OH_LANGUAGE=en
}
###################################################################
function set_language {
# set localized database creation script
DB_CREATE_SQL="create_all_$OH_LANGUAGE.sql"
# if $OH_SETTINGS is present set language
if [ -f ./$OH_DIR/rsc/$OH_SETTINGS ]; then
echo "Configuring OH language..."
######## $OH_SETTINGS language configuration
echo "Setting language to $OH_LANGUAGE in OH configuration file -> $OH_SETTINGS..."
sed -e "/^"LANGUAGE="/c"LANGUAGE=$OH_LANGUAGE"" -i ./$OH_DIR/rsc/$OH_SETTINGS
echo "Language set to $OH_LANGUAGE."
else
echo ""
echo "Warning: $OH_SETTINGS file not found."
fi
}
###################################################################
function set_log_level {
if [ -f ./$OH_DIR/rsc/$LOG4J_SETTINGS ]; then
echo ""
######## $LOG4J_SETTINGS log_level configuration
echo "Setting log level to $LOG_LEVEL in OH configuration file -> $LOG4J_SETTINGS..."
case "$LOG_LEVEL" in
*INFO*)
sed -e "s/DEBUG/$LOG_LEVEL/g" -i ./$OH_DIR/rsc/$LOG4J_SETTINGS
;;
*DEBUG*)
sed -e "s/INFO/$LOG_LEVEL/g" -i ./$OH_DIR/rsc/$LOG4J_SETTINGS
;;
*)
echo "Invalid log level: $LOG_LEVEL. Exiting."
exit 1
;;
esac
echo "Log level set to $LOG_LEVEL"
else
echo ""
echo "Warning: $LOG4J_SETTINGS file not found."
fi
}
###################################################################
function initialize_dir_structure {
# create directory structure
mkdir -p "./$TMP_DIR"
mkdir -p "./$LOG_DIR"
mkdir -p "./$DICOM_DIR"
mkdir -p "./$PHOTO_DIR"
mkdir -p "./$BACKUP_DIR"
}
###################################################################
function create_desktop_shortcut {
echo "Creating/updating OH shortcut on Desktop..."
# Create Desktop application entry
desktop_path=$(xdg-user-dir DESKTOP)
echo "[Desktop Entry]
Type=Application
# The version of the Desktop Entry Specification
Version=1.x
# The name of the application
Name=OpenHospital
# A comment which will be used as a tooltip
Comment=Open Hospital 1.x shortcut
# The path to the folder in which the executable is run
Path=$OH_PATH
# The executable of the application, possibly with arguments
Exec=$OH_PATH/$SCRIPT_NAME -Z
# The icon to display
Icon=$OH_PATH/oh.ico
# Describes whether this application needs to be run in a terminal or not
Terminal=true
# Describes the categories in which this entry should be shown
Categories=Utility;Application;
" > $desktop_path/OpenHospital.desktop
echo "Done!"
}
###################################################################
function java_lib_setup {
# NATIVE LIB setup
case $JAVA_ARCH in
64)
NATIVE_LIB_PATH="$OH_PATH/$OH_DIR/lib/native/Linux/amd64"
;;
32)
NATIVE_LIB_PATH="$OH_PATH/$OH_DIR/lib/native/Linux/i386"
;;
esac
# CLASSPATH setup
# include OH jar file
OH_CLASSPATH="$OH_PATH"/$OH_DIR/bin/$OH_GUI_JAR
# include all needed directories
OH_CLASSPATH=$OH_CLASSPATH:"$OH_PATH"/$OH_DIR/bundle
OH_CLASSPATH=$OH_CLASSPATH:"$OH_PATH"/$OH_DIR/rpt_base
OH_CLASSPATH=$OH_CLASSPATH:"$OH_PATH"/$OH_DIR/rpt_extra
OH_CLASSPATH=$OH_CLASSPATH:"$OH_PATH"/$OH_DIR/rpt_stat
OH_CLASSPATH=$OH_CLASSPATH:"$OH_PATH"/$OH_DIR/rsc
OH_CLASSPATH=$OH_CLASSPATH:"$OH_PATH"/$OH_DIR/rsc/images
# OH_CLASSPATH=$OH_CLASSPATH:"$OH_PATH"/$OH_DIR/rsc/icons # hardcoded
OH_CLASSPATH=$OH_CLASSPATH:"$OH_PATH"/$OH_DIR/lib
# include all jar files under lib/
DIRLIBS="$OH_PATH"/$OH_DIR/lib/*.jar
for i in ${DIRLIBS}
do
OH_CLASSPATH="$i":$OH_CLASSPATH
done
}
###################################################################
function java_check {
# check if JAVA_BIN is already set and it exists
if ( [ -z ${JAVA_BIN+x} ] || [ ! -x "$JAVA_BIN" ] ); then
# set default
echo "Setting default JAVA..."
JAVA_BIN="$OH_PATH/$JAVA_DIR/bin/java"
fi
# if JAVA_BIN is not found download JRE
if [ ! -x "$JAVA_BIN" ]; then
if [ ! -f "./$JAVA_DISTRO.$EXT" ]; then
echo "Warning - JAVA not found. Do you want to download it?"
get_confirmation;
# download java binaries
echo "Download $JAVA_DISTRO..."
wget -P ./ $JAVA_URL/$JAVA_DISTRO.$EXT
fi
echo "Unpacking $JAVA_DISTRO..."
tar xf ./$JAVA_DISTRO.$EXT -C ./
if [ $? -ne 0 ]; then
echo "Error unpacking Java. Exiting."
exit 1
fi
echo "JAVA unpacked successfully!"
echo "Removing downloaded file..."
rm ./$JAVA_DISTRO.$EXT
echo "Done!"
fi
echo "JAVA found!"
echo "Using $JAVA_BIN"
}
###################################################################
function mysql_check {
if [ ! -d "./$MYSQL_DIR" ]; then
if [ ! -f "./$MYSQL_DIR.$EXT" ]; then
echo "Warning - $MYSQL_NAME not found. Do you want to download it?"
get_confirmation;
# download mysql binary
echo "Downloading $MYSQL_DIR..."
wget -P ./ $MYSQL_URL/$MYSQL_DIR.$EXT
fi
echo "Unpacking $MYSQL_DIR..."
tar xf ./$MYSQL_DIR.$EXT -C ./
if [ $? -ne 0 ]; then
echo "Error unpacking $MYSQL_NAME. Exiting."
exit 1
fi
echo "$MYSQL_NAME unpacked successfully!"
echo "Removing downloaded file..."
rm ./$MYSQL_DIR.$EXT
echo "Done!"
fi
# check for mysqld binary
if [ -x ./$MYSQL_DIR/bin/mysqld_safe ]; then
echo "$MYSQL_NAME found!"
echo "Using $MYSQL_DIR"
else
echo "$MYSQL_NAME not found! Exiting."
exit 1
fi
# check for libaio
ldconfig -p | grep libaio > /dev/null;
if [ $? -eq 1 ]; then
echo "Error: libaio not found! Please install the library. Exiting."
exit 1
fi
# check for libncurses - version 5
ldconfig -p | grep libncurses.so.5 > /dev/null;
if [ $? -eq 1 ]; then
echo "Error: libncurses version 5 not found! Please install the library. Exiting."
exit 1
fi
}
###################################################################
function config_database {
echo "Checking for $MYSQL_NAME config file..."
if [ "$WRITE_CONFIG_FILES" = "on" ] || [ ! -f ./$CONF_DIR/$MYSQL_CONF_FILE ]; then
[ -f ./$CONF_DIR/$MYSQL_CONF_FILE ] && mv -f ./$CONF_DIR/$MYSQL_CONF_FILE ./$CONF_DIR/$MYSQL_CONF_FILE.old
# find a free TCP port to run MariaDB/MySQL starting from the default port
echo "Looking for a free TCP port for $MYSQL_NAME database..."
while [[ $(ss -tl4 sport = :$DATABASE_PORT | grep LISTEN) ]]; do
DATABASE_PORT=$(expr $DATABASE_PORT + 1)
done
echo "Found TCP port $DATABASE_PORT!"
echo "Writing $MYSQL_NAME config file..."
sed -e "s/DATABASE_SERVER/$DATABASE_SERVER/g" -e "s/DICOM_SIZE/$DICOM_MAX_SIZE/g" -e "s/OH_PATH_SUBSTITUTE/$OH_PATH_ESCAPED/g" \
-e "s/TMP_DIR/$TMP_DIR_ESCAPED/g" -e "s/DATA_DIR/$DATA_DIR_ESCAPED/g" -e "s/LOG_DIR/$LOG_DIR_ESCAPED/g" \
-e "s/DATABASE_PORT/$DATABASE_PORT/g" -e "s/MYSQL_DISTRO/$MYSQL_DIR/g" ./$CONF_DIR/$MYSQL_CONF_FILE.dist > ./$CONF_DIR/$MYSQL_CONF_FILE
fi
}
###################################################################
function initialize_database {
# create data directory
mkdir -p "./$DATA_DIR"
# initialize MariaDB/MySQL
echo "Initializing $MYSQL_NAME database on port $DATABASE_PORT..."
case "$MYSQL_DIR" in
*mariadb*)
./$MYSQL_DIR/scripts/mysql_install_db --basedir=./$MYSQL_DIR --datadir=./"$DATA_DIR" \
--auth-root-authentication-method=normal >> ./$LOG_DIR/$LOG_FILE 2>&1
;;
*mysql*)
./$MYSQL_DIR/bin/mysqld --initialize-insecure --basedir=./$MYSQL_DIR --datadir=./"$DATA_DIR" >> ./$LOG_DIR/$LOG_FILE 2>&1
;;
esac
if [ $? -ne 0 ]; then
echo "Error: $MYSQL_NAME initialization failed! Exiting."
exit 2
fi
}
###################################################################
function start_database {
echo "Checking if $MYSQL_NAME is running..."
if [ -f "$OH_PATH/$TMP_DIR/mysql.sock" ] || [ -f "$OH_PATH/$TMP_DIR/mysql.pid" ] ; then
echo "$MYSQL_NAME already running ! Exiting."
exit 1
fi
echo "Starting $MYSQL_NAME server... "
./$MYSQL_DIR/bin/mysqld_safe --defaults-file=./$CONF_DIR/$MYSQL_CONF_FILE >> ./$LOG_DIR/$LOG_FILE 2>&1 &
if [ $? -ne 0 ]; then
echo "Error: $MYSQL_NAME server not started! Exiting."
exit 2
fi
# wait till the MariaDB/MySQL tcp port is open
until nc -z $DATABASE_SERVER $DATABASE_PORT; do sleep 1; done
echo "$MYSQL_NAME server started! "
}
###################################################################
function set_database_root_pw {
# if using MySQL/MariaDB root password need to be set
echo "Setting $MYSQL_NAME $DATABASE_ROOT_USER password..."
./$MYSQL_DIR/bin/mysql -u $DATABASE_ROOT_USER --skip-password --host=$DATABASE_SERVER --port=$DATABASE_PORT --protocol=tcp -e "ALTER USER '$DATABASE_ROOT_USER'@'$DATABASE_SERVER' IDENTIFIED BY '$DATABASE_ROOT_PW';" >> ./$LOG_DIR/$LOG_FILE 2>&1
if [ $? -ne 0 ]; then
echo "Error: $MYSQL_NAME root password not set! Try resetting installation with option [X]. Exiting."
shutdown_database;
exit 2
fi
}
###################################################################
function create_database_user {
echo "Creating database user [$DATABASE_USER]..."
# create database user
./$MYSQL_DIR/bin/mysql -u $DATABASE_ROOT_USER -p$DATABASE_ROOT_PW --protocol=tcp --host=$DATABASE_SERVER --port=$DATABASE_PORT \
-e "CREATE USER '$DATABASE_USER'@'$DATABASE_SERVER' IDENTIFIED BY '$DATABASE_PASSWORD'; \
CREATE USER '$DATABASE_USER'@'%' IDENTIFIED BY '$DATABASE_PASSWORD';" >> ./$LOG_DIR/$LOG_FILE 2>&1
if [ $? -ne 0 ]; then
echo "Error: Database user creation failed! Exiting."
shutdown_database;
exit 2
fi
}
###################################################################
function create_database {
echo "Creating database [$DATABASE_NAME]..."
# create OH database
./$MYSQL_DIR/bin/mysql -u $DATABASE_ROOT_USER -p$DATABASE_ROOT_PW --protocol=tcp --host=$DATABASE_SERVER --port=$DATABASE_PORT \
-e "CREATE DATABASE $DATABASE_NAME CHARACTER SET utf8; GRANT ALL PRIVILEGES ON $DATABASE_NAME.* TO '$DATABASE_USER'@'$DATABASE_SERVER'; \
GRANT ALL PRIVILEGES ON $DATABASE_NAME.* TO '$DATABASE_USER'@'%' ; " >> ./$LOG_DIR/$LOG_FILE 2>&1
if [ $? -ne 0 ]; then
echo "Error: Database creation failed! Exiting."
shutdown_database;
exit 2
fi
}
###################################################################
function import_database {
echo "Checking for SQL creation script..."
# check for database creation script
if [ -f ./$SQL_DIR/$DB_CREATE_SQL ]; then
echo "Using SQL file $SQL_DIR/$DB_CREATE_SQL..."
else
echo "Error: No SQL file found! Exiting."
shutdown_database;
exit 2
fi
# create OH database structure
echo "Importing database [$DATABASE_NAME] with user [$DATABASE_USER@$DATABASE_SERVER]..."
cd "./$SQL_DIR"
# ../$MYSQL_DIR/bin/mysql --local-infile=1 -u $DATABASE_ROOT_USER -p$DATABASE_ROOT_PW --host=$DATABASE_SERVER --port=$DATABASE_PORT --protocol=tcp $DATABASE_NAME < ./$DB_CREATE_SQL >> ../$LOG_DIR/$LOG_FILE 2>&1
../$MYSQL_DIR/bin/mysql --local-infile=1 -u $DATABASE_USER -p$DATABASE_PASSWORD --host=$DATABASE_SERVER --port=$DATABASE_PORT --protocol=tcp $DATABASE_NAME < ./$DB_CREATE_SQL >> ../$LOG_DIR/$LOG_FILE 2>&1
if [ $? -ne 0 ]; then
echo "Error: Database not imported! Exiting."
shutdown_database;
cd "$CURRENT_DIR"
exit 2
fi
# EXPERIMENTAL ONLY
# workaround for hard coded password limit - execute extra sql script
# not needed anymore - see OP-1078
# if [ "$API_SERVER" = "on" ]; then
# echo "Setting admin password..."
# cd "$OH_PATH/$SQL_EXTRA_DIR/"
# $OH_PATH/$MYSQL_DIR/bin/mysql --local-infile=1 -u $DATABASE_ROOT_USER -p$DATABASE_ROOT_PW --host=$DATABASE_SERVER --port=$DATABASE_PORT --protocol=tcp $DATABASE_NAME < ./reset_admin_password_strong.sql >> ../../$LOG_DIR/$LOG_FILE 2>&1
# if [ $? -ne 0 ]; then
# echo "Error! Exiting."
# shutdown_database;
# cd "$CURRENT_DIR"
# exit 2
# fi
# fi
# end
cd "$OH_PATH"
}
###################################################################
function dump_database {
# save OH database if existing
if [ -x ./$MYSQL_DIR/bin/mysqldump ]; then
mkdir -p "$OH_PATH/$BACKUP_DIR"
echo "Dumping $MYSQL_NAME database..."
./$MYSQL_DIR/bin/mysqldump --skip-extended-insert -u $DATABASE_USER --password=$DATABASE_PASSWORD --host=$DATABASE_SERVER --port=$DATABASE_PORT --protocol=tcp $DATABASE_NAME > ./$BACKUP_DIR/mysqldump_$DATE.sql
if [ $? -ne 0 ]; then
echo "Error: Database not dumped! Exiting."
cd "$CURRENT_DIR"
shutdown_database;
exit 2
fi
else
echo "Error: No mysqldump utility found! Exiting."
shutdown_database;
cd "$CURRENT_DIR"
exit 2
fi
echo "$MYSQL_NAME dump file $BACKUP_DIR/mysqldump_$DATE.sql completed!"
}
###################################################################
function shutdown_database {
if [ "$OH_MODE" != "CLIENT" ]; then
echo "Shutting down $MYSQL_NAME..."
cd "$OH_PATH"
./$MYSQL_DIR/bin/mysqladmin -u $DATABASE_ROOT_USER -p$DATABASE_ROOT_PW --host=$DATABASE_SERVER --port=$DATABASE_PORT --protocol=tcp shutdown >> ./$LOG_DIR/$LOG_FILE 2>&1
# wait till the MySQL tcp port is closed
until !( nc -z $DATABASE_SERVER $DATABASE_PORT ); do sleep 1; done
echo "$MYSQL_NAME stopped!"
else
exit 1
fi
}
###################################################################
function test_database_connection {
# test if mysql client is available
if [ -x ./$MYSQL_DIR/bin/mysql ]; then
# test connection to the OH MySQL database
echo "Testing database connection..."
DBTEST=$(./$MYSQL_DIR/bin/mysql --user=$DATABASE_USER --password=$DATABASE_PASSWORD --host=$DATABASE_SERVER --port=$DATABASE_PORT --protocol=tcp -e "USE $DATABASE_NAME" >> ./$LOG_DIR/$LOG_FILE 2>&1; echo "$?" )
if [ $DBTEST -eq 0 ];then
echo "Database connection successfully established!"
else
echo "Error: can't connect to database! Exiting."
exit 2
fi
else
echo "Can't test database connection..."
fi
}
###################################################################
function write_api_config_file {
######## application.properties setup - OH API server
if [ "$WRITE_CONFIG_FILES" = "on" ] || [ ! -f ./$OH_DIR/rsc/$API_SETTINGS ]; then
[ -f ./$OH_DIR/rsc/$API_SETTINGS ] && mv -f ./$OH_DIR/rsc/$API_SETTINGS ./$OH_DIR/rsc/$API_SETTINGS.old
# generate OH API token and save to settings file
# JWT_TOKEN_SECRET=`openssl rand -base64 64 | xargs`
JWT_TOKEN_SECRET=`LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 66`
echo "Writing OH API configuration file -> $API_SETTINGS..."
sed -e "s/JWT_TOKEN_SECRET/"$JWT_TOKEN_SECRET"/g" \
-e "s&OH_API_PID&"$OH_API_PID"&g" \
-e "s/API_HOST:API_PORT/localhost:8080/g" \
./$OH_DIR/rsc/$API_SETTINGS.dist > ./$OH_DIR/rsc/$API_SETTINGS
fi
}
###################################################################
function copy_config_file {
# function to copy a single configuration file with backup
# usage: copy_config_file [file_name]
if [ "$WRITE_CONFIG_FILES" = "on" ] || [ ! -f ./$OH_DIR/rsc/$1 ]; then
[ -f ./$OH_DIR/rsc/$1 ] && mv -f ./$OH_DIR/rsc/$1 ./$OH_DIR/rsc/$1.old
echo "Writing OH configuration file -> $1..."
cp ./$OH_DIR/rsc/$1.dist ./$OH_DIR/rsc/$1
fi
}
###################################################################
function write_config_files {
# set up configuration files
echo "Checking for OH configuration files..."
######## IMAGING / DICOM setup
if [ "$WRITE_CONFIG_FILES" = "on" ] || [ ! -f ./$OH_DIR/rsc/$IMAGING_SETTINGS ]; then
[ -f ./$OH_DIR/rsc/$IMAGING_SETTINGS ] && mv -f ./$OH_DIR/rsc/$IMAGING_SETTINGS ./$OH_DIR/rsc/$IMAGING_SETTINGS.old
echo "Writing OH configuration file -> $IMAGING_SETTINGS..."
sed -e "s/DICOM_SIZE/$DICOM_MAX_SIZE/g" -e "s/OH_PATH_SUBSTITUTE/$OH_PATH_ESCAPED/g" \
-e "s/DICOM_STORAGE/$DICOM_STORAGE/g" -e "s/DICOM_DIR/$DICOM_DIR_ESCAPED/g" ./$OH_DIR/rsc/$IMAGING_SETTINGS.dist > ./$OH_DIR/rsc/$IMAGING_SETTINGS
fi
######## LOG4J_SETTINGS setup
if [ "$WRITE_CONFIG_FILES" = "on" ] || [ ! -f ./$OH_DIR/rsc/$LOG4J_SETTINGS ]; then
OH_LOG_DEST="$OH_PATH_ESCAPED/$LOG_DIR/$OH_LOG_FILE"
[ -f ./$OH_DIR/rsc/$LOG4J_SETTINGS ] && mv -f ./$OH_DIR/rsc/$LOG4J_SETTINGS ./$OH_DIR/rsc/$LOG4J_SETTINGS.old
echo "Writing OH configuration file -> $LOG4J_SETTINGS..."
sed -e "s/DBSERVER/$DATABASE_SERVER/g" -e "s/DBPORT/$DATABASE_PORT/" -e "s/DBUSER/$DATABASE_USER/g" -e "s/DBPASS/$DATABASE_PASSWORD/g" \
-e "s/DBNAME/$DATABASE_NAME/g" -e "s/LOG_LEVEL/$LOG_LEVEL/g" -e "s+LOG_DEST+$OH_LOG_DEST+g" \
./$OH_DIR/rsc/$LOG4J_SETTINGS.dist > ./$OH_DIR/rsc/$LOG4J_SETTINGS
fi
######## DATABASE_SETTINGS setup
if [ "$WRITE_CONFIG_FILES" = "on" ] || [ ! -f ./$OH_DIR/rsc/$DATABASE_SETTINGS ]; then
[ -f ./$OH_DIR/rsc/$DATABASE_SETTINGS ] && mv -f ./$OH_DIR/rsc/$DATABASE_SETTINGS ./$OH_DIR/rsc/$DATABASE_SETTINGS.old
echo "Writing OH database configuration file -> $DATABASE_SETTINGS..."
sed -e "s/DBSERVER/$DATABASE_SERVER/g" -e "s/DBPORT/$DATABASE_PORT/g" -e "s/DBNAME/$DATABASE_NAME/g" \
-e "s/DBUSER/$DATABASE_USER/g" -e "s/DBPASS/$DATABASE_PASSWORD/g" \
./$OH_DIR/rsc/$DATABASE_SETTINGS.dist > ./$OH_DIR/rsc/$DATABASE_SETTINGS
fi
######## OH_SETTINGS setup
if [ "$WRITE_CONFIG_FILES" = "on" ] || [ ! -f ./$OH_DIR/rsc/$OH_SETTINGS ]; then
[ -f ./$OH_DIR/rsc/$OH_SETTINGS ] && mv -f ./$OH_DIR/rsc/$OH_SETTINGS ./$OH_DIR/rsc/$OH_SETTINGS.old
echo "Writing OH configuration file -> $OH_SETTINGS..."
sed -e "s/OH_MODE/$OH_MODE/g" -e "s/OH_LANGUAGE/$OH_LANGUAGE/g" -e "s&OH_DOC_DIR&../$OH_DOC_DIR&g" \
-e "s/DEMODATA=off/"DEMODATA=$DEMO_DATA"/g" -e "s/YES_OR_NO/$OH_SINGLE_USER/g" \
-e "s/PHOTO_DIR/$PHOTO_DIR_ESCAPED/g" -e "s/APISERVER=off/"APISERVER=$API_SERVER"/g" \
./$OH_DIR/rsc/$OH_SETTINGS.dist > ./$OH_DIR/rsc/$OH_SETTINGS
fi
######## OH - Other settings setup
copy_config_file $EXAMINATION_SETTINGS;
copy_config_file $PRINTER_SETTINGS;
copy_config_file $SMS_SETTINGS;
copy_config_file $TELEMETRY_SETTINGS;
copy_config_file $XMPP_SETTINGS;
######## DEFAULT_CREDENTIALS_SETTINGS setup
if [ "$OH_MODE" == "PORTABLE" ]; then
copy_config_file $CRED_SETTINGS;
fi
if [ "$DEMO_DATA" = "on" ]; then
cp ./$OH_DIR/rsc/$DEMO_CRED_SETTINGS.dist ./$OH_DIR/rsc/$CRED_SETTINGS
fi
}
###################################################################
function clean_database {
# remove socket and pid file
echo "Removing socket and pid file..."
rm -rf ./$TMP_DIR/*
# remove database files
echo "Removing databases..."
# removing all databases under default data dir (prod / demo)
rm -rf ./$DEFAULT_DATADIR/*
}
###################################################################
function clean_conf_files {
# remove configuration files - leave only .dist files
echo "Removing configuration files..."
rm -f ./$CONF_DIR/$MYSQL_CONF_FILE
rm -f ./$OH_DIR/rsc/$OH_SETTINGS
rm -f ./$OH_DIR/rsc/$OH_SETTINGS.old
rm -f ./$OH_DIR/rsc/$DATABASE_SETTINGS
rm -f ./$OH_DIR/rsc/$DATABASE_SETTINGS.old
rm -f ./$OH_DIR/rsc/$EXAMINATION_SETTINGS
rm -f ./$OH_DIR/rsc/$EXAMINATION_SETTINGS.old
rm -f ./$OH_DIR/rsc/$IMAGING_SETTINGS
rm -f ./$OH_DIR/rsc/$IMAGING_SETTINGS.old
rm -f ./$OH_DIR/rsc/$LOG4J_SETTINGS
rm -f ./$OH_DIR/rsc/$LOG4J_SETTINGS.old
rm -f ./$OH_DIR/rsc/$PRINTER_SETTINGS
rm -f ./$OH_DIR/rsc/$PRINTER_SETTINGS.old
rm -f ./$OH_DIR/rsc/$SMS_SETTINGS
rm -f ./$OH_DIR/rsc/$SMS_SETTINGS.old
rm -f ./$OH_DIR/rsc/$TELEMETRY_SETTINGS
rm -f ./$OH_DIR/rsc/$TELEMETRY_SETTINGS.old
rm -f ./$OH_DIR/rsc/$XMPP_SETTINGS
rm -f ./$OH_DIR/rsc/$XMPP_SETTINGS.old
rm -f ./$OH_DIR/rsc/$API_SETTINGS
rm -f ./$OH_DIR/rsc/$API_SETTINGS.old
rm -f ./$OH_DIR/rsc/$CRED_SETTINGS
rm -f ./$OH_DIR/rsc/$CRED_SETTINGS.old
}
###################################################################
function clean_log_files {
# remove all log files
echo "Removing log files..."
rm -f ./$LOG_DIR/*
}
###################################################################
function start_gui {
echo "Starting Open Hospital GUI..."