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.

132 lines
2.8 KiB

2 years ago
2 years ago
  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 "Removes a project"
  7. echo
  8. echoSubTitle "Usage:"
  9. echo
  10. echo "remove-project [shortname]"
  11. echo
  12. echo "This will remove the project and move the project files to ./.trash"
  13. echo
  14. echo "--help Prints this message"
  15. echo
  16. }
  17. help="$(getParameter "--help" false "$@")"
  18. if [ "$help" == true ] || [ "$1" == "" ]
  19. then
  20. usage
  21. exit
  22. fi
  23. shortname="$(getArgument "$1" "$(usage)" true)"
  24. customer="$(getCustomerFromShortname "$shortname")"
  25. project="$(getProjectFromShortname "$shortname")"
  26. index=false
  27. for i in "${!shortnames[@]}"
  28. do
  29. if [ "${shortnames[$i]}" == "$shortname" ]
  30. then
  31. index="$i"
  32. fi
  33. done
  34. if [ "$index" == false ]
  35. then
  36. echo
  37. echoError "Could not find project: $shortname"
  38. echo
  39. exit
  40. fi
  41. echo
  42. echoMainTitle "Remove project"
  43. echo
  44. echoSubTitle "Please verify data"
  45. echo
  46. echo "Project Path: $workspaces_dir/$customer/$project"
  47. echo "Project Data Path: $project_manager_dir/data/$customer/$project"
  48. echo
  49. confirm
  50. nr=0
  51. projects_string='';
  52. for i in "${!projects[@]}"
  53. do
  54. if [ "$i" != "$index" ]
  55. then
  56. ((nr=nr+1))
  57. projects_string+="$(echo -e "\n\t\"${projects[$i]}\" # $nr")"
  58. fi
  59. done
  60. nr=0
  61. shortnames_string='';
  62. for i in "${!shortnames[@]}"
  63. do
  64. if [ "$i" != "$index" ]
  65. then
  66. ((nr=nr+1))
  67. shortnames_string+="$(echo -e "\n\t\"${shortnames[$i]}\" # $nr")"
  68. fi
  69. done
  70. nr=0
  71. customers_string='';
  72. for i in "${!customers[@]}"
  73. do
  74. if [ "$i" != "$index" ]
  75. then
  76. ((nr=nr+1))
  77. customers_string+="$(echo -e "\n\t\"${customers[$i]}\" # $nr")"
  78. fi
  79. done
  80. cat <<- EOF > "$project_manager_dir/etc/projects"
  81. #!/bin/bash
  82. projects=($projects_string
  83. )
  84. shortnames=($shortnames_string
  85. )
  86. customers=($customers_string
  87. )
  88. EOF
  89. echo
  90. echo "Moving files to trash"
  91. customer_dir_list="$(ls -t "$project_manager_dir/data/$customer")"
  92. has_more_dirs=$(if [ "${#customer_dir_list[*]}" -gt 1 ]; then echo true; else echo false; fi)
  93. rand=$(cat /proc/sys/kernel/random/uuid)
  94. trash_path="$project_manager_dir/.trash/$rand"
  95. mkdir "$trash_path"
  96. mkdir "$trash_path/data"
  97. mkdir "$trash_path/workspace"
  98. mkdir "$trash_path/data/$customer"
  99. mkdir "$trash_path/workspace/$customer"
  100. mv "$project_manager_dir/data/$customer/$project" "$trash_path/data/$customer/$project"
  101. mv "$workspaces_dir/$customer/$project" "$trash_path/workspace/$customer/$project"
  102. if [ "$has_more_dirs" == false ]
  103. then
  104. rmdir "$project_manager_dir/data/$customer"
  105. rmdir "$workspaces_dir/$customer"
  106. fi
  107. echo
  108. echoSubTitle "Running postscripts ..."
  109. postScript "$path/bin/postscripts/commands/remove-project"
  110. postScript "$workspaces_dir/$customer/$project/bin/postscripts/commands/remove-project"
  111. echo
  112. echoSuccess "Project has been remove, (moved to ./.trash)"
  113. echo