Ein für Shopware 6 vorbereitet Systemmanagment.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
4.8 KiB

  1. #!/bin/bash
  2. ### DO NOT EDIT THIS FILE
  3. source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/etc/config"
  4. source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/etc/projects"
  5. function usage {
  6. echo
  7. echoMainTitle "Creates a new project"
  8. echo
  9. echoSubTitle "Usage:"
  10. echo
  11. echo "create-project [customer] [project] [shortname]"
  12. echo
  13. echo "The given customer and project will result in the file directory as you have setted"
  14. echo "it in project_manager/etc/projects configuration file:"
  15. echo " - workspace_dir/customer/project"
  16. echo " - data_dir/customer/project"
  17. echo "It will set a configuration file for your project to:"
  18. echo " - data_dir/customer/project/etc/config"
  19. echo
  20. echo "--help Prints this message"
  21. echo
  22. }
  23. help="$(getParameter "--help" false "$*")"
  24. if [ "$help" == true ] || [ "$1" == "" ]
  25. then
  26. usage
  27. exit
  28. fi
  29. customer=$(getArgument "$1" "$(usage)" true)
  30. project=$(getArgument "$2" "$(usage)" true)
  31. shortname=$(getArgument "$3" "$(usage)" true)
  32. for p in "${projects[@]}"
  33. do
  34. if [ "$p" == "$project" ]
  35. then
  36. echoError "Project already exists"
  37. echo
  38. exit
  39. fi
  40. done
  41. for s in "${shortnames[@]}"
  42. do
  43. if [ "$s" == "$shortname" ]
  44. then
  45. echoError "Shortname already exists"
  46. echo
  47. exit
  48. fi
  49. done
  50. echo
  51. echoMainTitle "Create project"
  52. echo
  53. echoSubTitle "Please verify data"
  54. echo
  55. echo "Project path: $workspaces_dir/$customer/$project"
  56. echo "Project data path: $project_manager_dir/data/$customer/$project"
  57. echo
  58. confirm
  59. if [ -d "$project_manager_dir/data/$customer/$project" ] || [ -d "$project_manager_dir/data/$customer/$project" ]
  60. then
  61. echo
  62. echoError "Data path already exists"
  63. echo
  64. exit
  65. fi
  66. if [ -d "$workspaces_dir/$customer/$project" ] || [ -d "$workspaces_dir/$customer/$project" ]
  67. then
  68. echo
  69. echoError "Path already exists"
  70. echo
  71. exit
  72. fi
  73. path="$project_manager_dir/data/$customer/$project"
  74. if [ ! -d "$path" ]; then mkdir -p "$path"; fi
  75. if [ ! -d "$path/.ssh" ]; then mkdir "$path/.ssh"; fi
  76. if [ ! -d "$path/backup" ]; then mkdir "$path/backup"; fi
  77. if [ ! -d "$path/backup/database" ]; then mkdir "$path/backup/database"; fi
  78. if [ ! -d "$path/bin" ]; then mkdir "$path/bin"; fi
  79. if [ ! -d "$path/bin/postscripts" ]; then mkdir "$path/bin/postscripts"; fi
  80. if [ ! -d "$path/bin/postscripts/plugins" ]; then mkdir "$path/bin/postscripts/plugins"; fi
  81. if [ ! -d "$path/bin/includes" ]; then mkdir "$path/bin/includes"; fi
  82. if [ ! -d "$path/bin/includes/plugins" ]; then mkdir "$path/bin/includes/plugins"; fi
  83. if [ ! -d "$path/etc" ]; then mkdir "$path/etc"; fi
  84. if [ ! -d "$path/etc/plugins" ]; then mkdir "$path/etc/plugins"; fi
  85. if [ ! -d "$path/shared" ]; then mkdir "$path/shared"; fi
  86. if [ ! -d "$path/shared/live" ]; then mkdir "$path/shared/live"; fi
  87. if [ ! -d "$path/shared/stage" ]; then mkdir "$path/shared/stage"; fi
  88. if [ ! -d "$path/var" ]; then mkdir "$path/var"; fi
  89. if [ ! -d "$path/var/tmp" ]; then mkdir "$path/var/tmp"; fi
  90. if [ ! -d "$path/var/latest" ]; then mkdir "$path/var/latest"; fi
  91. if [ ! -f "$path/etc/config" ]
  92. then
  93. quoted="$(sedEscape "$project_manager_dir")"
  94. cat "$project_manager_dir/etc/.config_template" | \
  95. sed "s/app_customer=''/app_customer='$customer'/" | \
  96. sed "s/app_project=''/app_project='$project'/" | \
  97. sed "s/app_project_manager_dir=''/app_project_manager_dir='$quoted'/" \
  98. > "$path/etc/config"
  99. fi
  100. plugin_path="$project_manager_dir/plugins"
  101. plugins=$(ls -t "$plugin_path")
  102. for plugin in ${plugins[*]}
  103. do
  104. etc_file="$plugin_path/$plugin/etc/.config_template"
  105. if [ -f "$etc_file" ] && [ ! -f "$path/etc/plugins/$plugin/config" ]
  106. then
  107. if [ ! -d "$path/etc/plugins/$plugin" ]
  108. then
  109. mkdir "$path/etc/plugins/$plugin"
  110. fi
  111. cp "$etc_file" "$path/etc/plugins/$plugin/config"
  112. fi
  113. done
  114. if [ ! -d "$workspaces_dir/$customer/$project" ]; then mkdir -p "$workspaces_dir/$customer/$project"; fi
  115. projects_string='';
  116. for i in "${!projects[@]}"
  117. do
  118. ((nr=i+1))
  119. projects_string+="$(echo -e "\n\t'${projects[$i]}' # $nr")"
  120. done
  121. ((nr=nr+1))
  122. projects_string+="$(echo -e "\n\t'$project' # $nr")"
  123. shortnames_string='';
  124. for i in "${!shortnames[@]}"
  125. do
  126. ((nr=i+1))
  127. shortnames_string+="$(echo -e "\n\t'${shortnames[$i]}' # $nr")"
  128. done
  129. ((nr=nr+1))
  130. shortnames_string+="$(echo -e "\n\t'$shortname' # $nr")"
  131. customers_string='';
  132. for i in "${!customers[@]}"
  133. do
  134. ((nr=i+1))
  135. customers_string+="$(echo -e "\n\t'${customers[$i]}' # $nr")"
  136. done
  137. ((nr=nr+1))
  138. customers_string+="$(echo -e "\n\t'$customer' # $nr")"
  139. cat <<- EOF > "$project_manager_dir/etc/projects"
  140. #!/bin/bash
  141. projects=($projects_string
  142. )
  143. shortnames=($shortnames_string
  144. )
  145. customers=($customers_string
  146. )
  147. EOF
  148. echo
  149. echoSubTitle "Running postscripts ..."
  150. postScript "$path/bin/postscripts/commands/create-project"
  151. postScript "$workspaces_dir/$customer/$project/bin/postscripts/commands/create-project"
  152. echo
  153. echoSuccess "Project has been created, please configure: $path/etc/*"
  154. echo