This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblueprint.sh
2468 lines (2095 loc) · 118 KB
/
blueprint.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
# © 2023-2024 Ivy (prpl.wtf)
# Learn more @ blueprint.zip
# Source code available on github.com/blueprintframework/framework
# This should allow Blueprint to run in Docker. Please note that changing the $FOLDER variable after running
# the Blueprint installation script will not change anything in any files besides blueprint.sh.
FOLDER=$(realpath "$(dirname "$0")")
# This stores the webserver ownership user which Blueprint uses when applying webserver permissions.
OWNERSHIP="www-data:www-data" #;
# This stores options for permissions related to running install scripts the webserver user.
WEBUSER="www-data" #;
USERSHELL="/bin/bash" #;
# Defines the version Blueprint will display as the active one.
VERSION="beta-F248"
# Default GitHub repository to use when upgrading Blueprint.
REPOSITORY="BlueprintFramework/framework"
# Check for panels that are using Docker, which should have better support in the future.
if [[ -f "/.dockerenv" ]]; then
DOCKER="y"
FOLDER="/app"
else
DOCKER="n"
fi
# This has caused a bunch of errors but is just here to make sure people actually upload the
# "blueprint" folder onto their panel when installing Blueprint. Pick your poison.
if [[ -d "$FOLDER/blueprint" ]]; then mv "$FOLDER/blueprint" "$FOLDER/.blueprint"; fi
if [[ $VERSION != "" ]]; then
# This function makes sure some placeholders get replaced with the current Blueprint version.
if [[ ! -f "$FOLDER/.blueprint/extensions/blueprint/private/db/version" ]]; then
sed -E -i "s*::v*$VERSION*g" "$FOLDER/app/BlueprintFramework/Services/PlaceholderService/BlueprintPlaceholderService.php"
sed -E -i "s*::v*$VERSION*g" "$FOLDER/.blueprint/extensions/blueprint/public/index.html"
touch "$FOLDER/.blueprint/extensions/blueprint/private/db/version"
fi
fi
# Write environment variables.
export BLUEPRINT__FOLDER=$FOLDER
export BLUEPRINT__VERSION=$VERSION
export BLUEPRINT__DEBUG="$FOLDER"/.blueprint/extensions/blueprint/private/debug/logs.txt
export NODE_OPTIONS=--openssl-legacy-provider
# Write internal variables.
__BuildDir=".blueprint/extensions/blueprint/private/build"
# Automatically navigate to the Pterodactyl directory when running the core.
cd "$FOLDER" || return
# Import libraries.
source .blueprint/lib/parse_yaml.sh || missinglibs+="[parse_yaml]"
source .blueprint/lib/grabenv.sh || missinglibs+="[grabenv]"
source .blueprint/lib/logFormat.sh || missinglibs+="[logFormat]"
source .blueprint/lib/misc.sh || missinglibs+="[misc]"
# -config
# usage: "cITEM=VALUE bash blueprint.sh -config"
if [[ "$1" == "-config" ]]; then
# cTELEMETRY_ID
# Update the telemetry id.
if [[ "$cTELEMETRY_ID" != "" ]]; then
echo "$cTELEMETRY_ID" > .blueprint/extensions/blueprint/private/db/telemetry_id
fi
# cDEVELOPER
# Enable/Disable developer mode.
if [[ "$cDEVELOPER" != "" ]]; then
if [[ "$cDEVELOPER" == "true" ]]; then
dbAdd "blueprint.developerEnabled"
else
dbRemove "blueprint.developerEnabled"
fi
fi
echo .
exit 0
fi
cdhalt() { PRINT FATAL "Attempted navigation into nonexistent directory, halting process."; exit 1; }
depend() {
# Check for compatible node versions
nodeVer=$(node -v)
if [[ $nodeVer != "v17."* ]] \
&& [[ $nodeVer != "v18."* ]] \
&& [[ $nodeVer != "v19."* ]] \
&& [[ $nodeVer != "v20."* ]] \
&& [[ $nodeVer != "v21."* ]] \
&& [[ $nodeVer != "v22."* ]]; then
DEPEND_MISSING=true
fi
# Check for required (both internal and external) dependencies.
if \
! [ -x "$(command -v unzip)" ] || # unzip
! [ -x "$(command -v node)" ] || # node
! [ -x "$(command -v yarn)" ] || # yarn
! [ -x "$(command -v zip)" ] || # zip
! [ -x "$(command -v curl)" ] || # curl
! [ -x "$(command -v php)" ] || # php
! [ -x "$(command -v git)" ] || # git
! [ -x "$(command -v grep)" ] || # grep
! [ -x "$(command -v sed)" ] || # sed
! [ -x "$(command -v awk)" ] || # awk
! [ -x "$(command -v tput)" ] || # tput
! [ "$(ls "node_modules/"*"cross-env"* 2> /dev/null)" ] || # cross-env
! [ "$(ls "node_modules/"*"webpack"* 2> /dev/null)" ] || # webpack
! [ "$(ls "node_modules/"*"react"* 2> /dev/null)" ] || # react
[[ $missinglibs != "" ]]; then # internal
DEPEND_MISSING=true
fi
# Exit when missing dependencies.
if [[ $DEPEND_MISSING == true ]]; then
PRINT FATAL "Some framework dependencies are not installed or detected."
if [[ $nodeVer != "v18."* ]] \
&& [[ $nodeVer != "v19."* ]] \
&& [[ $nodeVer != "v20."* ]] \
&& [[ $nodeVer != "v21."* ]] \
&& [[ $nodeVer != "v22."* ]]; then
PRINT FATAL "Required dependency \"node\" is using an unsupported version."
fi
if ! [ -x "$(command -v unzip)" ]; then PRINT FATAL "Required dependency \"unzip\" is not installed or detected."; fi
if ! [ -x "$(command -v node)" ]; then PRINT FATAL "Required dependency \"node\" is not installed or detected."; fi
if ! [ -x "$(command -v yarn)" ]; then PRINT FATAL "Required dependency \"yarn\" is not installed or detected."; fi
if ! [ -x "$(command -v zip)" ]; then PRINT FATAL "Required dependency \"zip\" is not installed or detected."; fi
if ! [ -x "$(command -v curl)" ]; then PRINT FATAL "Required dependency \"curl\" is not installed or detected."; fi
if ! [ -x "$(command -v php)" ]; then PRINT FATAL "Required dependency \"php\" is not installed or detected."; fi
if ! [ -x "$(command -v git)" ]; then PRINT FATAL "Required dependency \"git\" is not installed or detected."; fi
if ! [ -x "$(command -v grep)" ]; then PRINT FATAL "Required dependency \"grep\" is not installed or detected."; fi
if ! [ -x "$(command -v sed)" ]; then PRINT FATAL "Required dependency \"sed\" is not installed or detected."; fi
if ! [ -x "$(command -v awk)" ]; then PRINT FATAL "Required dependency \"awk\" is not installed or detected."; fi
if ! [ -x "$(command -v tput)" ]; then PRINT FATAL "Required dependency \"tput\" is not installed or detected."; fi
if ! [ "$(ls "node_modules/"*"cross-env"* 2> /dev/null)" ]; then PRINT FATAL "Required dependency \"cross-env\" is not installed or detected."; fi
if ! [ "$(ls "node_modules/"*"webpack"* 2> /dev/null)" ]; then PRINT FATAL "Required dependency \"webpack\" is not installed or detected."; fi
if ! [ "$(ls "node_modules/"*"react"* 2> /dev/null)" ]; then PRINT FATAL "Required dependency \"react\" is not installed or detected."; fi
if [[ $missinglibs == *"[parse_yaml]"* ]]; then PRINT FATAL "Required internal dependency \"internal:parse_yaml\" is not installed or detected."; fi
if [[ $missinglibs == *"[grabEnv]"* ]]; then PRINT FATAL "Required internal dependency \"internal:grabEnv\" is not installed or detected."; fi
if [[ $missinglibs == *"[logFormat]"* ]]; then PRINT FATAL "Required internal dependency \"internal:logFormat\" is not installed or detected."; fi
if [[ $missinglibs == *"[misc]"* ]]; then PRINT FATAL "Required internal dependency \"internal:misc\" is not installed or detected."; fi
exit 1
fi
}
# Assign variables for extension flags.
assignflags() {
F_ignorePlaceholders=false
F_forceLegacyPlaceholders=false
F_hasInstallScript=false
F_hasRemovalScript=false
F_hasExportScript=false
F_developerIgnoreInstallScript=false
F_developerIgnoreRebuild=false
F_developerForceMigrate=false
F_developerKeepApplicationCache=false
F_developerEscalateExportScript=false
if [[ ( $flags == *"ignorePlaceholders,"* ) || ( $flags == *"ignorePlaceholders" ) ]]; then F_ignorePlaceholders=true ;fi
if [[ ( $flags == *"forceLegacyPlaceholders,"* ) || ( $flags == *"forceLegacyPlaceholders" ) ]]; then F_forceLegacyPlaceholders=true ;fi
if [[ ( $flags == *"hasInstallScript,"* ) || ( $flags == *"hasInstallScript" ) ]]; then F_hasInstallScript=true ;fi
if [[ ( $flags == *"hasRemovalScript,"* ) || ( $flags == *"hasRemovalScript" ) ]]; then F_hasRemovalScript=true ;fi
if [[ ( $flags == *"hasExportScript,"* ) || ( $flags == *"hasExportScript" ) ]]; then F_hasExportScript=true ;fi
if [[ ( $flags == *"developerIgnoreInstallScript,"* ) || ( $flags == *"developerIgnoreInstallScript" ) ]]; then F_developerIgnoreInstallScript=true ;fi
if [[ ( $flags == *"developerIgnoreRebuild,"* ) || ( $flags == *"developerIgnoreRebuild" ) ]]; then F_developerIgnoreRebuild=true ;fi
if [[ ( $flags == *"developerForceMigrate,"* ) || ( $flags == *"developerForceMigrate" ) ]]; then F_developerForceMigrate=true ;fi
if [[ ( $flags == *"developerKeepApplicationCache,"* ) || ( $flags == *"developerKeepApplicationCache" ) ]]; then F_developerKeepApplicationCache=true ;fi
if [[ ( $flags == *"developerEscalateExportScript,"* ) || ( $flags == *"developerEscalateExportScript" ) ]]; then F_developerEscalateExportScript=true ;fi
}
# Adds the "blueprint" command to the /usr/local/bin directory and configures the correct permissions for it.
if ! [ -x "$(command -v blueprint)" ]; then
PRINT INFO "Placing Blueprint command shortcut.."
{
touch /usr/local/bin/blueprint
chmod u+x \
"$FOLDER/blueprint.sh" \
/usr/local/bin/blueprint
} >> "$BLUEPRINT__DEBUG"
echo -e "#!/bin/bash\nbash $FOLDER/blueprint.sh -bash \$@;" > /usr/local/bin/blueprint
fi
if [[ $1 != "-bash" ]]; then
if dbValidate "blueprint.setupFinished"; then
PRINT FATAL "Installation process has already been finished before, consider using the 'blueprint' command."
exit 2
else
# Only run if Blueprint is not in the process of upgrading.
if [[ $1 != "--post-upgrade" ]]; then
# Print Blueprint icon with ascii characters.
echo -e " ██\n██ ██\n ████\n";
fi
PRINT INFO "Searching and validating framework dependencies.."
# Check if required dependencies are installed
depend
# Link directories.
PRINT INFO "Linking directories and filesystems.."
{
ln -s -r -T "$FOLDER/.blueprint/extensions/blueprint/public" "$FOLDER/public/extensions/blueprint"
ln -s -r -T "$FOLDER/.blueprint/extensions/blueprint/assets" "$FOLDER/public/assets/extensions/blueprint"
} 2>> "$BLUEPRINT__DEBUG"
php artisan storage:link &>> "$BLUEPRINT__DEBUG"
PRINT INFO "Replacing internal placeholders.."
# Copy "Blueprint" extension page logo from assets.
cp "$FOLDER/.blueprint/assets/logo.jpg" "$FOLDER/.blueprint/extensions/blueprint/assets/logo.jpg"
# Put application into maintenance.
PRINT INPUT "Would you like to put your application into maintenance while Blueprint is installing? (Y/n)"
read -r YN
if [[ ( $YN == "y"* ) || ( $YN == "Y"* ) || ( $YN == "" ) ]]; then
MAINTENANCE=true
PRINT INFO "Put application into maintenance mode."
php artisan down &>> "$BLUEPRINT__DEBUG"
else
MAINTENANCE=false
PRINT INFO "Putting application into maintenance has been skipped."
fi
# Flush cache.
PRINT INFO "Flushing view, config and route cache.."
{
php artisan view:cache
php artisan config:cache
php artisan route:clear
php artisan cache:clear
} &>> "$BLUEPRINT__DEBUG"
updateCacheReminder
# Run migrations if Blueprint is not upgrading.
if [[ ( $1 != "--post-upgrade" ) && ( $DOCKER != "y" ) ]]; then
PRINT INPUT "Would you like to migrate your database? (Y/n)"
read -r YN
if [[ ( $YN == "y"* ) || ( $YN == "Y"* ) || ( $YN == "" ) ]]; then
PRINT INFO "Running database migrations.."
php artisan migrate --force
else
PRINT INFO "Database migrations have been skipped."
fi
fi
# Make sure all files have correct permissions.
PRINT INFO "Changing Pterodactyl file ownership to '$OWNERSHIP'.."
find "$FOLDER/" \
-path "$FOLDER/node_modules" -prune \
-o -exec chown "$OWNERSHIP" {} + &>> "$BLUEPRINT__DEBUG"
# Rebuild panel assets.
PRINT INFO "Rebuilding panel assets.."
yarn run build:production --progress
if [[ $DOCKER != "y" ]] && ! $MAINTENANCE; then
# Put application into production.
PRINT INFO "Put application into production."
php artisan up &>> "$BLUEPRINT__DEBUG"
fi
if [[ $DOCKER != "y" ]]; then
# Sync some database values.
PRINT INFO "Syncing Blueprint-related database values.."
php artisan bp:sync
fi
# Finish installation
if [[ $1 != "--post-upgrade" ]]; then
PRINT SUCCESS "Blueprint has completed its installation process."
fi
dbAdd "blueprint.setupFinished"
# Let the panel know the user has finished installation.
sed -i "s/NOTINSTALLED/INSTALLED/g" "$FOLDER/app/BlueprintFramework/Services/PlaceholderService/BlueprintPlaceholderService.php"
exit 0
fi
fi
# help, -help, --help,
# h, -h, --h
if [[ ( $2 == "help" ) || ( $2 == "-help" ) || ( $2 == "--help" ) ||
( $2 == "h" ) || ( $2 == "-h" ) || ( $2 == "--h" ) || ( $2 == "" ) ]]; then VCMD="y"
if dbValidate "blueprint.developerEnabled"; then
help_dev_status=""
help_dev_primary="\e[34;1m"
help_dev_secondary="\e[34m"
else
help_dev_status=" (disabled)"
help_dev_primary="\x1b[2;1m"
help_dev_secondary="\x1b[2m"
fi
echo -e "
\x1b[34;1mExtensions\x1b[0m\x1b[34m
-install [name] -add -i install/update a blueprint extension
-remove [name] -r remove a blueprint extension
\x1b[0m
${help_dev_primary}Developer${help_dev_status}\x1b[0m${help_dev_secondary}
-init -I initialize development files
-build -b install/update your development files
-export (expose) -e export/download your development files
-wipe -w remove your development files
\x1b[0m
\x1b[34;1mMisc\x1b[0m\x1b[34m
-version -v returns the blueprint version
-help -h displays this menu
-info -f show neofetch-like information about blueprint
-debug [lines] print given amount of debug lines
\x1b[0m
\x1b[34;1mAdvanced\x1b[0m\x1b[34m
-upgrade (remote <url>) update/reset to another release
-rerun-install rerun the blueprint installation script
\x1b[0m
"
fi
# -i, -install, -add
if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="y"
if [[ $(( $# - 2 )) != 1 ]]; then PRINT FATAL "Expected 1 argument but got $(( $# - 2 )).";exit 2;fi
if [[ ( $3 == "./"* ) || ( $3 == "../"* ) || ( $3 == "/"* ) ]]; then PRINT FATAL "Cannot import extensions from external paths.";exit 2;fi
PRINT INFO "Searching and validating framework dependencies.."
# Check if required programs and libraries are installed.
depend
# The following code does some magic to allow for extensions with a
# different root folder structure than expected by Blueprint.
if [[ $3 == "[developer-build]" ]]; then
dev=true
n="dev"
mkdir -p ".blueprint/tmp/dev"
cp -R ".blueprint/dev/"* ".blueprint/tmp/dev/"
else
dev=false
n="$3"
if [[ $n == *".blueprint" ]]; then n="${n::-10}";fi
FILE="${n}.blueprint"
if [[ ! -f "$FILE" ]]; then PRINT FATAL "$FILE could not be found or detected.";exit 2;fi
ZIP="${n}.zip"
cp "$FILE" ".blueprint/tmp/$ZIP"
cd ".blueprint/tmp" || cdhalt
unzip -o -qq "$ZIP"
rm "$ZIP"
if [[ ! -f "$n/*" ]]; then
cd ".." || cdhalt
rm -R "tmp"
mkdir -p "tmp"
cd "tmp" || cdhalt
mkdir -p "./$n"
cp "../../$FILE" "./$n/$ZIP"
cd "$n" || cdhalt
unzip -o -qq "$ZIP"
rm "$ZIP"
cd ".." || cdhalt
fi
fi
# Return to the Pterodactyl installation folder.
cd "$FOLDER" || cdhalt
# Get all strings from the conf.yml file and make them accessible as variables.
if [[ ! -f ".blueprint/tmp/$n/conf.yml" ]]; then
# Quit if the extension doesn't have a conf.yml file.
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Extension configuration file not found or detected."
exit 1
fi
eval "$(parse_yaml .blueprint/tmp/"${n}"/conf.yml conf_)"
# Add aliases for config values to make working with them easier.
name="${conf_info_name//&/\\&}"
identifier="${conf_info_identifier//&/\\&}"
description="${conf_info_description//&/\\&}"
flags="${conf_info_flags//&/\\&}" #(optional)
version="${conf_info_version//&/\\&}"
target="${conf_info_target//&/\\&}"
author="${conf_info_author//&/\\&}" #(optional)
icon="${conf_info_icon//&/\\&}" #(optional)
website="${conf_info_website//&/\\&}"; #(optional)
admin_view="$conf_admin_view"
admin_controller="$conf_admin_controller"; #(optional)
admin_css="$conf_admin_css"; #(optional)
admin_wrapper="$conf_admin_wrapper"; #(optional)
dashboard_css="$conf_dashboard_css"; #(optional)
dashboard_wrapper="$conf_dashboard_wrapper"; #(optional)
dashboard_components="$conf_dashboard_components"; #(optional)
data_directory="$conf_data_directory"; #(optional)
data_public="$conf_data_public"; #(optional)
data_console="$conf_data_console"; #(optional)
requests_views="$conf_requests_views"; #(optional)
requests_controllers="$conf_requests_controllers"; #(optional)
requests_routers="$conf_requests_routers"; #(optional)
requests_routers_application="$conf_requests_routers_application"; #(optional)
requests_routers_client="$conf_requests_routers_client"; #(optional)
requests_routers_web="$conf_requests_routers_web"; #(optional)
database_migrations="$conf_database_migrations"; #(optional)
# assign config aliases
if [[ $requests_routers_application == "" ]] \
&& [[ $requests_routers_client == "" ]] \
&& [[ $requests_routers_web == "" ]] \
&& [[ $requests_routers != "" ]]; then
requests_routers_application="$requests_routers"
fi
# "prevent" folder "escaping"
if [[ ( $icon == "/"* ) || ( $icon == *"/.."* ) || ( $icon == *"../"* ) || ( $icon == *"/../"* ) || ( $icon == *"~"* ) || ( $icon == *"\\"* ) ]] \
|| [[ ( $admin_view == "/"* ) || ( $admin_view == *"/.."* ) || ( $admin_view == *"../"* ) || ( $admin_view == *"/../"* ) || ( $admin_view == *"~"* ) || ( $admin_view == *"\\"* ) ]] \
|| [[ ( $admin_controller == "/"* ) || ( $admin_controller == *"/.."* ) || ( $admin_controller == *"../"* ) || ( $admin_controller == *"/../"* ) || ( $admin_controller == *"~"* ) || ( $admin_controller == *"\\"* ) ]] \
|| [[ ( $admin_css == "/"* ) || ( $admin_css == *"/.."* ) || ( $admin_css == *"../"* ) || ( $admin_css == *"/../"* ) || ( $admin_css == *"~"* ) || ( $admin_css == *"\\"* ) ]] \
|| [[ ( $admin_wrapper == "/"* ) || ( $admin_wrapper == *"/.."* ) || ( $admin_wrapper == *"../"* ) || ( $admin_wrapper == *"/../"* ) || ( $admin_wrapper == *"~"* ) || ( $admin_wrapper == *"\\"* ) ]] \
|| [[ ( $dashboard_css == "/"* ) || ( $dashboard_css == *"/.."* ) || ( $dashboard_css == *"../"* ) || ( $dashboard_css == *"/../"* ) || ( $dashboard_css == *"~"* ) || ( $dashboard_css == *"\\"* ) ]] \
|| [[ ( $dashboard_wrapper == "/"* ) || ( $dashboard_wrapper == *"/.."* ) || ( $dashboard_wrapper == *"../"* ) || ( $dashboard_wrapper == *"/../"* ) || ( $dashboard_wrapper == *"~"* ) || ( $dashboard_wrapper == *"\\"* ) ]] \
|| [[ ( $dashboard_components == "/"* ) || ( $dashboard_components == *"/.."* ) || ( $dashboard_components == *"../"* ) || ( $dashboard_components == *"/../"* ) || ( $dashboard_components == *"~"* ) || ( $dashboard_components == *"\\"* ) ]] \
|| [[ ( $data_directory == "/"* ) || ( $data_directory == *"/.."* ) || ( $data_directory == *"../"* ) || ( $data_directory == *"/../"* ) || ( $data_directory == *"~"* ) || ( $data_directory == *"\\"* ) ]] \
|| [[ ( $data_public == "/"* ) || ( $data_public == *"/.."* ) || ( $data_public == *"../"* ) || ( $data_public == *"/../"* ) || ( $data_public == *"~"* ) || ( $data_public == *"\\"* ) ]] \
|| [[ ( $data_console == "/"* ) || ( $data_console == *"/.."* ) || ( $data_console == *"../"* ) || ( $data_console == *"/../"* ) || ( $data_console == *"~"* ) || ( $data_console == *"\\"* ) ]] \
|| [[ ( $requests_views == "/"* ) || ( $requests_views == *"/.."* ) || ( $requests_views == *"../"* ) || ( $requests_views == *"/../"* ) || ( $requests_views == *"~"* ) || ( $requests_views == *"\\"* ) ]] \
|| [[ ( $requests_controllers == "/"* ) || ( $requests_controllers == *"/.."* ) || ( $requests_controllers == *"../"* ) || ( $requests_controllers == *"/../"* ) || ( $requests_controllers == *"~"* ) || ( $requests_controllers == *"\\"* ) ]] \
|| [[ ( $requests_routers_application == "/"* ) || ( $requests_routers_application == *"/.."* ) || ( $requests_routers_application == *"../"* ) || ( $requests_routers_application == *"/../"* ) || ( $requests_routers_application == *"~"* ) || ( $requests_routers_application == *"\\"* ) ]] \
|| [[ ( $requests_routers_client == "/"* ) || ( $requests_routers_client == *"/.."* ) || ( $requests_routers_client == *"../"* ) || ( $requests_routers_client == *"/../"* ) || ( $requests_routers_client == *"~"* ) || ( $requests_routers_client == *"\\"* ) ]] \
|| [[ ( $requests_routers_web == "/"* ) || ( $requests_routers_web == *"/.."* ) || ( $requests_routers_web == *"../"* ) || ( $requests_routers_web == *"/../"* ) || ( $requests_routers_web == *"~"* ) || ( $requests_routers_web == *"\\"* ) ]] \
|| [[ ( $database_migrations == "/"* ) || ( $database_migrations == *"/.."* ) || ( $database_migrations == *"../"* ) || ( $database_migrations == *"/../"* ) || ( $database_migrations == *"~"* ) || ( $database_migrations == *"\\"* ) ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Config file paths cannot escape the extension bundle."
exit 1
fi
# prevent potentional problems during installation due to wrongly defined folders
if [[ ( $dashboard_components == *"/" ) ]] \
|| [[ ( $data_directory == *"/" ) ]] \
|| [[ ( $data_public == *"/" ) ]] \
|| [[ ( $data_console == *"/" ) ]] \
|| [[ ( $requests_views == *"/" ) ]] \
|| [[ ( $requests_controllers == *"/" ) ]] \
|| [[ ( $database_migrations == *"/" ) ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Directory paths in conf.yml should not end with a slash."
exit 1
fi
# check if extension still has placeholder values
if [[ ( $name == "[name]" ) || ( $identifier == "[identifier]" ) || ( $description == "[description]" ) ]] \
|| [[ ( $version == "[ver]" ) || ( $target == "[version]" ) || ( $author == "[author]" ) ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Extension contains placeholder values which need to be replaced."
exit 1
fi
# Detect if extension is already installed and prepare the upgrading process.
if [[ $(cat .blueprint/extensions/blueprint/private/db/installed_extensions) == *"$identifier,"* ]]; then
PRINT INFO "Switching to update process as extension has already been installed."
if [[ ! -d ".blueprint/extensions/$identifier/private/.store" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Upgrading extension has failed due to missing essential .store files."
exit 1
fi
eval "$(parse_yaml .blueprint/extensions/"${identifier}"/private/.store/conf.yml old_)"
DUPLICATE="y"
# Clean up some old extension files.
if [[ $old_data_public != "" ]]; then
# Clean up old public folder.
rm -R ".blueprint/extensions/$identifier/public"
mkdir ".blueprint/extensions/$identifier/public"
fi
if [[ $old_data_console != "" ]]; then
# Clean up old console folder.
rm -R \
".blueprint/extensions/$identifier/console" \
"app/Console/Commands/BlueprintFramework/Extensions/${identifier^}"
fi
fi
# Assign variables to extension flags.
PRINT INFO "Reading and assigning extension flags.."
assignflags
# Force http/https url scheme for extension website urls when needed.
if [[ $website != "" ]]; then
if [[ ( $website != "https://"* ) && ( $website != "http://"* ) ]] \
&& [[ ( $website != "/"* ) && ( $website != "."* ) ]]; then
website="http://${conf_info_website}"
conf_info_website="${website}"
fi
# Change link icon depending on website url.
websiteiconclass="bx bx-link-external"
# git
if [[ $website == *"://github.com/"* ]] || [[ $website == *"://www.github.com/"* ]] \
|| [[ $website == *"://github.com" ]] || [[ $website == *"://www.github.com" ]] \
|| [[ $website == *"://gitlab.com/"* ]] || [[ $website == *"://www.gitlab.com/"* ]] \
|| [[ $website == *"://gitlab.com" ]] || [[ $website == *"://www.gitlab.com" ]]; then websiteiconclass="bx bx-git-branch";fi
# marketplaces
if [[ $website == *"://sourcexchange.net/"* ]] || [[ $website == *"://www.sourcexchange.net/"* ]] \
|| [[ $website == *"://sourcexchange.net" ]] || [[ $website == *"://www.sourcexchange.net" ]] \
|| [[ $website == *"://builtbybit.com/"* ]] || [[ $website == *"://www.builtbybit.com/"* ]] \
|| [[ $website == *"://builtbybit.com" ]] || [[ $website == *"://www.builtbybit.com" ]] \
|| [[ $website == *"://builtbyb.it/"* ]] || [[ $website == *"://www.builtbyb.it/"* ]] \
|| [[ $website == *"://builtbyb.it" ]] || [[ $website == *"://www.builtbyb.it" ]] \
|| [[ $website == *"://bbyb.it/"* ]] || [[ $website == *"://www.bbyb.it/"* ]] \
|| [[ $website == *"://bbyb.it" ]] || [[ $website == *"://www.bbyb.it" ]]; then websiteiconclass="bx bx-store";fi
# discord
if [[ $website == *"://discord.com/"* ]] || [[ $website == *"://www.discord.com/"* ]] \
|| [[ $website == *"://discord.com" ]] || [[ $website == *"://www.discord.com" ]] \
|| [[ $website == *"://discord.gg/"* ]] || [[ $website == *"://www.discord.gg/"* ]] \
|| [[ $website == *"://discord.gg" ]] || [[ $website == *"://www.discord.gg" ]]; then websiteiconclass="bx bxl-discord-alt";fi
# patreon
if [[ $website == *"://patreon.com/"* ]] || [[ $website == *"://www.patreon.com/"* ]] \
|| [[ $website == *"://patreon.com" ]] || [[ $website == *"://www.patreon.com" ]]; then websiteiconclass="bx bxl-patreon";fi
# reddit
if [[ $website == *"://reddit.com/"* ]] || [[ $website == *"://www.reddit.com/"* ]] \
|| [[ $website == *"://reddit.com" ]] || [[ $website == *"://www.reddit.com" ]]; then websiteiconclass="bx bxl-reddit";fi
# trello
if [[ $website == *"://trello.com/"* ]] || [[ $website == *"://www.trello.com/"* ]] \
|| [[ $website == *"://trello.com" ]] || [[ $website == *"://www.trello.com" ]]; then websiteiconclass="bx bxl-trello";fi
fi
if [[ $dev == true ]]; then
mv ".blueprint/tmp/$n" ".blueprint/tmp/$identifier"
n=$identifier
fi
if ! $F_ignorePlaceholders; then
# Prepare variables for placeholders
PRINT INFO "Writing extension placeholders.."
DIR=".blueprint/tmp/$n"
INSTALL_STAMP=$(date +%s)
INSTALL_MODE="local"
if $dev; then INSTALL_MODE="develop"; fi
EXT_AUTHOR="$author"
if [[ $author == "" ]]; then EXT_AUTHOR="undefined"; fi
IS_TARGET=true
if [[ $target != "$VERSION" ]]; then IS_TARGET=false; fi
# Use either legacy or stable placeholders for backwards compatibility.
if [[ $target == "alpha-"* ]] \
|| [[ $target == "indev-"* ]] \
|| $F_forceLegacyPlaceholders; then
# (v1) Legacy placeholders
INSTALLMODE="normal"
if [[ $dev == true ]]; then INSTALLMODE="developer"; fi
PLACE_PLACEHOLDERS() {
local dir="$1"
for file in "$dir"/*; do
if [ -f "$file" ]; then
file=${file// /\\ }
sed -i \
-e "s~\^#version#\^~$version~g" \
-e "s~\^#author#\^~$author~g" \
-e "s~\^#name#\^~$name~g" \
-e "s~\^#identifier#\^~$identifier~g" \
-e "s~\^#path#\^~$FOLDER~g" \
-e "s~\^#datapath#\^~$FOLDER/.blueprint/extensions/$identifier/private~g" \
-e "s~\^#publicpath#\^~$FOLDER/.blueprint/extensions/$identifier/public~g" \
-e "s~\^#installmode#\^~$INSTALLMODE~g" \
-e "s~\^#blueprintversion#\^~$VERSION~g" \
-e "s~\^#timestamp#\^~$INSTALL_STAMP~g" \
-e "s~\^#componentroot#\^~@/blueprint/extensions/$identifier~g" \
\
-e "s~__version__~$version~g" \
-e "s~__author__~$author~g" \
-e "s~__identifier__~$identifier~g" \
-e "s~__name__~$name~g" \
-e "s~__path__~$FOLDER~g" \
-e "s~__datapath__~$FOLDER/.blueprint/extensions/$identifier/private~g" \
-e "s~__publicpath__~$FOLDER/.blueprint/extensions/$identifier/public~g" \
-e "s~__installmode__~$INSTALLMODE~g" \
-e "s~__blueprintversion__~$VERSION~g" \
-e "s~__timestamp__~$INSTALL_STAMP~g" \
-e "s~__componentroot__~@/blueprint/extensions/$identifier~g" \
"$file"
elif [ -d "$file" ]; then
PLACE_PLACEHOLDERS "$file"
fi
done
}
PLACE_PLACEHOLDERS "$DIR"
else
# (v2) Stable placeholders
PLACE_PLACEHOLDERS() {
local dir="$1"
for file in "$dir"/*; do
if [ -f "$file" ]; then
file=${file// /\\ }
# Step 1: Modify escaped placeholders to prevent them from being written to.
# Step 2: Apply normal placeholders.
# Step 3: Apply placeholders with modifiers.
# Step 4: Apply conditional placeholders.
# Step 5: Switch escaped placeholders back to their original form, without the backslash.
sed -i \
-e "s~!{identifier~{!!!!identifier~g" \
-e "s~!{name~{!!!!name~g" \
-e "s~!{author~{!!!!author~g" \
-e "s~!{version~{!!!!version~g" \
-e "s~!{random~{!!!!random~g" \
-e "s~!{timestamp~{!!!!timestamp~g" \
-e "s~!{mode~{!!!!mode~g" \
-e "s~!{target~{!!!!target~g" \
-e "s~!{root~{!!!!root~g" \
-e "s~!{webroot~{!!!!webroot~g" \
-e "s~!{is_~{!!!!is_~g" \
\
-e "s~{identifier}~$identifier~g" \
-e "s~{name}~$name~g" \
-e "s~{author}~$EXT_AUTHOR~g" \
-e "s~{version}~$version~g" \
-e "s~{random}~$RANDOM~g" \
-e "s~{timestamp}~$INSTALL_STAMP~g" \
-e "s~{mode}~$INSTALL_MODE~g" \
-e "s~{target}~$VERSION~g" \
-e "s~{root}~$FOLDER~g" \
-e "s~{webroot}~/~g" \
\
-e "s~{identifier^}~${identifier^}~g" \
-e "s~{identifier!}~${identifier^^}~g" \
-e "s~{name!}~${name^^}~g" \
-e "s~{root/public}~$FOLDER/.blueprint/extensions/$identifier/public~g" \
-e "s~{root/data}~$FOLDER/.blueprint/extensions/$identifier/private~g" \
-e "s~{webroot/public}~/extensions/$identifier~g" \
-e "s~{webroot/fs}~/fs/extensions/$identifier~g" \
\
-e "s~{is_target}~$IS_TARGET~g" \
\
-e "s~{!!!!identifier~{identifier~g" \
-e "s~{!!!!name~{name~g" \
-e "s~{!!!!author~{author~g" \
-e "s~{!!!!version~{version~g" \
-e "s~{!!!!random~{random~g" \
-e "s~{!!!!timestamp~{timestamp~g" \
-e "s~{!!!!mode~{mode~g" \
-e "s~{!!!!target~{target~g" \
-e "s~{!!!!root~{root~g" \
-e "s~{!!!!webroot~{webroot~g" \
-e "s~{!!!!is_~{is~g" \
"$file"
elif [ -d "$file" ]; then
PLACE_PLACEHOLDERS "$file"
fi
done
}
PLACE_PLACEHOLDERS "$DIR"
fi
fi
if [[ $name == "" ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "'info_name' is a required configuration option.";exit 1;fi
if [[ $identifier == "" ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "'info_identifier' is a required configuration option.";exit 1;fi
if [[ $description == "" ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "'info_description' is a required configuration option.";exit 1;fi
if [[ $version == "" ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "'info_version' is a required configuration option.";exit 1;fi
if [[ $target == "" ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "'info_target' is a required configuration option.";exit 1;fi
if [[ $admin_view == "" ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "'admin_view' is a required configuration option.";exit 1;fi
if [[ $icon == "" ]]; then PRINT WARNING "This extension does not come with an icon, consider adding one.";fi
if [[ $target != "$VERSION" ]]; then PRINT WARNING "This extension is built for version $target, but your version is $VERSION.";fi
if [[ $identifier != "$n" ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "Extension file name must be the same as your identifier. (example: identifier.blueprint)";exit 1;fi
if ! [[ $identifier =~ [a-z] ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "Extension identifier should be lowercase and only contain characters a-z.";exit 1;fi
if [[ $identifier == "blueprint" ]]; then rm -R ".blueprint/tmp/$n"; PRINT FATAL "Extensions can not have the identifier 'blueprint'.";exit 1;fi
if [[ $identifier == *" "* ]] \
|| [[ $identifier == *"-"* ]] \
|| [[ $identifier == *"_"* ]] \
|| [[ $identifier == *"."* ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Extension identifier may not contain spaces, underscores, hyphens or periods."
exit 1
fi
# Validate paths to files and directories defined in conf.yml.
if [[ ( ! -f ".blueprint/tmp/$n/$icon" ) && ( ${icon} != "" ) ]] || # file: icon (optional)
[[ ( ! -f ".blueprint/tmp/$n/$admin_view" ) ]] || # file: admin_view
[[ ( ! -f ".blueprint/tmp/$n/$admin_controller" ) && ( ${admin_controller} != "" ) ]] || # file: admin_controller (optional)
[[ ( ! -f ".blueprint/tmp/$n/$admin_css" ) && ( ${admin_css} != "" ) ]] || # file: admin_css (optional)
[[ ( ! -f ".blueprint/tmp/$n/$admin_wrapper" ) && ( ${admin_wrapper} != "" ) ]] || # file: admin_wrapper (optional)
[[ ( ! -f ".blueprint/tmp/$n/$dashboard_css" ) && ( ${dashboard_css} != "" ) ]] || # file: dashboard_css (optional)
[[ ( ! -f ".blueprint/tmp/$n/$dashboard_wrapper" ) && ( ${dashboard_wrapper} != "" ) ]] || # file: dashboard_wrapper (optional)
[[ ( ! -d ".blueprint/tmp/$n/$dashboard_components" ) && ( ${dashboard_components} != "" ) ]] || # folder: dashboard_components (optional)
[[ ( ! -d ".blueprint/tmp/$n/$data_directory" ) && ( ${data_directory} != "" ) ]] || # folder: data_directory (optional)
[[ ( ! -d ".blueprint/tmp/$n/$data_public" ) && ( ${data_public} != "" ) ]] || # folder: data_public (optional)
[[ ( ! -d ".blueprint/tmp/$n/$requests_views" ) && ( ${requests_views} != "" ) ]] || # folder: requests_views (optional)
[[ ( ! -d ".blueprint/tmp/$n/$requests_controllers" ) && ( ${requests_controllers} != "" ) ]] || # folder: requests_controllers (optional)
[[ ( ! -f ".blueprint/tmp/$n/$requests_routers_application" ) && ( ${requests_routers_application} != "" ) ]] || # file: requests_routers_application (optional)
[[ ( ! -f ".blueprint/tmp/$n/$requests_routers_client" ) && ( ${requests_routers_client} != "" ) ]] || # file: requests_routers_client (optional)
[[ ( ! -f ".blueprint/tmp/$n/$requests_routers_web" ) && ( ${requests_routers_web} != "" ) ]] || # file: requests_routers_web (optional)
[[ ( ! -d ".blueprint/tmp/$n/$database_migrations" ) && ( ${database_migrations} != "" ) ]];then # folder: database_migrations (optional)
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Extension configuration points towards one or more files that do not exist."
exit 1
fi
# Validate custom script paths.
if [[ $F_hasInstallScript == true || $F_hasRemovalScript == true || $F_hasExportScript == true ]]; then
if [[ $data_directory == "" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Install/Remove/Export script requires private folder to be enabled."
exit 1
fi
if [[ $F_hasInstallScript == true ]] && [[ ! -f ".blueprint/tmp/$n/$data_directory/install.sh" ]] \
|| [[ $F_hasRemovalScript == true ]] && [[ ! -f ".blueprint/tmp/$n/$data_directory/remove.sh" ]] \
|| [[ $F_hasExportScript == true ]] && [[ ! -f ".blueprint/tmp/$n/$data_directory/export.sh" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Install/Remove/Export script could not be found or detected, even though enabled."
exit 1
fi
fi
# Place database migrations.
if [[ $database_migrations != "" ]]; then
PRINT INFO "Cloning database migration files.."
cp -R ".blueprint/tmp/$n/$database_migrations/"* "database/migrations/" 2>> "$BLUEPRINT__DEBUG"
fi
# Place views directory.
if [[ $requests_views != "" ]]; then
PRINT INFO "Cloning and linking views directory.."
mkdir -p ".blueprint/extensions/$identifier/views"
cp -R ".blueprint/tmp/$n/$requests_views/"* ".blueprint/extensions/$identifier/views/" 2>> "$BLUEPRINT__DEBUG"
ln -s -r -T "$FOLDER/.blueprint/extensions/$identifier/views" "$FOLDER/resources/views/blueprint/extensions/$identifier" 2>> "$BLUEPRINT__DEBUG"
fi
# Place controllers directory.
if [[ $requests_controllers != "" ]]; then
PRINT INFO "Cloning and linking controllers directory.."
mkdir -p ".blueprint/extensions/$identifier/controllers"
cp -R ".blueprint/tmp/$n/$requests_controllers/"* ".blueprint/extensions/$identifier/controllers/" 2>> "$BLUEPRINT__DEBUG"
ln -s -r -T "$FOLDER/.blueprint/extensions/$identifier/controllers" "$FOLDER/app/BlueprintFramework/Extensions/$identifier" 2>> "$BLUEPRINT__DEBUG"
fi
# Place routes directory.
if [[ $requests_routers_application != "" ]] \
|| [[ $requests_routers_client != "" ]] \
|| [[ $requests_routers_web != "" ]]; then
PRINT INFO "Cloning and linking router files.."
mkdir -p ".blueprint/extensions/$identifier/routers"
if [[ $requests_routers_application != "" ]]; then
{
rm "$FOLDER/routes/blueprint/application/$identifier.php"
cp -R ".blueprint/tmp/$n/$requests_routers_application" ".blueprint/extensions/$identifier/routers/application.php"
ln -s -r -T ".blueprint/extensions/$identifier/routers/application.php" "$FOLDER/routes/blueprint/application/$identifier.php"
} 2>> "$BLUEPRINT__DEBUG"
fi
if [[ $requests_routers_client != "" ]]; then
{
rm "$FOLDER/routes/blueprint/client/$identifier.php"
cp -R ".blueprint/tmp/$n/$requests_routers_client" ".blueprint/extensions/$identifier/routers/client.php"
ln -s -r -T ".blueprint/extensions/$identifier/routers/client.php" "$FOLDER/routes/blueprint/client/$identifier.php"
} 2>> "$BLUEPRINT__DEBUG"
fi
if [[ $requests_routers_web != "" ]]; then
{
rm "$FOLDER/routes/blueprint/web/$identifier.php"
cp -R ".blueprint/tmp/$n/$requests_routers_web" ".blueprint/extensions/$identifier/routers/web.php"
ln -s -r -T ".blueprint/extensions/$identifier/routers/web.php" "$FOLDER/routes/blueprint/web/$identifier.php"
} 2>> "$BLUEPRINT__DEBUG"
fi
fi
# Place and link console directory and generate artisan files.
if [[ $data_console != "" ]]; then
PRINT INFO "Cloning and linking console directory.."
# Create console directory alongside a functions directory which would store all console functions.
# -> To avoid conflicts, we sadly have to import functions instead of giving full access to Artisan commands.
# We'll need to create a decently large BlueprintConsoleLibrary for more functionality as well, and somehow
# automatically import it into these functions.
mkdir -p \
".blueprint/extensions/$identifier/console/functions" \
"app/Console/Commands/BlueprintFramework/Extensions/${identifier^}"
cp -R ".blueprint/tmp/$n/$data_console/"* ".blueprint/extensions/$identifier/console/functions/" 2>> "$BLUEPRINT__DEBUG"
# Now we check if Console.yml exists, and if it does, create Artisan commands from options defined in Console.yml.
if [[ -f ".blueprint/tmp/$n/$data_console/Console.yml" ]]; then
# Read the Console.yml file with the "parse_yaml" library.
eval "$(parse_yaml .blueprint/tmp/"$n"/"$data_console"/Console.yml Console_)"
if [[ $DUPLICATE == "y" ]]; then eval "$(parse_yaml .blueprint/extensions/"${identifier}"/private/.store/Console.yml OldConsole_)"; fi
# Print warning if console configuration is empty - otherwise go through all options.
if [[ $Console__ == "" ]]; then
PRINT WARNING "Console configuration (Console.yml) is empty!"
else
PRINT INFO "Creating and linking console commands and schedules.."
# Create (and replace) schedules file
touch "app/BlueprintFramework/Schedules/${identifier^}Schedules.php" 2>> "$BLUEPRINT__DEBUG"
echo -e "<?php\n\n" > "app/BlueprintFramework/Schedules/${identifier^}Schedules.php"
for parent in $Console__; do
parent="${parent}_"
for child in ${!parent}; do
# Entry signature
if [[ $child == "Console_"+([0-9])"_Signature" ]]; then CONSOLE_ENTRY_SIGN="${!child}"; fi
# Entry description
if [[ $child == "Console_"+([0-9])"_Description" ]]; then CONSOLE_ENTRY_DESC="${!child}"; fi
# Entry path
if [[ $child == "Console_"+([0-9])"_Path" ]]; then CONSOLE_ENTRY_PATH="${!child}"; fi
# Entry interval
if [[ $child == "Console_"+([0-9])"_Interval" ]]; then CONSOLE_ENTRY_INTE="${!child}"; fi
done
ArtisanCommandConstructor="$__BuildDir/extensions/console/ArtisanCommandConstructor.bak"
ScheduleConstructor="$__BuildDir/extensions/console/ScheduleConstructor.bak"
{
cp "$__BuildDir/extensions/console/ArtisanCommandConstructor" "$ArtisanCommandConstructor"
cp "$__BuildDir/extensions/console/ScheduleConstructor" "$ScheduleConstructor"
} 2>> "$BLUEPRINT__DEBUG"
sed -i "s~\[id\^]~""${identifier^}""~g" $ArtisanCommandConstructor
CONSOLE_ENTRY_SIGN="${CONSOLE_ENTRY_SIGN//&/\\&}"
CONSOLE_ENTRY_DESC="${CONSOLE_ENTRY_DESC//&/\\&}"
CONSOLE_ENTRY_SIGN="${CONSOLE_ENTRY_SIGN//\'/\\\'}"
CONSOLE_ENTRY_DESC="${CONSOLE_ENTRY_DESC//\'/\\\'}"
# Console entry identifier
CONSOLE_ENTRY_IDEN=$(tr -dc '[:lower:]' < /dev/urandom | fold -w 10 | head -n 1)
CONSOLE_ENTRY_IDEN="${identifier^}${CONSOLE_ENTRY_IDEN^}"
echo -e "SIGN: $CONSOLE_ENTRY_SIGN\nDESC: $CONSOLE_ENTRY_DESC\nPATH: $CONSOLE_ENTRY_PATH\nINTE: $CONSOLE_ENTRY_INTE\nIDEN: $CONSOLE_ENTRY_IDEN" >> "$BLUEPRINT__DEBUG"
# Prevent escaping console folder.
if [[
( ${CONSOLE_ENTRY_PATH} == "/"* ) ||
( ${CONSOLE_ENTRY_PATH} == *"/.."* ) ||
( ${CONSOLE_ENTRY_PATH} == *"../"* ) ||
( ${CONSOLE_ENTRY_PATH} == *"/../"* ) ||
( ${CONSOLE_ENTRY_PATH} == *"\n"* ) ||
( ${CONSOLE_ENTRY_PATH} == *"@"* ) ||
( ${CONSOLE_ENTRY_PATH} == *"\\"* )
]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Console entry paths may not escape the console directory."
exit 1
fi
# Validate file names for console entries.
if [[ ${CONSOLE_ENTRY_PATH} != *".php" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Console entry paths may not end with a file extension other than '.php'."
exit 1
fi
# Validate file path.
if [[ ! -f ".blueprint/tmp/$n/$data_console/${CONSOLE_ENTRY_PATH}" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Console configuration points towards one or more files that do not exist."
exit 1
fi
# Return error if identifier is generated incorrectly.
if [[ $CONSOLE_ENTRY_IDEN == "" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "Failed to generate extension console entry identifier, halting process."
exit 1
fi
# Return error if console entries are defined incorrectly.
if [[ $CONSOLE_ENTRY_SIGN == "" ]] \
|| [[ $CONSOLE_ENTRY_DESC == "" ]] \
|| [[ $CONSOLE_ENTRY_INTE == "" ]]; then
rm -R ".blueprint/tmp/$n"
PRINT FATAL "One or more extension console entries appear to have undefined fields."
exit 1
fi
# Assign value to certain variables if empty/invalid
if [[ $CONSOLE_ENTRY_INTE == "" ]]; then CONSOLE_ENTRY_INTE="false"; fi
# Apply variables to contructors.
sed -i \
-e "s~\[IDENTIFIER\]~$identifier~g" \
-e "s~\[SIGNATURE\]~$CONSOLE_ENTRY_SIGN~g" \
-e "s~\[DESCRIPTION\]~$CONSOLE_ENTRY_DESC~g" \
-e "s~\[FILENAME\]~$CONSOLE_ENTRY_PATH~g" \
-e "s~__ArtisanCommand__~${CONSOLE_ENTRY_IDEN}Command~g" \
"$ArtisanCommandConstructor"
sed -i \
-e "s~\[IDENTIFIER\]~$identifier~g" \
-e "s~\[SIGNATURE\]~$CONSOLE_ENTRY_SIGN~g" \
"$ScheduleConstructor"
cp "$ArtisanCommandConstructor" "app/Console/Commands/BlueprintFramework/Extensions/${identifier^}/${CONSOLE_ENTRY_IDEN}Command.php"
# Detect schedule definition and apply it
SCHEDULE_SET=false
if [[
( $CONSOLE_ENTRY_INTE != "" ) &&
( $CONSOLE_ENTRY_INTE != "false" )
]]; then
SCHEDULE_SET="false"
ApplyConsoleInterval() {
sed -i "s~\[SCHEDULE\]~${1}()~g" "$ScheduleConstructor"
}
if [[ $CONSOLE_ENTRY_INTE == "everyMinute" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "everyMinute"; fi
if [[ $CONSOLE_ENTRY_INTE == "everyTwoMinutes" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "everyTwoMinutes"; fi
if [[ $CONSOLE_ENTRY_INTE == "everyThreeMinutes" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "everyThreeMinutes"; fi
if [[ $CONSOLE_ENTRY_INTE == "everyFourMinutes" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "everyFourMinutes"; fi
if [[ $CONSOLE_ENTRY_INTE == "everyFiveMinutes" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "everyFiveMinutes"; fi
if [[ $CONSOLE_ENTRY_INTE == "everyTenMinutes" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "everyTenMinutes"; fi
if [[ $CONSOLE_ENTRY_INTE == "everyFifteenMinutes" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "everyFifteenMinutes"; fi
if [[ $CONSOLE_ENTRY_INTE == "everyThirtyMinutes" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "everyThirtyMinutes"; fi
if [[ $CONSOLE_ENTRY_INTE == "hourly" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "hourly"; fi
if [[ $CONSOLE_ENTRY_INTE == "daily" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily"; fi
if [[ $CONSOLE_ENTRY_INTE == "weekdays" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->weekdays"; fi
if [[ $CONSOLE_ENTRY_INTE == "weekends" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->weekends"; fi
if [[ $CONSOLE_ENTRY_INTE == "sundays" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->sundays"; fi
if [[ $CONSOLE_ENTRY_INTE == "mondays" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->mondays"; fi
if [[ $CONSOLE_ENTRY_INTE == "tuesdays" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->tuesdays"; fi
if [[ $CONSOLE_ENTRY_INTE == "wednesdays" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->wednesdays"; fi
if [[ $CONSOLE_ENTRY_INTE == "thursdays" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->thursdays"; fi
if [[ $CONSOLE_ENTRY_INTE == "fridays" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->fridays"; fi
if [[ $CONSOLE_ENTRY_INTE == "saturdays" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "daily()->saturdays"; fi
if [[ $CONSOLE_ENTRY_INTE == "weekly" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "weekly"; fi
if [[ $CONSOLE_ENTRY_INTE == "monthly" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "monthly"; fi
if [[ $CONSOLE_ENTRY_INTE == "quarterly" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "quarterly"; fi
if [[ $CONSOLE_ENTRY_INTE == "yearly" ]]; then SCHEDULE_SET="true"; ApplyConsoleInterval "yearly"; fi
if [[ "$SCHEDULE_SET" == "false" ]]; then
sed -i "s~\[SCHEDULE\]~cron('$CONSOLE_ENTRY_INTE')~g" "$ScheduleConstructor"
fi
cat "$ScheduleConstructor" >> "app/BlueprintFramework/Schedules/${identifier^}Schedules.php"
fi
# Clear variables after doing all console entry stuff for a defined entry.
CONSOLE_ENTRY_SIGN=""
CONSOLE_ENTRY_DESC=""
CONSOLE_ENTRY_PATH=""
CONSOLE_ENTRY_INTE=""
CONSOLE_ENTRY_IDEN=""
rm \
"$ArtisanCommandConstructor" \
"$ScheduleConstructor" \
2>> "$BLUEPRINT__DEBUG"
done
fi
fi
fi
# Create, link and connect components directory.
if [[ $dashboard_components != "" ]]; then
YARN="y"
PRINT INFO "Cloning and linking components directory.."
mkdir -p ".blueprint/extensions/$identifier/components"
ln -s -r -T "$FOLDER/.blueprint/extensions/$identifier/components" "$FOLDER/resources/scripts/blueprint/extensions/$identifier" 2>> "$BLUEPRINT__DEBUG"
# Remove custom routes to prevent duplicates.
if [[ $DUPLICATE == "y" ]]; then
sed -i \
-e "s/\/\* ${identifier^}ImportStart \*\/.*\/\* ${identifier^}ImportEnd \*\///" \
-e "s~/\* ${identifier^}ImportStart \*/~~g" \
-e "s~/\* ${identifier^}ImportEnd \*/~~g" \