11#! /bin/bash
22
33InstallExtension () {
4- clear_tmp () {
5- rm -r " .blueprint/tmp/$n "
4+ postexit () {
5+ if [[ $1 == " cleartmp" ]]; then
6+ rm -r " .blueprint/tmp/$n "
7+ fi
8+ lock_remove
69 }
710
811 # The following code does some magic to allow for extensions with a
@@ -12,11 +15,14 @@ InstallExtension() {
1215 n=" dev"
1316 cp -r " .blueprint/dev" " .blueprint/tmp/dev"
1417
15- clear_tmp () {
16- rm -r \
17- " .blueprint/tmp/dev" \
18- " .blueprint/tmp/$n " \
19- 2> /dev/null
18+ postexit () {
19+ if [[ $1 == " cleartmp" ]]; then
20+ rm -r \
21+ " .blueprint/tmp/dev" \
22+ " .blueprint/tmp/$n " \
23+ 2> /dev/null
24+ fi
25+ lock_remove
2026 }
2127 else
2228 PRINT INFO " \x1b[34;mInstalling $1 ...\x1b[0m \x1b[37m($current /$total )\x1b[0m"
@@ -56,7 +62,7 @@ InstallExtension() {
5662 # Get all strings from the conf.yml file and make them accessible as variables.
5763 if [[ ! -f " .blueprint/tmp/$n /conf.yml" ]]; then
5864 # Quit if the extension doesn't have a conf.yml file.
59- clear_tmp
65+ postexit cleartmp
6066 PRINT FATAL " Extension configuration file not found or detected."
6167 return 1
6268 fi
@@ -130,7 +136,7 @@ InstallExtension() {
130136 || [[ ( $requests_routers_client == " /" * ) || ( $requests_routers_client == * " /.." * ) || ( $requests_routers_client == * " ../" * ) || ( $requests_routers_client == * " /../" * ) || ( $requests_routers_client == * " ~" * ) || ( $requests_routers_client == * " \\ " * ) ]] \
131137 || [[ ( $requests_routers_web == " /" * ) || ( $requests_routers_web == * " /.." * ) || ( $requests_routers_web == * " ../" * ) || ( $requests_routers_web == * " /../" * ) || ( $requests_routers_web == * " ~" * ) || ( $requests_routers_web == * " \\ " * ) ]] \
132138 || [[ ( $database_migrations == " /" * ) || ( $database_migrations == * " /.." * ) || ( $database_migrations == * " ../" * ) || ( $database_migrations == * " /../" * ) || ( $database_migrations == * " ~" * ) || ( $database_migrations == * " \\ " * ) ]]; then
133- clear_tmp
139+ postexit cleartmp
134140 PRINT FATAL " Config file paths cannot escape the extension bundle."
135141 return 1
136142 fi
@@ -145,7 +151,7 @@ InstallExtension() {
145151 || [[ ( $requests_views == * " /" ) ]] \
146152 || [[ ( $requests_app == * " /" ) ]] \
147153 || [[ ( $database_migrations == * " /" ) ]]; then
148- clear_tmp
154+ postexit cleartmp
149155 PRINT FATAL " Directory paths in conf.yml should not end with a slash."
150156 return 1
151157 fi
@@ -155,7 +161,7 @@ InstallExtension() {
155161 # check if extension still has placeholder values
156162 if [[ ( $name == " [name]" ) || ( $identifier == " [identifier]" ) || ( $description == " [description]" ) ]] \
157163 || [[ ( $version == " [ver]" ) || ( $target == " [version]" ) || ( $author == " [author]" ) ]]; then
158- clear_tmp
164+ postexit cleartmp
159165 PRINT FATAL " Extension contains placeholder values which need to be replaced."
160166 return 1
161167 fi
@@ -167,7 +173,7 @@ InstallExtension() {
167173 PRINT INFO " Switching to update process as extension has already been installed."
168174
169175 if [[ ! -d " .blueprint/extensions/$identifier /private/.store" ]]; then
170- clear_tmp
176+ postexit cleartmp
171177 PRINT FATAL " Upgrading extension has failed due to missing essential .store files."
172178 return 1
173179 fi
@@ -395,12 +401,12 @@ InstallExtension() {
395401
396402 (( PROGRESS_NOW++ ))
397403
398- if [[ $name == " " ]]; then clear_tmp ; PRINT FATAL " 'info.name' is a required configuration option." ; return 1; fi
399- if [[ $identifier == " " ]]; then clear_tmp ; PRINT FATAL " 'info.identifier' is a required configuration option." ; return 1; fi
400- if [[ $description == " " ]]; then clear_tmp ; PRINT FATAL " 'info.description' is a required configuration option." ; return 1; fi
401- if [[ $version == " " ]]; then clear_tmp ; PRINT FATAL " 'info.version' is a required configuration option." ; return 1; fi
402- if [[ $target == " " ]]; then clear_tmp ; PRINT FATAL " 'info.target' is a required configuration option." ; return 1; fi
403- if [[ $admin_view == " " ]]; then clear_tmp ; PRINT FATAL " 'admin.view' is a required configuration option." ; return 1; fi
404+ if [[ $name == " " ]]; then postexit cleartmp ; PRINT FATAL " 'info.name' is a required configuration option." ; return 1; fi
405+ if [[ $identifier == " " ]]; then postexit cleartmp ; PRINT FATAL " 'info.identifier' is a required configuration option." ; return 1; fi
406+ if [[ $description == " " ]]; then postexit cleartmp ; PRINT FATAL " 'info.description' is a required configuration option." ; return 1; fi
407+ if [[ $version == " " ]]; then postexit cleartmp ; PRINT FATAL " 'info.version' is a required configuration option." ; return 1; fi
408+ if [[ $target == " " ]]; then postexit cleartmp ; PRINT FATAL " 'info.target' is a required configuration option." ; return 1; fi
409+ if [[ $admin_view == " " ]]; then postexit cleartmp ; PRINT FATAL " 'admin.view' is a required configuration option." ; return 1; fi
404410
405411 if [[ $icon == " " ]]; then PRINT WARNING " ${identifier^} does not come with an icon, consider adding one." ; fi
406412 if [[ $target != " $VERSION " ]]; then PRINT WARNING " ${identifier^} is built for version $target , but your version is $VERSION ." ; fi
@@ -419,7 +425,7 @@ InstallExtension() {
419425 if [[ $TEST_IDENTIFIER == * " [chars]" * ]]; then TEST_IDENTIFIER_MATCHES=" true" ; PRINT FATAL " Extension identifiers should be lowercase and only contain characters a-z." ; fi
420426
421427 if [[ $TEST_IDENTIFIER_MATCHES == " true" ]]; then
422- clear_tmp
428+ postexit cleartmp
423429 return 1
424430 fi
425431 unset TEST_IDENTIFIER
@@ -445,7 +451,7 @@ InstallExtension() {
445451 [[ ( ! -f " .blueprint/tmp/$n /$requests_routers_client " ) && ( ${requests_routers_client} ! = " " ) ]] || # file: requests_routers_client (optional)
446452 [[ ( ! -f " .blueprint/tmp/$n /$requests_routers_web " ) && ( ${requests_routers_web} ! = " " ) ]] || # file: requests_routers_web (optional)
447453 [[ ( ! -d " .blueprint/tmp/$n /$database_migrations " ) && ( ${database_migrations} ! = " " ) ]]; then # folder: database_migrations (optional)
448- clear_tmp
454+ postexit cleartmp
449455 PRINT FATAL " Extension configuration points towards one or more files that do not exist."
450456 return 1
451457 fi
@@ -542,7 +548,7 @@ InstallExtension() {
542548 PRINT INFO " Creating and linking console commands and schedules.."
543549
544550 if [[ " $SYS_ENCODING " != " UTF-8" ]]; then
545- clear_tmp
551+ postexit cleartmp
546552 PRINT FATAL " System locale encoding is not UTF-8, artisan commands cannot be generated."
547553 return 1
548554 fi
@@ -596,36 +602,36 @@ InstallExtension() {
596602 ( ${CONSOLE_ENTRY_PATH} == * " @" * ) ||
597603 ( ${CONSOLE_ENTRY_PATH} == * " \\ " * )
598604 ]]; then
599- clear_tmp
605+ postexit cleartmp
600606 PRINT FATAL " Console entry paths may not escape the console directory."
601607 return 1
602608 fi
603609
604610 # Validate file names for console entries.
605611 if [[ ${CONSOLE_ENTRY_PATH} != * " .php" ]]; then
606- clear_tmp
612+ postexit cleartmp
607613 PRINT FATAL " Console entry paths may not end with a file extension other than '.php'."
608614 return 1
609615 fi
610616
611617 # Validate file path.
612618 if [[ ! -f " .blueprint/tmp/$n /$data_console /${CONSOLE_ENTRY_PATH} " ]]; then
613- clear_tmp
619+ postexit cleartmp
614620 PRINT FATAL " Console configuration points towards one or more files that do not exist."
615621 return 1
616622 fi
617623
618624 # Return error if identifier is generated incorrectly.
619625 if [[ $CONSOLE_ENTRY_IDEN == " " ]]; then
620- clear_tmp
626+ postexit cleartmp
621627 PRINT FATAL " Failed to generate extension console entry identifier, halting process."
622628 return 1
623629 fi
624630
625631 # Return error if console entries are defined incorrectly.
626632 if [[ $CONSOLE_ENTRY_SIGN == " " ]] \
627633 || [[ $CONSOLE_ENTRY_DESC == " " ]]; then
628- clear_tmp
634+ postexit cleartmp
629635 PRINT FATAL " One or more extension console entries appear to have undefined fields."
630636 return 1
631637 fi
@@ -751,7 +757,7 @@ InstallExtension() {
751757 ( $1 == * " @" * ) ||
752758 ( $1 == * " \\ " * )
753759 ]]; then
754- clear_tmp
760+ postexit cleartmp
755761 PRINT FATAL " Component file paths cannot escape the components folder."
756762 return 1
757763 fi
@@ -768,7 +774,7 @@ InstallExtension() {
768774 [[ ${1} == * " .ts" ]] ||
769775 [[ ${1} == * " .jsx" ]] ||
770776 [[ ${1} == * " .js" ]]; then
771- clear_tmp
777+ postexit cleartmp
772778 PRINT FATAL " Component paths may not end with a file extension."
773779 return 1
774780 fi
@@ -778,7 +784,7 @@ InstallExtension() {
778784 [[ ! -f " .blueprint/tmp/$n /$dashboard_components /${1} .ts" ]] &&
779785 [[ ! -f " .blueprint/tmp/$n /$dashboard_components /${1} .jsx" ]] &&
780786 [[ ! -f " .blueprint/tmp/$n /$dashboard_components /${1} .js" ]]; then
781- clear_tmp
787+ postexit cleartmp
782788 PRINT FATAL " Components configuration points towards one or more files that do not exist."
783789 return 1
784790 fi
@@ -891,7 +897,7 @@ InstallExtension() {
891897 PRINT INFO " Linking navigation routes.."
892898
893899 if [[ " $SYS_ENCODING " != " UTF-8" ]]; then
894- clear_tmp
900+ postexit cleartmp
895901 PRINT FATAL " System locale encoding is not UTF-8, navigation routes cannot be generated at this time."
896902 return 1
897903 fi
@@ -936,7 +942,7 @@ InstallExtension() {
936942
937943 # Return error if type is not defined correctly.
938944 if [[ ( $COMPONENTS_ROUTE_TYPE ! = " server" ) && ( $COMPONENTS_ROUTE_TYPE ! = " account" ) ]]; then
939- clear_tmp
945+ postexit cleartmp
940946 PRINT FATAL " Navigation route types can only be either 'server' or 'account'."
941947 return 1
942948 fi
@@ -951,7 +957,7 @@ InstallExtension() {
951957 ( ${COMPONENTS_ROUTE_COMP} == * " @" * ) ||
952958 ( ${COMPONENTS_ROUTE_COMP} == * " \\ " * )
953959 ]]; then
954- clear_tmp
960+ postexit cleartmp
955961 PRINT FATAL " Navigation route component paths may not escape the components directory."
956962 return 1
957963 fi
@@ -961,7 +967,7 @@ InstallExtension() {
961967 || [[ ${COMPONENTS_ROUTE_COMP} == * " .ts" ]] \
962968 || [[ ${COMPONENTS_ROUTE_COMP} == * " .jsx" ]] \
963969 || [[ ${COMPONENTS_ROUTE_COMP} == * " .js" ]]; then
964- clear_tmp
970+ postexit cleartmp
965971 PRINT FATAL " Navigation route component paths may not end with a file extension."
966972 return 1
967973 fi
@@ -971,14 +977,14 @@ InstallExtension() {
971977 && [[ ! -f " .blueprint/tmp/$n /$dashboard_components /${COMPONENTS_ROUTE_COMP} .ts" ]] \
972978 && [[ ! -f " .blueprint/tmp/$n /$dashboard_components /${COMPONENTS_ROUTE_COMP} .jsx" ]] \
973979 && [[ ! -f " .blueprint/tmp/$n /$dashboard_components /${COMPONENTS_ROUTE_COMP} .js" ]]; then
974- clear_tmp
980+ postexit cleartmp
975981 PRINT FATAL " Navigation route configuration points towards one or more components that do not exist."
976982 return 1
977983 fi
978984
979985 # Return error if identifier is generated incorrectly.
980986 if [[ $COMPONENTS_ROUTE_IDEN == " " ]]; then
981- clear_tmp
987+ postexit cleartmp
982988 PRINT FATAL " Failed to generate extension navigation route identifier, halting process."
983989 return 1
984990 fi
@@ -987,7 +993,7 @@ InstallExtension() {
987993 if [[ $COMPONENTS_ROUTE_PATH == " " ]] \
988994 || [[ $COMPONENTS_ROUTE_TYPE == " " ]] \
989995 || [[ $COMPONENTS_ROUTE_COMP == " " ]]; then
990- clear_tmp
996+ postexit cleartmp
991997 PRINT FATAL " One or more extension navigation routes appear to have undefined fields."
992998 return 1
993999 fi
@@ -1284,7 +1290,7 @@ InstallExtension() {
12841290 rm \
12851291 " $AdminBladeConstructor " \
12861292 " $ConfigExtensionFS "
1287- clear_tmp
1293+ postexit cleartmp
12881294
12891295 (( PROGRESS_NOW++ ))
12901296
0 commit comments