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.

166 lines
4.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #!/bin/bash
  2. if [ true != ${includes_included:-false} ]
  3. then
  4. includes_included=true
  5. function echoMainTitle {
  6. echo -e "\033[1;34m$1\033[0m"
  7. }
  8. function echoSubTitle {
  9. echo -e "\033[0;32m$1\033[0m"
  10. }
  11. function echoSelect {
  12. local select="$1"
  13. local message="$2"
  14. echo -e "\033[0;33m$select\033[0m $message"
  15. }
  16. function echoError {
  17. echo -e "\033[0;91m$1\033[0m"
  18. }
  19. function getArgument {
  20. local var=$1
  21. local errmsg=$2
  22. local allow=${3:-false}
  23. if [ "$allow" != false ] && [ "$(isAllowed "$var" "$allow")" == false ]
  24. then
  25. echo "$errmsg" >&2
  26. exit 1
  27. fi
  28. echo "$var"
  29. }
  30. function isAllowed {
  31. local var="$1"
  32. local allow="$2"
  33. local valid=true
  34. if [ "$allow" == true ] && [ "$var" == "" ]
  35. then
  36. valid=false
  37. elif [ "$allow" != false ] && [ "$allow" != true ]
  38. then
  39. allow=($allow)
  40. local found=false
  41. for i in "${!allow[@]}"
  42. do
  43. if [ "${allow[$i]}" == "$var" ]
  44. then
  45. found=true
  46. fi
  47. done
  48. if [ "$found" != true ]
  49. then
  50. valid=false
  51. fi
  52. fi
  53. echo $valid
  54. }
  55. function readConsole {
  56. local message="$1"
  57. local errmsg="$2"
  58. local allow=${3:-false}
  59. local default=${4:-""}
  60. if [ "$default" != "" ]
  61. then
  62. message="$message [d:$default]"
  63. fi
  64. read -p "$message" var
  65. var=${var:-$default}
  66. if [ "$(isAllowed "$var" "$allow")" == false ]
  67. then
  68. echo "$errmsg" >&2
  69. var=$(readConsole "$message" "$errmsg" "$allow")
  70. fi
  71. echo "$var"
  72. }
  73. function addSSHKey {
  74. local env=$(getArgument "$1" "Usage: addSSHKey [live|stage|git]" "live stage git")
  75. local ssh_key_file=$(eval "echo \"\$${env}_has_ssh_key_file\"")
  76. if [ "$ssh_key_file" != "" ]
  77. then
  78. copySSHKeys "$env"
  79. else
  80. installSSHKey "$env"
  81. fi
  82. ssh-add "$app_dir/.ssh/$env"
  83. }
  84. function copySSHKeys {
  85. local env=$(getArgument "$1" "Usage: copySSHKeys [live|stage|git]" "live stage git")
  86. local source=$(eval "echo \$${env}_ssh_key_file")
  87. local target="$app_dir/.ssh/$env"
  88. if [ -f "$source" ] && [ ! -f "$target" ]
  89. then
  90. cp "$source" "$target"
  91. chmod 0600 "$target"
  92. else
  93. echoError "Could not copy ssh key file" >&2
  94. exit 1
  95. fi
  96. if [ -f "$source.pub" ] && [ ! -f "$target.pub" ]
  97. then
  98. cp "$source.pub" "$target.pub"
  99. chmod 0600 "$target.pub"
  100. else
  101. echoError "Could not copy ssh key file" >&2
  102. exit 1
  103. fi
  104. }
  105. function installSSHKey {
  106. local env=$(getArgument "$1" "Usage: installSSHKey [live|stage|git]" "live stage git")
  107. local file=$(eval "echo \"\$${env}_ssh_key_file\"")
  108. local user=$(eval "echo \"\$${env}_ssh_user\"")
  109. local domain=$(eval "echo \"\$${env}_ssh_domain\"")
  110. if [ "$file" == "" ] && [ ! -f "$app_dir/.ssh/$env" ]
  111. then
  112. ssh-keygen -b 4096 -t rsa -f "$app_dir/.ssh/$env" -q -N ""
  113. chmod 0600 "$app_dir/.ssh/$env"
  114. chmod 0600 "$app_dir/.ssh/$env.pub"
  115. echo "Please enter SSH $env system password:"
  116. ssh-copy-id -i "$app_dir/.ssh/$env.pub" "$user"@"$domain"
  117. fi
  118. }
  119. function buildIgnoredTablesArguments {
  120. local env=$(getArgument "$1" "Usage: buildIgnoredTables [live|stage|local] [ignoredTablesArray]" "live stage local")
  121. local ignoredTables=$(getArgument "$2" "Usage: buildIgnoredTables [live|stage|local] [ignoredTablesArray]" true)
  122. local database_name=$(eval "echo \"\$${env}_database_name\"")
  123. ignoredTables=($ignoredTables)
  124. local ignoredTablesArguments=""
  125. for table in "${ignoredTables[@]}"
  126. do
  127. ignoredTablesArguments="$ignoredTablesArguments --ignore-table=\"${database_name}.${table}\""
  128. done
  129. echo "$ignoredTablesArguments"
  130. }
  131. function postScript {
  132. local script=$(getArgument "$1" "Usage: postScript \"post_script.sh\"" true)
  133. if [ -f "$script" ]
  134. then
  135. source "$script"
  136. fi
  137. }
  138. fi