-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
demo_build.sh
965 lines (896 loc) · 35 KB
/
demo_build.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
#!/bin/sh
# Copyright (C) 2014 Brady Miller <[email protected]>
#
#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 2 of the License, or
#(at your option) any later version.
#
#This script is for the OpenEMR demo farms
#
getRandomThemeOne () {
THEME[0]='style_ash_blue.css'
THEME[1]='style_burgundy.css'
THEME[2]='style_cadmium_yellow.css'
THEME[3]='style_chocolate.css'
THEME[4]='style_cobalt_blue.css'
THEME[5]='style_coral.css'
THEME[6]='style_deep_purple.css'
THEME[7]='style_dune.css'
THEME[8]='style_emerald.css'
THEME[9]='style_forest_green.css'
THEME[10]='style_mauve.css'
THEME[11]='style_mustard_green.css'
THEME[12]='style_olive.css'
THEME[13]='style_pink.css'
THEME[14]='style_powder_blue.css'
THEME[15]='style_red.css'
THEME[16]='style_sienna.css'
THEME[17]='style_tangerine.css'
THEME[18]='style_light.css'
THEME[19]='style_light.css'
THEME[20]='style_light.css'
THEME[21]='style_light.css'
THEME[22]='style_light.css'
THEME[23]='style_light.css'
THEME[24]='style_light.css'
THEME[25]='style_light.css'
THEME[26]='style_light.css'
THEME[27]='style_light.css'
THEME[28]='style_light.css'
THEME[29]='style_light.css'
THEME[30]='style_light.css'
THEME[31]='style_light.css'
THEME[32]='style_light.css'
THEME[33]='style_light.css'
THEME[34]='style_light.css'
THEME[35]='style_light.css'
#choose randomly from 36 choices (0-35)
RANDOM_THEME_INT=$((RANDOM % 36))
echo ${THEME[${RANDOM_THEME_INT}]}
}
getRandomThemeTwo () {
THEME[0]='style_cobalt_blue.css'
THEME[1]='style_forest_green.css'
THEME[2]='style_light.css'
THEME[3]='style_dark.css'
THEME[4]='style_solar.css'
THEME[5]='style_manila.css'
#choose randomly from 6 choices (0-5)
RANDOM_THEME_INT=$((RANDOM % 6))
echo ${THEME[${RANDOM_THEME_INT}]}
}
#function to collect variables from config files
# 1st param is variable name, 2nd param is filename
collect_var () {
echo `grep -i "^[[:space:]]*$1[[:space:]=]" $2 | cut -d \= -f 2 | cut -d \; -f 1 | sed "s/[ '\"]//gi"`
}
# If there is a parameter, then just pursue a light reset of the subdemo
if [ -z "$1" ]; then
lightReset=false;
else
lightReset=true;
lightResetDemo=$1
fi
# PUBLIC REPOS (note the openemr repo is mapped in GITDEMOFARMMAP)
TRANSLATIONSREPO=https://github.com/openemr/translations_development_openemr.git
# PATH VARIABLES AND CREATED NEEDED DIRS
if [ -d /var/www/localhost/htdocs ]; then
WEB=/var/www/localhost/htdocs
alpineOs=true;
htmlDirApache=false;
elif [ -d /var/www/html ]; then
WEB=/var/www/html
htmlDirApache=true;
alpineOs=false;
else
WEB=/var/www
htmlDirApache=false;
alpineOs=false;
fi
LOG=$WEB/log/logSetup.txt
mkdir -p $WEB/log
CAPSULES=/home/openemr/capsules
GITMAIN=/home/openemr/git
GITDEMOFARM=$GITMAIN/demo_farm_openemr
GITDEMOFARMMAP=$GITDEMOFARM/ip_map_branch.txt
PASSWORDRESETSCRIPT=$GITDEMOFARM/set_pass.php
if $htmlDirApache ; then
OPENEMRAPACHECONF=$GITDEMOFARM/openemr-html.conf
else
if $alpineOs; then
OPENEMRAPACHECONF=$GITDEMOFARM/openemr-alpine.conf
else
OPENEMRAPACHECONF=$GITDEMOFARM/openemr.conf
fi
fi
GITTRANS=$GITMAIN/translations_development_openemr
TRANSSERVEDIR=$WEB/translations
TMPDIR=/tmp/openemr-tmp
# WORDPRESS PATIENT PORTAL VARIABLES
GITDEMOWORDPRESSDEMOWEB=$GITDEMOFARM/wordpress_demo/web/wordpress
GITDEMOWORDPRESSDEMOSQLONE=$GITDEMOFARM/pieces/portal_onsite_and_wordpress.sql
GITDEMOWORDPRESSDEMOSQLONETEMP=$GITDEMOFARM/pieces/portal_onsite_and_wordpress_temp.sql
GITDEMOWORDPRESSDEMOSQLTWO=$GITDEMOFARM/wordpress_demo/database/wordpress.sql
GITDEMOWORDPRESSDEMOSQLTWOTEMP=$GITDEMOFARM/wordpress_demo/database/wordpress_temp.sql
if $lightReset; then
echo "This is a light reset"
echo "This is a light reset" >> $LOG
fi
# Turn off apache to avoid users messing up while setting up
# (start it again below after complete setup)
# (note that in alpine it is not on, so don't need to stop)
# (also note don't do this for a light subdemo reset)
if ! $lightReset; then
if ! $alpineOs; then
/etc/init.d/apache2 stop
fi
fi
# Record start time
timeStart=`date -u`
echo -n "Started Build: "
echo "$timeStart"
echo -n "Started Build: " >> $LOG
echo "$timeStart" >> $LOG
if $lightReset; then
demosGo=("$lightResetDemo")
echo -n "subdemo reset mode for: "
echo "$lightResetDemo"
echo -n "subdemo reset mode for: " >> $LOG
echo "$lightResetDemo"
elif [ "$DOCKERNUMBERDEMOS" == "10" ]; then
demosGo=("empty" "a" "b" "c" "d" "e" "f" "g" "h" "i")
echo "10 demos mode"
echo "10 demos mode" >> $LOG
elif [ "$DOCKERNUMBERDEMOS" == "9" ]; then
demosGo=("empty" "a" "b" "c" "d" "e" "f" "g" "h")
echo "9 demos mode"
echo "9 demos mode" >> $LOG
elif [ "$DOCKERNUMBERDEMOS" == "8" ]; then
demosGo=("empty" "a" "b" "c" "d" "e" "f" "g")
echo "8 demos mode"
echo "8 demos mode" >> $LOG
elif [ "$DOCKERNUMBERDEMOS" == "7" ]; then
demosGo=("empty" "a" "b" "c" "d" "e" "f")
echo "7 demos mode"
echo "7 demos mode" >> $LOG
elif [ "$DOCKERNUMBERDEMOS" == "6" ]; then
demosGo=("empty" "a" "b" "c" "d" "e")
echo "6 demos mode"
echo "6 demos mode" >> $LOG
elif [ "$DOCKERNUMBERDEMOS" == "5" ]; then
demosGo=("empty" "a" "b" "c" "d")
echo "5 demos mode"
echo "5 demos mode" >> $LOG
elif [ "$DOCKERNUMBERDEMOS" == "4" ]; then
demosGo=("empty" "a" "b" "c")
echo "4 demos mode"
echo "4 demos mode" >> $LOG
elif [ "$DOCKERNUMBERDEMOS" == "3" ]; then
demosGo=("empty" "a" "b")
echo "3 demos mode"
echo "3 demos mode" >> $LOG
elif [ "$DOCKERNUMBERDEMOS" == "2" ]; then
demosGo=("empty" "a")
echo "2 demos mode"
echo "2 demos mode" >> $LOG
else
demosGo=("empty")
echo "Single demo mode"
echo "Single demo mode" >> $LOG
fi
if [ -n "$DOCKERDEMO" ] ; then
DOCKERDEMOORIGINAL=$DOCKERDEMO
fi
for demo in ${demosGo[*]}
do
if [ "$demo" == "empty" ]; then
OPENEMR=$WEB/openemr
WORDPRESS=$WEB/wordpress
FILESSERVEDIR=$WEB/files
if [ -n "$DOCKERDEMO" ] ; then
DOCKERDEMO=$DOCKERDEMOORIGINAL
fi
FINALWEB=$WEB
else
DOCKERDEMO=${DOCKERDEMOORIGINAL}_${demo}
OPENEMR=${WEB}/${demo}/openemr
WORDPRESS=${WEB}/${demo}/wordpress
FILESSERVEDIR=$WEB/${demo}/files
FINALWEB=$WEB/${demo}
fi
# Collect ip address or docker demo number
if [ -n "$DOCKERDEMO" ] ; then
echo -n "Docker Demo is "
echo "$DOCKERDEMO"
echo -n "Docker Demo is " >> $LOG
echo "$DOCKERDEMO" >> $LOG
IPADDRESS=$DOCKERDEMO
else
tempx=`/sbin/ifconfig`
tempy=${tempx#*inet addr:}
IPADDRESS=${tempy%% *}
echo -n "IP ADDRESS is "
echo "$IPADDRESS"
echo -n "IP ADDRESS is " >> $LOG
echo "$IPADDRESS" >> $LOG
fi
# COLLECT MAPPED BRANCH AND OPTIONS
# Grab repo link
OPENEMRREPO=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 2`
echo -n "git repo is "
echo "$OPENEMRREPO"
echo -n "git repo is " >> $LOG
echo "$OPENEMRREPO" >> $LOG
# Parse out the repo name and set the $GIT variable
OPENEMRREPOFULLNAME=$(basename "$OPENEMRREPO")
echo -n "git repo full name is "
echo "$OPENEMRREPOFULLNAME"
echo -n "git repo full name is " >> $LOG
echo "$OPENEMRREPOFULLNAME" >> $LOG
OPENEMRREPONAME="${OPENEMRREPOFULLNAME%.*}"
echo -n "git repo name is "
echo "$OPENEMRREPONAME"
echo -n "git repo name is " >> $LOG
echo "$OPENEMRREPONAME" >> $LOG
GIT=$GITMAIN/$OPENEMRREPONAME
echo -n "git repo local path is "
echo "$GIT"
echo -n "git repo local path is " >> $LOG
echo "$GIT" >> $LOG
# Grab branch
GITBRANCH=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 3`
echo -n "git branch is "
echo "$GITBRANCH"
echo -n "git branch is " >> $LOG
echo "$GITBRANCH" >> $LOG
# Grab serve development translation set option
sdt=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 4`
echo -n "sdt option is "
echo "$sdt"
echo -n "sdt option is " >> $LOG
echo "$sdt" >> $LOG
# Grab use development translation set option
udt=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 5`
echo -n "udt option is "
echo "$udt"
echo -n "udt option is " >> $LOG
echo "$udt" >> $LOG
# Grab serve packages option
sp=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 6`
echo -n "sp option is "
echo "$sp"
echo -n "sp option is " >> $LOG
echo "$sp" >> $LOG
# Grab legacy patching option
lp=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 7`
echo -n "lp option is "
echo "$lp"
echo -n "lp option is " >> $LOG
echo "$lp" >> $LOG
# Grab demo data option
dd=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 8`
echo -n "dd option is "
echo "$dd"
echo -n "dd option is " >> $LOG
echo "$dd" >> $LOG
# Grab demo ssh option
ds=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 9`
echo -n "ds option is "
echo "$ds"
echo -n "ds option is " >> $LOG
echo "$ds" >> $LOG
wp=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 10`
echo -n "wp option is "
echo "$wp"
echo -n "wp option is " >> $LOG
echo "$wp" >> $LOG
EXTERNALLINK=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 11`
echo -n "external link is "
echo "$EXTERNALLINK"
echo -n "external link is " >> $LOG
echo "$EXTERNALLINK" >> $LOG
mrp=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 12`
echo -n "mysql p is "
echo "$mrp"
echo -n "mysql p is " >> $LOG
echo "$mrp" >> $LOG
branchOrTag=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 13`
echo -n "github repo branch/tag is "
echo "$branchOrTag"
echo -n "github repo branch/tag is " >> $LOG
echo "$branchOrTag" >> $LOG
ddu=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 14`
echo -n "ddu option is "
echo "$ddu"
echo -n "ddu option is " >> $LOG
echo "$ddu" >> $LOG
funStuff=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 15`
echo -n "funStuff option is "
echo "$funStuff"
echo -n "funStuff option is " >> $LOG
echo "$funStuff" >> $LOG
passReset=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 16`
echo -n "passReset option is "
echo "$passReset"
echo -n "passReset option is " >> $LOG
echo "$passReset" >> $LOG
useCapsule=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 17`
echo -n "useCapsule option is "
echo "$useCapsule"
echo -n "useCapsule option is " >> $LOG
echo "$useCapsule" >> $LOG
# SET OPTIONS
# set if serve development translation set
if [ "$sdt" == "1" ]; then
translationServe=true;
else
translationServe=false;
fi
# set if use development translation set
if [ "$udt" == "1" ]; then
translationsDevelopment=true;
else
translationsDevelopment=false;
fi
# set if serve packages
if [ "$sp" == "1" ]; then
packageServe=true;
else
packageServe=false;
fi
# set if legacy patching
if [ "$lp" == "1" ]; then
legacyPatch=true;
else
legacyPatch=false;
fi
# set if using demo sample data
if [ "$dd" == "0" ]; then
demoData=false;
else
demoData=true;
fi
# set if using ssh offsite portal connection
if [ "$ds" == "0" ]; then
demoSSH=false;
else
demoSSH=true;
fi
# set if setting up onsite and wordpress patient portals
if [ "$wp" == "0" ]; then
portalsDemo=false;
else
portalsDemo=true;
fi
# set the mysql r pass string if needed
if [ -z "$mrp" ]; then
rpassparam=
else
rpassparam="-p$mrp"
fi
# set if doing a demo data upgrade (specific feature to support demo data on most recent codebase)
if [ "$ddu" == "0" ]; then
demoDataUpgrade=false;
else
demoDataUpgrade=true;
demoDataUpgradeFrom="$ddu"
fi
# set if doing fun stuff (now 1 will support random theme)
if [ "$funStuff" == "0" ]; then
randomTheme=false;
else
randomTheme=true;
fi
# set if doing password reset
# (if 1, then will reset just admin, if 2, then will reset all the official demo users)
if [ "$passReset" == "0" ]; then
passResetAuto=false;
else
passResetAuto=true;
fi
# set if using a capsule
if [ "$useCapsule" == "0" ]; then
useCapsuleBoolean=false;
else
useCapsuleBoolean=true;
useCapsuleFile="$useCapsule"
fi
# COLLECT and output demo description
desc=`cat $GITDEMOFARMMAP | grep "$IPADDRESS" | tr -d '\n' | cut -f 18`
echo -n "Demo description: "
echo "$desc"
echo -n "Demo description: " >> $LOG
echo "$desc" >> $LOG
# COLLECT THE GIT REPO (it should not exist yet, but will check)
if ! [ -d $GIT ]; then
echo "Downloading the OpenEMR git repository"
echo "Downloading the OpenEMR git repository" >> $LOG
mkdir -p $GITMAIN
cd $GITMAIN
if [ "$branchOrTag" != "tag" ]; then
# using a branch, so can do less expensive clone
git clone $OPENEMRREPO --branch $GITBRANCH --depth 1
else
# using a tag, so need to do more expensive full clone
git clone $OPENEMRREPO
cd $GIT
git checkout $GITBRANCH
cd $GITMAIN
fi
if $translationServe ; then
# download the translations git repo and place the set sql file for serving
echo "Placing OpenEMR Development translation set"
echo "Placing OpenEMR Development translation set" >> $LOG
git clone $TRANSLATIONSREPO
mkdir -p $TRANSSERVEDIR
cp $GITTRANS/languageTranslations_utf8.sql $TRANSSERVEDIR/
echo "Done Placing OpenEMR Development translation set"
echo "Done Placing OpenEMR Development translation set" >> $LOG
fi
else
echo "ERROR, The OpenEMR git repository already exist"
echo "ERROR, The OpenEMR git repository already exist" >> $LOG
fi
# COPY THE GIT REPO OPENEMR COPY TO THE WEB DIRECTOY
echo "Copy git OpenEMR to web directory"
echo "Copy git OpenEMR to web directory" >> $LOG
mkdir -p $OPENEMR
rm -fr $OPENEMR/*
rsync --recursive --exclude .git $GIT/* $OPENEMR/
if ! $packageServe; then
rm -fr $GIT
fi
#INSTALL AND CONFIGURE OPENEMR
echo "Configuring OpenEMR"
echo "Configuring OpenEMR" >> $LOG
#
# Set file and directory permissions
chmod 666 $OPENEMR/sites/default/sqlconf.php
if $alpineOs; then
chmod -R a+w $OPENEMR/sites/default/documents
chmod -R a+w $OPENEMR/sites/default/edi
chmod -R a+w $OPENEMR/sites/default/era
chmod -R a+w $OPENEMR/library/freeb
chmod -R a+w $OPENEMR/sites/default/letter_templates
chmod -R a+w $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/cache
chmod -R a+w $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/compiled
chmod -R a+w $OPENEMR/gacl/admin/templates_c
else
chown -R www-data:www-data $OPENEMR/sites/default/documents
chown -R www-data:www-data $OPENEMR/sites/default/edi
chown -R www-data:www-data $OPENEMR/sites/default/era
chown -R www-data:www-data $OPENEMR/library/freeb
chown -R www-data:www-data $OPENEMR/sites/default/letter_templates
chown -R www-data:www-data $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/cache
chown -R www-data:www-data $OPENEMR/interface/main/calendar/modules/PostCalendar/pntemplates/compiled
chown -R www-data:www-data $OPENEMR/gacl/admin/templates_c
fi
if [ -f $OPENEMR/interface/modules/zend_modules/config/application.config.php ] ; then
# This is specifically for Zend code that is currently under development, so it works on the demos.
if $alpineOs; then
chmod a+w $OPENEMR/interface/modules/zend_modules/config/application.config.php
else
chown www-data:www-data $OPENEMR/interface/modules/zend_modules/config/application.config.php
fi
echo "Configuring Zend file permission: application.config.php"
echo "Configuring Zend file permission: application.config.php" >> $LOG
fi
#Build openemr package
if [ ! -d $OPENEMR/vendor ]; then
cd $OPENEMR
# install php dependencies
GITHUB_KEY_COMPOSER=`cat /home/openemr/github-key`
githubTokenRateLimitRequest=`curl -H "Authorization: token $GITHUB_KEY_COMPOSER" https://api.github.com/rate_limit`
githubTokenRateLimit=`echo $githubTokenRateLimitRequest | jq '.rate.remaining'`
echo "Number of github api requests remaining is $githubTokenRateLimit"
echo "Number of github api requests remaining is $githubTokenRateLimit" >> $LOG
if [ "$githubTokenRateLimit" -gt 1000 ]; then
echo "Using composer github api token"
echo "Using composer github api token" >> $LOG
composer config --global --auth github-oauth.github.com $GITHUB_KEY_COMPOSER
else
echo "Not using composer github api token"
echo "Not using composer github api token" >> $LOG
fi
composer install --no-dev &>> $LOG
if [ -f $OPENEMR/package.json ]; then
# install frontend dependencies (need unsafe-perm to run as root)
npm install --unsafe-perm &>> $LOG
# build css
npm run build &>> $LOG
fi
if [ -f $OPENEMR/ccdaservice/package.json ]; then
# install ccdaservice dependencies (need unsafe-perm to run as root)
cd $OPENEMR/ccdaservice
npm install --unsafe-perm &>> $LOG
cd $OPENEMR
fi
# clean up
composer global require phing/phing &>> $LOG
/root/.composer/vendor/bin/phing vendor-clean &>> $LOG
/root/.composer/vendor/bin/phing assets-clean &>> $LOG
composer global remove phing/phing &>> $LOG
# optimize
composer dump-autoload -o &>> $LOG
fi
#
# Run installer class for the demo (note to avoid malicious use, script is activated by removing an exit command,
# and the active script is then removed after completion.
INST=$OPENEMR/contrib/util/installScripts/InstallerAuto.php
INSTTEMP=$OPENEMR/contrib/util/installScripts/InstallerAutoTemp.php
sed -e 's@^exit;@ @' <$INST >$INSTTEMP
if [ -n "$DOCKERDEMO" ]; then
DOCKERPARAMETERS="server=${DOCKERMYSQLHOST} loginhost=% login=${DOCKERDEMO} pass=${DOCKERDEMO} dbname=${DOCKERDEMO}"
fi
if $translationsDevelopment ; then
echo "Using online development translation set"
echo "Using online development translation set" >> $LOG
if [ -z "$mrp" ] ; then
php -f $INSTTEMP development_translations=yes $DOCKERPARAMETERS >> $LOG
else
php -f $INSTTEMP development_translations=yes rootpass=$mrp $DOCKERPARAMETERS >> $LOG
fi
else
echo "Using included translation set"
echo "Using included translation set" >> $LOG
if [ -z "$mrp" ] ; then
php -f $INSTTEMP $DOCKERPARAMETERS >> $LOG
else
php -f $INSTTEMP rootpass=$mrp $DOCKERPARAMETERS >> $LOG
fi
fi
rm -f $INSTTEMP
if $legacyPatch; then
#Run the patching script to bring in database changes for script via
# legacy method. (patch branches rel-412 and higher do not need to
# do this)
echo "Upgrading via legacy patch"
echo "Upgrading via legacy patch" >> $LOG
echo "<?php \$_GET['site'] = 'default'; ?>" > $OPENEMR/TEMPsql_patch.php
cat $OPENEMR/sql_patch.php >> $OPENEMR/TEMPsql_patch.php
php -f $OPENEMR/TEMPsql_patch.php >> $LOG
rm -f $OPENEMR/TEMPsql_patch.php
echo "Completed upgrading via legacy patch"
echo "Completed upgrading via legacy patch" >> $LOG
fi
if $demoData; then
# Need to insert the demo data, which is in $dd item in the pieces directory
echo "Inserting demo data from $dd"
echo "Inserting demo data from $dd" >> $LOG
# First, check to ensure the file exists
if [ -f "$GITDEMOFARM/pieces/$dd" ]; then
# Now insert the data
# -Note need to first clear the current database (can make this an option in future if need to add data without clearing database)
if [ -n "$DOCKERDEMO" ] ; then
mysqldump -h $DOCKERMYSQLHOST -u root $rpassparam --add-drop-table --no-data $DOCKERDEMO | grep ^DROP | awk ' BEGIN { print "SET FOREIGN_KEY_CHECKS=0;" } { print $0 } END { print "SET FOREIGN_KEY_CHECKS=1;" } ' | mysql -h $DOCKERMYSQLHOST -u root $rpassparam $DOCKERDEMO
mysql -h $DOCKERMYSQLHOST -u root $rpassparam $DOCKERDEMO < "$GITDEMOFARM/pieces/$dd"
else
mysqldump -u root $rpassparam --add-drop-table --no-data openemr | grep ^DROP | mysql -u root $rpassparam openemr
mysql -u root $rpassparam openemr < "$GITDEMOFARM/pieces/$dd"
fi
echo "Completed inserting demo data from $dd"
echo "Completed inserting demo data from $dd" >> $LOG
else
echo "Error, $dd data does not exist"
echo "Error, $dd data does not exist" >> $LOG
fi
if $demoDataUpgrade; then
# Run the sql upgrade script. This allows using demo data on most recent codebase.
echo "Upgrading demo data from $demoDataUpgradeFrom"
echo "Upgrading demo data from $demoDataUpgradeFrom" >> $LOG
sed -e "s@!empty(\$_POST\['form_submit'\])@true@" <$OPENEMR/sql_upgrade.php >$OPENEMR/sql_upgrade_temp.php
sed -i "s@\$form_old_version = \$_POST\['form_old_version'\];@\$form_old_version = '${demoDataUpgradeFrom}';@" $OPENEMR/sql_upgrade_temp.php
sed -i "1s@^@<?php \$_GET['site'] = 'default'; ?>@" $OPENEMR/sql_upgrade_temp.php
php -f $OPENEMR/sql_upgrade_temp.php >> $LOG
rm -f $OPENEMR/sql_upgrade_temp.php
# Also need to change encoding/collation when using OpenEMR versions at 6 or greater
VERSION_MAJOR=$(collect_var \$v_major $OPENEMR/version.php)
if [ -n "$VERSION_MAJOR" ] && [ "$VERSION_MAJOR" -ge "6" ]; then
echo "Upgrading database/collation to utf8mbf since using version ${VERSION_MAJOR}"
echo "Upgrading database/collation to utf8mbf since using version ${VERSION_MAJOR}" >> $LOG
mysql -h $DOCKERMYSQLHOST -u root $rpassparam -e 'SELECT concat("ALTER DATABASE `",TABLE_SCHEMA,"` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;") as _sql FROM `information_schema`.`TABLES` where `TABLE_SCHEMA` like "'"${DOCKERDEMO}"'" and `TABLE_TYPE`="BASE TABLE" group by `TABLE_SCHEMA`;' | egrep '^ALTER' | mysql -h $DOCKERMYSQLHOST -u root $rpassparam
mysql -h $DOCKERMYSQLHOST -u root $rpassparam -e 'SELECT concat("ALTER TABLE `",TABLE_SCHEMA,"`.`",TABLE_NAME,"` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") as _sql FROM `information_schema`.`TABLES` where `TABLE_SCHEMA` like "'"${DOCKERDEMO}"'" and `TABLE_TYPE`="BASE TABLE" group by `TABLE_SCHEMA`, `TABLE_NAME`;' | egrep '^ALTER' | mysql -h $DOCKERMYSQLHOST -u root $rpassparam
fi
fi
if $translationsDevelopment ; then
# Need to bring the development translations back in (only can support this in docker mode)
if [ -n "$DOCKERDEMO" ] ; then
echo "TODO: Need to support bringing in the translations here in the future"
echo "TODO: Need to support bringing in the translations here in the future" >> $LOG
# below is way to slow; need to figure out how to get the innodb optimizations in here (as do in main codebase inserts)
# plan to make a temp file in /home/openemr/temp/languageTranslations_utf8_temp.sql and modify it for the innodb optimizations
# mysql -h $DOCKERMYSQLHOST -u root $rpassparam $DOCKERDEMO < /home/openemr/git/translations_development_openemr/languageTranslations_utf8.sql
fi
fi
fi
if $useCapsuleBoolean; then
# load the capsule
echo "Load $useCapsuleFile capsule"
echo "Load $useCapsuleFile capsule" >> $LOG
# First, check to ensure the capsule exists
if [ -f "$CAPSULES/${useCapsuleFile}.tgz" ]; then
# ensure unpackaged directory is cleared prior to using
rm -fr "$OPENEMR/${useCapsuleFile}"
cp "$CAPSULES/${useCapsuleFile}.tgz" "$OPENEMR/"
tar -xzf "${useCapsuleFile}.tgz"
# Note need to first clear the current database
mysqldump -h $DOCKERMYSQLHOST -u root $rpassparam --add-drop-table --no-data $DOCKERDEMO | grep ^DROP | awk ' BEGIN { print "SET FOREIGN_KEY_CHECKS=0;" } { print $0 } END { print "SET FOREIGN_KEY_CHECKS=1;" } ' | mysql -h $DOCKERMYSQLHOST -u root $rpassparam $DOCKERDEMO
mysql -h $DOCKERMYSQLHOST -u root $rpassparam $DOCKERDEMO < "$OPENEMR/${useCapsuleFile}/backup.sql"
cp "$OPENEMR/sites/default/sqlconf.php" "$OPENEMR/"
rsync --delete --recursive --links "$OPENEMR/${useCapsuleFile}/sites" "$OPENEMR/"
cp "$OPENEMR/sqlconf.php" "$OPENEMR/sites/default/sqlconf.php"
rm "$OPENEMR/sqlconf.php"
if $alpineOs; then
chmod -R a+w $OPENEMR/sites/default/documents
if [ -f "$OPENEMR/sites/default/documents/certificates/oaprivate.key" ]; then
# this file needs special treatment in the alpine demo dockers to work correctly
chmod 640 "$OPENEMR/sites/default/documents/certificates/oaprivate.key"
chown apache:apache "$OPENEMR/sites/default/documents/certificates/oaprivate.key"
fi
if [ -f "$OPENEMR/sites/default/documents/certificates/oapublic.key" ]; then
# this file needs special treatment in the alpine demo dockers to work correctly
chmod 660 "$OPENEMR/sites/default/documents/certificates/oapublic.key"
chown apache:apache "$OPENEMR/sites/default/documents/certificates/oapublic.key"
fi
else
chown -R www-data:www-data $OPENEMR/sites/default/documents
fi
# clear unpackaged directory
rm -fr "$OPENEMR/${useCapsuleFile}"
if $demoDataUpgrade; then
# Run the sql upgrade script. This allows using capsule on most recent codebase.
echo "Upgrading capsule from $demoDataUpgradeFrom"
echo "Upgrading capsule from $demoDataUpgradeFrom" >> $LOG
sed -e "s@!empty(\$_POST\['form_submit'\])@true@" <$OPENEMR/sql_upgrade.php >$OPENEMR/sql_upgrade_temp.php
sed -i "s@\$form_old_version = \$_POST\['form_old_version'\];@\$form_old_version = '${demoDataUpgradeFrom}';@" $OPENEMR/sql_upgrade_temp.php
sed -i "1s@^@<?php \$_GET['site'] = 'default'; ?>@" $OPENEMR/sql_upgrade_temp.php
php -f $OPENEMR/sql_upgrade_temp.php >> $LOG
rm -f $OPENEMR/sql_upgrade_temp.php
fi
else
echo "ERROR: $useCapsuleFile capsule did not exist, so could not use"
echo "ERROR: $useCapsuleFile capsule did not exist, so could not use" >> $LOG
fi
fi
#set up external link in global
EXTERNALLINKBASE=$(echo "$EXTERNALLINK" | cut -d '/' -f 1)
if [ -n "$DOCKERDEMO" ] ; then
mysql -h $DOCKERMYSQLHOST -u root $rpassparam -e "UPDATE ${DOCKERDEMO}.globals SET gl_value='https://${EXTERNALLINKBASE}' WHERE gl_name='site_addr_oath'"
else
mysql -u root $rpassparam -e "UPDATE openemr.globals SET gl_value='https://${EXTERNALLINKBASE}' WHERE gl_name='site_addr_oath'"
fi
#random theme generator
if $randomTheme; then
#collect the random theme
if [ "$funStuff" == "2" ]; then
RANDOM_THEME=`getRandomThemeTwo`
else # "$funStuff" == "1"
RANDOM_THEME=`getRandomThemeOne`
fi
echo -n "random theme is "
echo "$RANDOM_THEME"
echo -n "random theme is " >> $LOG
echo "$RANDOM_THEME" >> $LOG
#set the random theme
if [ -n "$DOCKERDEMO" ] ; then
mysql -h $DOCKERMYSQLHOST -u root $rpassparam -e "UPDATE ${DOCKERDEMO}.globals SET gl_value='${RANDOM_THEME}' WHERE gl_name='css_header'"
else
mysql -u root $rpassparam -e "UPDATE openemr.globals SET gl_value='${RANDOM_THEME}' WHERE gl_name='css_header'"
fi
fi
#reinstitute file permissions
chmod 644 $OPENEMR/sites/default/sqlconf.php
echo "Done configuring OpenEMR"
echo "Done configuring OpenEMR" >> $LOG
# Set up to allow demo and testing of hl7 labs feature
mkdir $OPENEMR/sites/default/procedure_results
if $alpineOs; then
chmod -R a+w $OPENEMR/sites/default/procedure_results
else
chown -R www-data:www-data $OPENEMR/sites/default/procedure_results
fi
# Set up swagger api to work
if [ -f $OPENEMR/swagger/openemr-api.yaml ]; then
echo "Setting up swagger api"
echo "Setting up swagger api" >> $LOG
if [ "$demo" == "empty" ]; then
demoPath=""
else
demoPath="/${demo}"
fi
sed -i "s@/apis/default/@${demoPath}/openemr/apis/default/@" $OPENEMR/swagger/openemr-api.yaml
sed -i "s@/oauth2/default/authorize@${demoPath}/openemr/oauth2/default/authorize@" $OPENEMR/swagger/openemr-api.yaml
sed -i "s@/oauth2/default/token@${demoPath}/openemr/oauth2/default/token@" $OPENEMR/swagger/openemr-api.yaml
fi
#Security stuff
#1. remove the library/openflashchart/php-ofc-library/ofc_upload_image.php file if it exists
if [ -f $OPENEMR/library/openflashchart/php-ofc-library/ofc_upload_image.php ]; then
rm -f $OPENEMR/library/openflashchart/php-ofc-library/ofc_upload_image.php
echo "Removed ofc_upload_image.php file"
echo "Removed ofc_upload_image.php file" >> $LOG
fi
#set up ssh if this is turned on, which is stored in $ds
if $demoSSH; then
echo "Setting up $ds ssh"
echo "Setting up $ds ssh" >> $LOG
#ensure the file exists
if [ -f "$GITDEMOFARM/ssh/$ds.zip" ]; then
cd "$GITDEMOFARM/ssh/"
unzip "$ds.zip"
cd "$ds"
if [ -z "$DOCKERDEMO" ] ; then
#install openvpn
apt-get update >> $LOG
apt-get -y install openvpn >> $LOG
fi
#initiate up ssh tunnel
bash connect.sh
cd ~
echo "Done setting up $ds ssh"
echo "Done setting up $ds ssh" >> $LOG
else
echo "Error, $ds data does not exist"
echo "Error, $ds data does not exist" >> $LOG
fi
fi
if $packageServe ; then
#Package the development version into a tarball and zip file to be available thru web browser
# This is basically to allow download of most recent cvs version from the cvs Demo appliance
# It will also ease transfer/testing openemr on windows systems when using the Developer appliance
echo "Creating OpenEMR Development packages"
echo "Creating OpenEMR Development packages" >> $LOG
# Prepare the development package
mkdir -p $TMPDIR/openemr
rsync --recursive --exclude .git $GIT/* $TMPDIR/openemr/
#Build openemr package
if [ ! -d $TMPDIR/openemr/vendor ]; then
cd $TMPDIR/openemr
# install php dependencies
GITHUB_KEY_COMPOSER=`cat /home/openemr/github-key`
githubTokenRateLimitRequestPackage=`curl -H "Authorization: token $GITHUB_KEY_COMPOSER" https://api.github.com/rate_limit`
githubTokenRateLimitPackage=`echo $githubTokenRateLimitRequestPackage | jq '.rate.remaining'`
echo "Number of github api requests remaining is $githubTokenRateLimitPackage"
echo "Number of github api requests remaining is $githubTokenRateLimitPackage" >> $LOG
if [ "$githubTokenRateLimitPackage" -gt 1000 ]; then
echo "Using composer github api token"
echo "Using composer github api token" >> $LOG
composer config --global --auth github-oauth.github.com $GITHUB_KEY_COMPOSER
else
echo "Not using composer github api token"
echo "Not using composer github api token" >> $LOG
fi
composer install --no-dev &>> $LOG
if [ -f $TMPDIR/openemr/package.json ]; then
# install frontend dependencies (need unsafe-perm to run as root)
npm install --unsafe-perm &>> $LOG
# build css
npm run build &>> $LOG
fi
# clean up
composer global require phing/phing &>> $LOG
/root/.composer/vendor/bin/phing vendor-clean &>> $LOG
/root/.composer/vendor/bin/phing assets-clean &>> $LOG
composer global remove phing/phing &>> $LOG
# remove the node_modules directory
rm -fr $TMPDIR/openemr/node_modules &>> $LOG
# optimize
composer dump-autoload -o &>> $LOG
fi
chmod a+w $TMPDIR/openemr/sites/default/sqlconf.php
chmod -R a+w $TMPDIR/openemr/sites/default/documents
chmod -R a+w $TMPDIR/openemr/sites/default/edi
chmod -R a+w $TMPDIR/openemr/sites/default/era
chmod -R a+w $TMPDIR/openemr/library/freeb
chmod -R a+w $TMPDIR/openemr/sites/default/letter_templates
chmod -R a+w $TMPDIR/openemr/interface/main/calendar/modules/PostCalendar/pntemplates/cache
chmod -R a+w $TMPDIR/openemr/interface/main/calendar/modules/PostCalendar/pntemplates/compiled
chmod -R a+w $TMPDIR/openemr/gacl/admin/templates_c
if [ -f $TMPDIR/openemr/interface/modules/zend_modules/config/application.config.php ] ; then
# This is specifically for Zend code that is currently under development(added in version 4.1.3).
chmod a+w $TMPDIR/openemr/interface/modules/zend_modules/config/application.config.php
fi
# Create the web file directory
mkdir $FILESSERVEDIR
# Save the tar.gz cvs package
cd $TMPDIR
rm -f $FILESSERVEDIR/openemr-cvs.tar.gz
tar -czf $FILESSERVEDIR/openemr-cvs.tar.gz openemr
cd $FILESSERVEDIR
md5sum openemr-cvs.tar.gz > openemr-linux-md5.txt
# Save the .zip cvs package
cd $TMPDIR
rm -f $FILESSERVEDIR/openemr-cvs.zip
zip -rq $FILESSERVEDIR/openemr-cvs.zip openemr
cd $FILESSERVEDIR
md5sum openemr-cvs.zip > openemr-windows-md5.txt
# Create the time stamp
date > date-cvs.txt
# Clean up
rm -fr $TMPDIR
rm -fr $GIT
echo "Done creating OpenEMR Development packages"
echo "Done creating OpenEMR Development packages" >> $LOG
fi
if $portalsDemo; then
# This will install and set up the wordpress patient portal
echo "Setting up patient portals"
echo "Setting up patient portals" >> $LOG
# Prepare the sql files with the external link
sed -e '[email protected]:2104@'"$EXTERNALLINK"'@g' <"$GITDEMOWORDPRESSDEMOSQLONE" >"$GITDEMOWORDPRESSDEMOSQLONETEMP"
sed -e '[email protected]:2104@'"$EXTERNALLINK"'@g' <"$GITDEMOWORDPRESSDEMOSQLTWO" >"$GITDEMOWORDPRESSDEMOSQLTWOTEMP"
# Install the openemr sql stuff for portals
if [ -n "$DOCKERDEMO" ] ; then
mysql -h $DOCKERMYSQLHOST -u root $rpassparam $DOCKERDEMO < "$GITDEMOWORDPRESSDEMOSQLONETEMP"
else
mysql -u root $rpassparam openemr < "$GITDEMOWORDPRESSDEMOSQLONETEMP"
fi
# Install wordpress file stuff
mkdir -p $WORDPRESS
rm -fr $WORDPRESS/*
cp -r $GITDEMOWORDPRESSDEMOWEB/* $WORDPRESS/
# Install wordpress database stuff
if [ -n "$DOCKERDEMO" ] ; then
mysqladmin -h $DOCKERMYSQLHOST -u root $rpassparam create ${DOCKERDEMO}wordpress
mysql -h $DOCKERMYSQLHOST -u root $rpassparam --execute "GRANT ALL PRIVILEGES ON ${DOCKERDEMO}wordpress.* TO '${DOCKERDEMO}wordpress'@'%' IDENTIFIED BY '${DOCKERDEMO}wordpress'" ${DOCKERDEMO}wordpress
mysql -h $DOCKERMYSQLHOST -u root $rpassparam ${DOCKERDEMO}wordpress < "$GITDEMOWORDPRESSDEMOSQLTWOTEMP"
# Modify $WORDPRESS/wp-config.php to match credentials created above
sed -i "s@'DB_NAME', 'wordpress'@'DB_NAME', '${DOCKERDEMO}wordpress'@" "$WORDPRESS/wp-config.php"
sed -i "s@'DB_USER', 'wordpress'@'DB_USER', '${DOCKERDEMO}wordpress'@" "$WORDPRESS/wp-config.php"
sed -i "s@'DB_PASSWORD', 'wordpress'@'DB_PASSWORD', '${DOCKERDEMO}wordpress'@" "$WORDPRESS/wp-config.php"
sed -i "s@'DB_HOST', 'localhost'@'DB_HOST', '${DOCKERMYSQLHOST}'@" "$WORDPRESS/wp-config.php"
else
mysqladmin -u root $rpassparam create wordpress
mysql -u root $rpassparam --execute "GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'wordpress'" wordpress
mysql -u root $rpassparam wordpress < "$GITDEMOWORDPRESSDEMOSQLTWOTEMP"
fi
rm "$GITDEMOWORDPRESSDEMOSQLONETEMP"
rm "$GITDEMOWORDPRESSDEMOSQLTWOTEMP"
echo "Done setting up patient portals"
echo "Done setting up patient portals" >> $LOG
fi
#if $passResetAuto; then
# run the auto reset password script every 5 minutes
#nohup php -f ${PASSWORDRESETSCRIPT} ${FINALWEB} 300 ${passReset} >/dev/null 2>&1 &
#fi
done
# Install Postfix to allow email registration on wordpress patient portal demo and other openemr stuff, if possible.
# Note docker demos already have this installed, but do need to start it. Docker also
# uses stunnel to communicate to aws ses email server.
if [ -z "$DOCKERDEMO" ] ; then
apt-get update >> $LOG
debconf-set-selections <<< "postfix postfix/mailname string opensourceemr.com"
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
apt-get -y install postfix >> $LOG
else
if ! $lightReset; then
stunnel /etc/stunnel/stunnel.conf >> $LOG
postfix start >> $LOG
fi
fi
#restart apache and secure sensitive directories
if ! $lightReset; then
if $alpineOs; then
cp $OPENEMRAPACHECONF /etc/apache2/conf.d/openemr.conf
httpd -k start >> $LOG
else
cp $OPENEMRAPACHECONF /etc/apache2/sites-available/openemr.conf
a2ensite openemr.conf >> $LOG
/etc/init.d/apache2 start >> $LOG
fi
fi
echo "Demo install script is complete"
echo "Demo install script is complete" >> $LOG
# Record end time
timeEnd=`date -u`
echo -n "Completed Build: "
echo "$timeEnd"
echo -n "Completed Build: " >> $LOG
echo "$timeEnd" >> $LOG
if ! $lightReset; then
if [ -n "$DOCKERDEMO" ] ; then
# to stop docker image from exiting
echo "hold docker open"
tail -F -n0 /etc/hosts
fi
fi