forked from BU-ISCIII/iskylims
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
837 lines (738 loc) · 33.9 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
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
#!/bin/bash
ISKYLIMS_VERSION="3.x.x"
usage() {
cat << EOF
This script install and upgrade the iskylims app.
usage : $0 --upgrade --dev --conf
Optional input data:
--install | Install iskylims full/dep/app
--upgrade | Upgrade iskylims full/dep/app
--dev | Use the develop version instead of main release
--conf | Select custom configuration file. Default: ./install_settings.txt
--tables | Load the first inital tables for upgrades in conf folder
--script | Run a migration script.
--ren_app | Rename apps required for the upgrade migration to 3.0.0
--docker | Specific installation for docker compose configuration.
Examples:
Install iskylims only dep
sudo $0 --install dep
Install only iSkyLIMS app
$0 --install app
Upgrade using develop code
$0 --upgrade full --dev
Upgrade running migration script and update initial tables
$0 --upgrade full --script <migration_script> --tables
Make adjustments for apps renaming in upgrade 2.3.0 to 2.3.1
$0 --upgrade full --ren_app --script <migration_script> --tables
EOF
}
db_check(){
# user should have mysql permission on remote server.
mysqladmin -h $DB_SERVER_IP -u$DB_USER -p$DB_PASS -P$DB_PORT processlist > /dev/null
if ! [ $? -eq 0 ]; then
echo -e "${RED}ERROR : Unable to connect to database. Check if your database is running and accessible${NC}"
exit 1
fi
RESULT=`mysqlshow --user=$DB_USER --password=$DB_PASS --host=$DB_SERVER_IP --port=$DB_PORT | grep -o $DB_NAME`
if ! [ "$RESULT" == "$DB_NAME" ] ; then
echo -e "${RED}ERROR : iskylims database is not defined yet ${NC}"
echo -e "${RED}ERROR : Create iskylims database on your mysql server and run again the installation script ${NC}"
exit 1
fi
}
apache_check(){
if [[ $linux_distribution == "Ubuntu" ]]; then
if ! pidof apache2 > /dev/null ; then
# web server down, restart the server
echo "Apache Server is down... Trying to restart Apache"
systemctl restart apache2.service
sleep 10
if pidof apache2 > /dev/null ; then
echo "Apache Server is up"
else
echo -e "${RED}ERROR : Unable to start Apache ${NC}"
echo -e "${RED}ERROR : Solve the issue with Apache server and run again the installation script ${NC}"
exit 1
fi
fi
elif [[ $linux_distribution == "CentOs" || $linux_distribution == "RedHatEnterprise" ]]; then
if ! pidof httpd > /dev/null ; then
# web server down, restart the server
echo "Apache Server is down... Trying to restart Apache"
systemctl restart httpd
sleep 10
if pidof httpd > /dev/null ; then
echo "Apache Server is up"
else
echo -e "${RED}ERROR : Unable to start Apache ${NC}"
echo -e "${RED}ERROR : Solve the issue with Apache server and run again the installation script ${NC}"
exit 1
fi
fi
fi
}
python_check(){
python_version=$(su -c $PYTHON_BIN_PATH --version $user)
if [[ $python_version == "" ]]; then
echo -e "${RED}ERROR : Python3 is not found in your system ${NC}"
echo -e "${RED}ERROR : Solve the issue with Python and run again the installation script ${NC}"
exit 1
fi
p_version=$(echo $python_version | cut -d"." -f2)
if (( $p_version < 7 )); then
echo -e "${RED}ERROR : Application requieres at least the version 3.7.x of Python3 ${NC}"
echo -e "${RED}ERROR : Solve the issue with python and run again the installation script ${NC}"
exit 1
fi
}
root_check(){
if [[ $EUID -ne 0 ]]; then
printf "\n\n%s"
printf "${RED}------------------${NC}\n"
printf "%s"
printf "${RED}Exiting installation. This script must be run as root ${NC}\n"
printf "\n\n%s"
printf "${RED}------------------${NC}\n"
printf "%s"
exit 1
fi
}
update_settings_and_urls(){
# save SECRET KEY at home user directory
grep ^SECRET $INSTALL_PATH/iskylims/settings.py > ~/.secret
# Copying config files and script. TODO CHANGE iSkyLIMS to app name
cp conf/template_settings.txt $INSTALL_PATH/iskylims/settings.py
cp conf/urls.py $INSTALL_PATH/iskylims
# replacing dummy variables with real values
sed -i "/^SECRET/c\\$(cat ~/.secret)" $INSTALL_PATH/iskylims/settings.py
sed -i "s/djangouser/${DB_USER}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/djangopass/${DB_PASS}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/djangohost/${DB_SERVER_IP}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/djangoport/${DB_PORT}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/djangodbname/${DB_NAME}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/emailhostserver/${EMAIL_HOST_SERVER}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/emailport/${EMAIL_PORT}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/emailhostuser/${EMAIL_HOST_USER}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/emailhostpassword/${EMAIL_HOST_PASSWORD}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/emailhosttls/${EMAIL_USE_TLS}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/localserverip/${LOCAL_SERVER_IP}/g" $INSTALL_PATH/iskylims/settings.py
sed -i "s/localhost/${DNS_URL}/g" $INSTALL_PATH/iskylims/settings.py
}
upgrade_venv(){
echo "activate the virtualenv"
source virtualenv/bin/activate
echo "Installing required python packages"
python -m pip install --upgrade pip
python -m pip install -r conf/requirements.txt
}
#================================================================
#SET TEMINAL COLORS
#================================================================
YELLOW='\033[0;33m'
WHITE='\033[0;37m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
# translate long options to short
reset=true
for arg in "$@"
do
if [ -n "$reset" ]; then
unset reset
set -- # this resets the "$@" array so we can rebuild it
fi
case "$arg" in
# OPTIONAL
--install) set -- "$@" -i ;;
--upgrade) set -- "$@" -u ;;
--script) set -- "$@" -s ;;
--tables) set -- "$@" -t ;;
--dev) set -- "$@" -d ;;
--conf) set -- "$@" -c ;;
--ren_app) set -- "$@" -r ;;
--docker) set -- "$@" -k ;;
# ADITIONAL
--help) set -- "$@" -h ;;
--version) set -- "$@" -v ;;
# PASSING VALUE IN PARAMETER
*) set -- "$@" "$arg" ;;
esac
done
# SETTING DEFAULT VALUES
ren_app=false
tables=false
git_branch="main"
conf="./install_settings.txt"
install=true
install_type="full"
upgrade=false
upgrade_type="full"
docker=false
# PARSE VARIABLE ARGUMENTS WITH getops
options=":c:s:i:u:drtkvh"
while getopts $options opt; do
case $opt in
i )
install=true
upgrade=false
if [[ "$OPTARG" -eq "full" || "$OPTARG" -eq "dep" || "$OPTARG" -eq "app" ]]; then
install_type=$OPTARG
upgrade_type=$OPTARG
else
echo "Upgrade is not set to one valid option. Use: --upgrade full/app/dep"
exit 1
fi
;;
u )
install=false
upgrade=true
if [[ "$OPTARG" -eq "full" || "$OPTARG" -eq "dep" || "$OPTARG" -eq "app" ]]; then
upgrade_type=$OPTARG
install_type=$OPTARG
else
echo "Upgrade is not set to one valid option. Use: --upgrade full/app/dep"
exit 1
fi
;;
s )
run_script=true
migration_script+=("$OPTARG")
;;
t )
tables=true
;;
r )
ren_app=true
;;
d )
git_branch="develop"
;;
c )
conf=$OPTARG
;;
k )
docker=true
;;
h )
usage
exit 1
;;
v )
echo $ISKYLIMS_VERSION
exit 1
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
usage
exit 1
;;
: )
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
* )
echo "Unimplemented option: -$OPTARG" >&2;
exit 1
;;
esac
done
shift $((OPTIND-1))
#=============================================================================
# SETTINGS CHECKINGS
#=============================================================================
if [ ! -f "$conf" ]; then
printf "\n\n%s"
printf "${RED}------------------${NC}\n"
printf "${RED}Unable to start.${NC}\n"
printf "${RED}Configuration File $conf does not exist.${NC}\n"
printf "${RED}------------------${NC}\n"
exit 1
fi
# Read configuration file
. $conf
# check if branch master/develop is defined and checkout
if [ "`git branch --list $git_branch`" ]; then
git checkout $git_branch
else
printf "\n\n%s"
printf "${RED}------------------${NC}\n"
printf "${RED}Unable to start.${NC}\n"
printf "${RED}Git branch $git_branch is not define in ${PWD}.${NC}\n"
printf "${RED}------------------${NC}\n"
exit 1
fi
#================================================================
# CHECK REQUIREMENTS BEFORE STARTING INSTALLATION
#================================================================
echo "Checking main requirements"
python_check
printf "${BLUE}Valid version of Python${NC}\n"
if [ $docker == false ]; then
db_check
printf "${BLUE}Successful check for database${NC}\n"
apache_check
printf "${BLUE}Successful check for apache${NC}\n"
fi
if [ "$install_type" == "full" ] || [ "$install_type" == "dep" ] || [ "$upgrade_type" == "full" ] || [ "$upgrade_type" == "dep" ]; then
printf "${YELLOW} Checking requirement of root user when installation is full or dep ${NC}\n"
root_check
printf "${BLUE}Successful checking of root user${NC}\n"
fi
#=============================================================================
# UPGRADE INSTALLATION
# Check if parameter is passing to script to upgrade the installation
# If "upgrade" parameter is set then the script only execute the upgrade part.
# If other parameter as upgrade is given return usage message and exit
#=============================================================================
if [ $upgrade == true ]; then
# check if upgrade keyword is given
if [ ! -d $INSTALL_PATH ]; then
printf "\n\n%s"
printf "${RED}------------------${NC}\n"
printf "${RED}Unable to start the upgrade.${NC}\n"
printf "${RED}Folder $INSTALL_PATH does not exist.${NC}\n"
printf "${RED}------------------${NC}\n"
exit 1
fi
#================================================================
# MAIN_BODY FOR UPGRADE
#================================================================
printf "\n\n%s"
printf "${YELLOW}------------------${NC}\n"
printf "%s"
printf "${YELLOW}Starting iSkyLIMS Upgrade version: ${ISKYLIMS_VERSION}${NC}\n"
printf "%s"
printf "${YELLOW}------------------${NC}\n\n"
if [ "$upgrade_type" = "full" ] || [ "$upgrade_type" = "dep" ]; then
if [ -d $INSTALL_PATH/virtualenv ]; then
read -p "Do you want to remove current virtualenv and reinstall? (Y/N) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]] ; then
rm -rf $INSTALL_PATH/virtualenv
rsync -rlv conf/requirements.txt $INSTALL_PATH/conf/requirements.txt
cd $INSTALL_PATH
bash -c "$PYTHON_BIN_PATH -m venv virtualenv"
upgrade_venv
cd -
else
rsync -rlv conf/requirements.txt $INSTALL_PATH/conf/requirements.txt
cd $INSTALL_PATH
upgrade_venv
cd -
fi
else
echo "There is no virtualenv to upgrade in $INSTALL_PATH."
read -p "Do you want to create a new virtualenv and reinstall? (Y/N) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]] ; then
rsync -rlv conf/requirements.txt $INSTALL_PATH/conf/requirements.txt
cd $INSTALL_PATH
bash -c "$PYTHON_BIN_PATH -m venv virtualenv"
upgrade_venv
cd -
else
echo "Exiting..."
exit 0
fi
fi
fi
if [ "$upgrade_type" = "full" ] || [ "$upgrade_type" = "app" ]; then
# Delete git and no copy files stuff
if [ $ren_app == true ] ; then
# remove all previous migrations and make a fake initial
# delete existing migrations file
rm -rf $INSTALL_PATH/django_utils/migrations/*
rm -rf $INSTALL_PATH/iSkyLIMS_core/migrations/*
rm -rf $INSTALL_PATH/iSkyLIMS_wetlab/migrations/*
rm -rf $INSTALL_PATH/iSkyLIMS_drylab/migrations/*
cd $INSTALL_PATH
sed -i "s/ugettext/gettext/g" iSkyLIMS_wetlab/models.py
sed -i "s/ugettext/gettext/g" iSkyLIMS_core/forms.py
sed -i "s/ugettext/gettext/g" django_utils/forms.py
echo "activate the virtualenv"
source virtualenv/bin/activate
echo "Create a fake initial"
python manage.py makemigrations django_utils iSkyLIMS_core \
iSkyLIMS_wetlab iSkyLIMS_drylab
python manage.py migrate --fake-initial
if [ -d "$INSTALL_PATH/iSkyLIMS_core" ]; then
echo "Changing app dir names in $INSTALL_PATH..."
rm -rf $INSTALL_PATH/.git $INSTALL_PATH/.github $INSTALL_PATH/.gitignore \
$INSTALL_PATH/.Rhistory $INSTALL_PATH/docker-compose.yml $INSTALL_PATH/docker_iskylims_install.sh \
$INSTALL_PATH/Dockerfile $INSTALL_PATH/install.sh $INSTALL_PATH/install_settings.txt
mv $INSTALL_PATH/iSkyLIMS_core $INSTALL_PATH/core
mv $INSTALL_PATH/iSkyLIMS_wetlab $INSTALL_PATH/wetlab
mv $INSTALL_PATH/iSkyLIMS_drylab $INSTALL_PATH/drylab
mv $INSTALL_PATH/iSkyLIMS_clinic $INSTALL_PATH/clinic
echo "Done changing app dir names in $INSTALL_PATH..."
fi
if [ -d "iSkyLIMS" ]; then
mv iSkyLIMS/ iskylims/
sed -i "s/iSkyLIMS/iskylims/g" $INSTALL_PATH/iskylims/wsgi.py
sed -i "s/iSkyLIMS/iskylims/g" $INSTALL_PATH/manage.py
fi
cd -
fi
# update installation by sinchronize folders
echo "Copying files to installation folder"
rsync -rlv conf/ $INSTALL_PATH/conf/
rsync -rlv --fuzzy --delay-updates --delete-delay \
--exclude "logs" --exclude "documents" --exclude "migrations" --exclude "__pycache__" \
README.md LICENSE test conf core drylab clinic wetlab django_utils $INSTALL_PATH
# update the settings.py and the main urls
echo "Update settings and url file."
update_settings_and_urls
# update illumina template files.# Copy illumina sample sheet templates
mkdir -p $INSTALL_PATH/documents/wetlab/templates/
cp $INSTALL_PATH/conf/*_template.csv $INSTALL_PATH/documents/wetlab/templates/
cp $INSTALL_PATH/conf/samples_template.xlsx $INSTALL_PATH/documents/wetlab/templates/
# update logging configuration file
cp $INSTALL_PATH/conf/template_logging_config.ini $INSTALL_PATH/wetlab/logging_config.ini
sed -i "s@INSTALL_PATH@${INSTALL_PATH}@g" $INSTALL_PATH/wetlab/logging_config.ini
# update the sample sheet folder and name
if [ -d "$INSTALL_PATH/documents/wetlab/SampleSheets" ]; then
echo "Updating sample sheet folder name"
mv $INSTALL_PATH/documents/wetlab/SampleSheets $INSTALL_PATH/documents/wetlab/sample_sheet
fi
if [ -d "$INSTALL_PATH/documents/wetlab/SampleSheets4LibPrep" ]; then
echo "Updating sample sheet for libary preparationfolder name"
mv $INSTALL_PATH/documents/wetlab/SampleSheets4LibPrep $INSTALL_PATH/documents/wetlab/sample_sheets_lib_prep
fi
cd $INSTALL_PATH
echo "activate the virtualenv"
source virtualenv/bin/activate
### RENAME APP in database and migration files ####
if [ $ren_app == true ] ; then
echo "Modifying database names and constraints..."
mysql -u $DB_USER -p$DB_PASS -D $DB_NAME -h $DB_SERVER_IP \
-e 'UPDATE django_content_type SET app_label = REPLACE(app_label , "iSkyLIMS_core", "core") WHERE app_label like ("iSkyLIMS_%");'
# mysql -u $DB_USER -p$DB_PASS -D $DB_NAME -h $DB_SERVER_IP \
# -e 'UPDATE django_content_type SET app_label = REPLACE(app_label , "iSkyLIMS_clinic", "clinic") WHERE app_label like ("iSkyLIMS_%");'
mysql -u $DB_USER -p$DB_PASS -D $DB_NAME -h $DB_SERVER_IP \
-e 'UPDATE django_content_type SET app_label = REPLACE(app_label , "iSkyLIMS_wetlab", "wetlab") WHERE app_label like ("iSkyLIMS_%");'
mysql -u $DB_USER -p$DB_PASS -D $DB_NAME -h $DB_SERVER_IP \
-e 'UPDATE django_content_type SET app_label = REPLACE(app_label , "iSkyLIMS_drylab", "drylab") WHERE app_label like ("iSkyLIMS_%");'
mysql -u $DB_USER -p$DB_PASS -D $DB_NAME -h $DB_SERVER_IP \
-e 'UPDATE django_migrations SET app = REPLACE(app , "iSkyLIMS_core", "core") WHERE app like ("iSkyLIMS_%");'
# mysql -u $DB_USER -p$DB_PASS -D $DB_NAME -h $DB_SERVER_IP \
# -e 'UPDATE django_migrations SET app = REPLACE(app , "iSkyLIMS_clinic", "clinic") WHERE app like ("iSkyLIMS_%");'
mysql -u $DB_USER -p$DB_PASS -D $DB_NAME -h $DB_SERVER_IP \
-e 'UPDATE django_migrations SET app = REPLACE(app , "iSkyLIMS_wetlab", "wetlab") WHERE app like ("iSkyLIMS_%");'
mysql -u $DB_USER -p$DB_PASS -D $DB_NAME -h $DB_SERVER_IP \
-e 'UPDATE django_migrations SET app = REPLACE(app , "iSkyLIMS_drylab", "drylab") WHERE app like ("iSkyLIMS_%");'
echo "Renaming tables"
query_rename_table="SELECT CONCAT('RENAME TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, \
' TO ', TABLE_SCHEMA, '.', REPLACE(TABLE_NAME, 'iSkyLIMS_', ''), ';') \
AS query FROM information_schema.tables WHERE TABLE_SCHEMA = \"$DB_NAME\" AND TABLE_NAME LIKE 'iSkyLIMS_%';"
mysql -u $DB_USER -p$DB_PASS -h $DB_SERVER_IP -e "$query_rename_table" \
| xargs -I % echo "mysql -u$DB_USER -p'$DB_PASS' -D $DB_NAME -h $DB_SERVER_IP -e \"% \" " | bash
echo "Renaming index"
query_rename_unique_indexes="SELECT CONCAT('ALTER TABLE ', rcu.TABLE_SCHEMA, '.', rcu.TABLE_NAME, \
' RENAME INDEX ', rcu.CONSTRAINT_NAME, \
' TO ', REPLACE(rcu.CONSTRAINT_NAME, 'iSkyLIMS_', ''), ';') \
AS query FROM information_schema.key_column_usage rcu \
JOIN information_schema.table_constraints tc \
ON tc.CONSTRAINT_NAME = rcu.CONSTRAINT_NAME WHERE rcu.TABLE_SCHEMA = \"$DB_NAME\" \
AND rcu.CONSTRAINT_NAME LIKE 'iSkyLIMS_%' AND tc.CONSTRAINT_TYPE = 'UNIQUE' \
GROUP BY rcu.TABLE_SCHEMA, rcu.TABLE_NAME, rcu.CONSTRAINT_NAME, tc.CONSTRAINT_TYPE, \
rcu.REFERENCED_TABLE_SCHEMA, rcu.REFERENCED_TABLE_NAME;"
mysql -u $DB_USER -p$DB_PASS -h $DB_SERVER_IP -e "$query_rename_unique_indexes" \
| xargs -I % echo "mysql -u$DB_USER -p'$DB_PASS' -D $DB_NAME -h $DB_SERVER_IP -e \"% \" " | bash
echo "Renaming constraints"
query_rename_constraints="SELECT CONCAT('ALTER TABLE ', rcu.TABLE_SCHEMA, '.', rcu.TABLE_NAME, \
' DROP FOREIGN KEY ' , rcu.CONSTRAINT_NAME, ';', \
' ALTER TABLE ', rcu.TABLE_SCHEMA, '.', rcu.TABLE_NAME, \
' ADD CONSTRAINT ', REPLACE(rcu.CONSTRAINT_NAME, 'iSkyLIMS_', ''), ' ', \
tc.CONSTRAINT_TYPE, ' (', GROUP_CONCAT(rcu.COLUMN_NAME ORDER BY rcu.ORDINAL_POSITION SEPARATOR ', '), ')', \
IF(tc.CONSTRAINT_TYPE = 'FOREIGN KEY', \
CONCAT(' REFERENCES ', rcu.REFERENCED_TABLE_SCHEMA, '.', REPLACE(rcu.REFERENCED_TABLE_NAME, 'iSkyLIMS_', ''), ' (', \
GROUP_CONCAT(rcu.REFERENCED_COLUMN_NAME ORDER BY rcu.ORDINAL_POSITION SEPARATOR ', '), ') ON DELETE ', rc.DELETE_RULE), \
''), ';') AS query \
FROM information_schema.key_column_usage rcu \
LEFT JOIN information_schema.table_constraints tc ON rcu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME \
LEFT JOIN information_schema.referential_constraints rc ON rcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME \
WHERE rcu.TABLE_SCHEMA = '$DB_NAME' AND rcu.CONSTRAINT_NAME LIKE 'iSkyLIMS_%' \
GROUP BY rcu.TABLE_SCHEMA, rcu.TABLE_NAME, rcu.CONSTRAINT_NAME, tc.CONSTRAINT_TYPE, rcu.REFERENCED_TABLE_SCHEMA, rcu.REFERENCED_TABLE_NAME, rc.DELETE_RULE;"
mysql -u $DB_USER -p$DB_PASS -h $DB_SERVER_IP -e "$query_rename_constraints" | xargs -I % echo "mysql -u$DB_USER -p'$DB_PASS' -D $DB_NAME -h $DB_SERVER_IP -e \"% \" " | bash
echo "Done modifying database names and constraints..."
echo "Modifying names in migration files..."
sed -i 's/iSkyLIMS_core/core/g' */migrations/*.py
# sed -i 's/iSkyLIMS_clinic/clinic/g' */migrations/*.py
sed -i 's/iSkyLIMS_drylab/drylab/g' */migrations/*.py
sed -i 's/iSkyLIMS_wetlab/wetlab/g' */migrations/*.py
echo "Done modifying names in migration files..."
# copy modified migration files
echo "Copying custom migration files from conf."
cp $INSTALL_PATH/conf/0002_core_migration_v3.0.0.py $INSTALL_PATH/core/migrations/0002_migration_v3_0_0.py
cp $INSTALL_PATH/conf/0002_drylab_migration_v3.0.0.py $INSTALL_PATH/drylab/migrations/0002_migration_v3_0_0.py
cp $INSTALL_PATH/conf/0002_wetlab_migration_v3.0.0.py $INSTALL_PATH/wetlab/migrations/0002_migration_v3_0_0.py
# cp conf/0002_clinic_migration_v2.3.1.py clinic/migrations/0002_migration_v2_3_1.py
cp $INSTALL_PATH/conf/0002_django_utils_migration_v3.0.0.py $INSTALL_PATH/django_utils/migrations/0002_migration_v3_0_0.py
read -p "Do you want to proceed with the migrate command? (Y/N) " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
echo "Exiting without running migrate command."
exit 1
fi
echo "activate the virtualenv"
source virtualenv/bin/activate
echo "Running migrate..."
python manage.py migrate
echo "Done migrate command."
else
echo "checking for database changes"
if python manage.py makemigrations | grep -q "No changes"; then
echo "No migration is required"
else
read -p "Do you want to proceed with the migrate command? (Y/N) " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
echo "Exiting without running migrate command."
exit 1
fi
echo "Running migrate..."
python manage.py migrate
echo "Done migrate command."
fi
fi
echo "Running collect statics..."
python manage.py collectstatic
echo "Done collect statics"
if [ $tables == true ] ; then
echo "Loading pre-filled tables..."
python manage.py loaddata conf/first_install_tables.json
echo "Done loading pre-filled tables..."
fi
if [ $run_script ]; then
for val in "${migration_script[@]}"; do
echo "Running migration script: $val"
python manage.py runscript $val
echo "Done migration script: $val"
done
fi
cd -
# Linux distribution
linux_distribution=$(lsb_release -i | cut -f 2-)
echo ""
echo "Restart apache server to update changes"
if [[ $linux_distribution == "Ubuntu" ]]; then
apache_daemon="apache2"
else
apache_daemon="httpd"
fi
# systemctl restart $apache_user
if ! [ $? -eq 0 ]; then
echo -e "${ORANGE}Apache server restart failed. trying with sudo{NC}"
sudo systemctl restart $apache_daemon
fi
fi
printf "\n\n%s"
printf "${BLUE}------------------${NC}\n"
printf "%s"
printf "${BLUE}Successfuly upgrade of iSKyLIMS version: ${ISKYLIMS_VERSION}${NC}\n"
printf "%s"
printf "${BLUE}------------------${NC}\n\n"
# exit once upgrade is finished
exit 0
fi
#================================================================
# INSTALL REPOSITORY REQUIRED SOFTWARE AND PYTHON VIRTUAL ENVIRONMENT
#================================================================
if [ $install == true ]; then
if [ "$install_type" == "full" ] || [ "$install_type" == "dep" ]; then
#================================================================
# MAIN_BODY FOR INSTALL
#================================================================
printf "\n\n%s"
printf "${YELLOW}------------------${NC}\n"
printf "%s"
printf "${YELLOW}Starting iSkyLIMS install version: ${ISKYLIMS_VERSION}${NC}\n"
printf "%s"
printf "${YELLOW}------------------${NC}\n\n"
user=$SUDO_USER
group=$(groups | cut -d" " -f1)
# Find out server Linux distribution
linux_distribution=$(lsb_release -i | cut -f 2-)
if [[ $linux_distribution == "Ubuntu" ]]; then
apache_group="www-data"
else
apache_group="apache"
fi
echo "Starting iSkyLIMS installation"
if [ -d $INSTALL_PATH ]; then
echo "There already is an installation of iskylims in $INSTALL_PATH."
read -p "Do you want to remove current installation and reinstall? (Y/N) " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
echo "Exiting without running iSkyLIMS installation"
exit 1
else
rm -rf $INSTALL_PATH
fi
fi
echo "Installing Interop"
if [ -d /opt/interop ]; then
echo "There is already an interop installation"
echo "Skipping Interop installation"
else
cd /opt
echo "Downloading interop software"
wget https://github.com/Illumina/interop/releases/download/v1.1.15/InterOp-1.1.15-Linux-GNU.tar.gz
tar -xf InterOp-1.1.15-Linux-GNU.tar.gz
ln -s InterOp-1.1.15-Linux-GNU interop
rm InterOp-1.1.15-Linux-GNU.tar.gz
echo "Interop is now installed"
cd -
fi
if [[ $linux_distribution == "Ubuntu" ]]; then
echo "Software installation for Ubuntu"
apt-get update && apt-get upgrade -y
apt-get install -y \
apt-utils wget \
libmysqlclient-dev \
python3-venv \
libpq-dev \
python3-dev python3-pip python3-wheel \
apache2-dev cifs-utils \
gnuplot
fi
if [[ $linux_distribution == "CentOS" || $linux_distribution == "RedHatEnterprise" ]]; then
echo "Software installation for Centos/RedHat"
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel \
wget httpd-devel mysql-libs sqlite sqlite-devel \
mariadb-devel libffi-devel \
gnuplot cifs-utils
fi
## Create the installation folder
mkdir -p $INSTALL_PATH/conf
chown -R $user:$apache_group $INSTALL_PATH
chmod 775 $INSTALL_PATH
# Copy requirements before moving to install path
rsync -rlv conf/requirements.txt $INSTALL_PATH/conf/requirements.txt
cd $INSTALL_PATH
# install virtual environment
echo "Creating virtual environment"
if [ -d $INSTALL_PATH/virtualenv ]; then
echo "There already is a virtualenv for iskylims in $INSTALL_PATH."
read -p "Do you want to remove current virtualenv and reinstall? (Y/N) " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
rm -rf $INSTALL_PATH/virtualenv
bash -c "$PYTHON_BIN_PATH -m venv virtualenv"
else
echo "virtualenv alredy defined. Skipping."
fi
else
bash -c "$PYTHON_BIN_PATH -m venv virtualenv"
fi
echo "activate the virtualenv"
source virtualenv/bin/activate
# Install python packages required for iSkyLIMS
echo "Installing required python packages"
python -m pip install wheel
python -m pip install -r conf/requirements.txt
cd -
if [ "$install_type" == "full" ] || [ "$install_type" == "app" ]; then
printf "\n\n%s"
printf "${BLUE}------------------${NC}\n"
printf "%s"
printf "${BLUE}Software dep are successfuly installed${NC}\n"
printf "%s"
printf "${BLUE}------------------${NC}\n\n"
else
printf "\n\n%s"
printf "${BLUE}------------------${NC}\n"
printf "%s"
printf "${BLUE}Software dep are successfuly installed${NC}\n"
printf "%s"
printf "${BLUE}------------------${NC}\n\n"
printf "\n\n%s"
printf "${RED}------------------${NC}\n"
printf "%s"
printf "${RED}Exiting${NC}\n"
printf "%s"
printf "${RED}------------------${NC}\n\n"
exit 0
fi
fi
#================================================================
# INSTALL iSkyLIMS PLATFORM APPLICATION
#================================================================
if [ "$install_type" == "full" ] || [ "$install_type" == "app" ]; then
if [ $LOG_TYPE == "symbolic_link" ]; then
if [ -d $LOG_PATH ]; then
ln -s $LOG_PATH $INSTALL_PATH/logs
chmod 775 $LOG_PATH
else
echo "Log folder path: $LOG_PATH does not exist. Fix it in the install_settings.txt and run again."
exit 1
fi
else
mkdir -p $INSTALL_PATH/logs
chown $user:$apache_group $INSTALL_PATH/logs
chmod 775 $INSTALL_PATH/logs
fi
rsync -rlv README.md LICENSE test conf core drylab \
wetlab clinic django_utils $INSTALL_PATH
cd $INSTALL_PATH
# Create necessary folders
echo "Created documents structure"
mkdir -p $INSTALL_PATH/documents/wetlab
mkdir -p $INSTALL_PATH/documents/wetlab/tmp
mkdir -p $INSTALL_PATH/documents/wetlab/sample_sheet
mkdir -p $INSTALL_PATH/documents/wetlab/images_plot
mkdir -p $INSTALL_PATH/documents/wetlab/templates
mkdir -p $INSTALL_PATH/documents/wetlab/sample_sheets_lib_prep
mkdir -p $INSTALL_PATH/documents/drylab
mkdir -p $INSTALL_PATH/documents/drylab/service_files
chown -R $user:$apache_group $INSTALL_PATH/documents
chmod 775 $INSTALL_PATH/documents
# Copy illumina sample sheet templates
cp $INSTALL_PATH/conf/*_template.csv $INSTALL_PATH/documents/wetlab/templates/
cp $INSTALL_PATH/conf/samples_template.xlsx $INSTALL_PATH/documents/wetlab/templates/
# update logging configuration file
cp $INSTALL_PATH/conf/template_logging_config.ini $INSTALL_PATH/wetlab/logging_config.ini
sed -i "s|INSTALL_PATH|${INSTALL_PATH}|g" $INSTALL_PATH/wetlab/logging_config.ini
# Starting iSkyLIMS
echo "activate the virtualenv"
source virtualenv/bin/activate
echo "Creating iskylims project"
django-admin startproject iskylims .
# update the settings.py and the main urls
update_settings_and_urls
if [ $docker == false ]; then
echo "Creating the database structure for iSkyLIMS"
python manage.py migrate
python manage.py makemigrations django_utils core wetlab drylab
python manage.py migrate
echo "Loading in database initial data"
python manage.py loaddata conf/first_install_tables.json
echo "Creating super user "
python manage.py createsuperuser --username admin
fi
# copy static files
echo "Run collectstatic"
python manage.py collectstatic
cd -
printf "\n\n%s"
printf "${BLUE}------------------${NC}\n"
printf "%s"
printf "${BLUE}Successfuly iSkyLIMS Installation version: ${ISKYLIMS_VERSION}${NC}\n"
printf "%s"
printf "${BLUE}------------------${NC}\n\n"
echo "Installation completed"
exit 0
fi
fi
printf "\n\n%s"
printf "${RED}------------------${NC}\n"
printf "%s"
printf "${RED}Invalid installation parameters${NC}\n"
printf "%s"
printf "${RED}------------------${NC}\n\n"
echo "See the usage examples"
usage
exit 1