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.

157 lines
4.3 KiB

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