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.

180 lines
4.6 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #!/bin/bash
  2. ### DO NOT EDIT THIS FILE
  3. ssh_included=true
  4. function sshValidate {
  5. if [ "$ssh_stage_user" == "" ] || [ "$ssh_stage_domain" == "" ] || [ "$ssh_live_user" == "" ] || [ "$ssh_live_domain" == "" ]
  6. then
  7. echo >&2
  8. echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/ssh/config" >&2
  9. echo >&2
  10. exit
  11. fi
  12. if [ "$git_included" == "" ]
  13. then
  14. echo >&2
  15. echoError "Plugin \"git\" has to be included" >&2
  16. echo >&2
  17. exit
  18. fi
  19. if [ "$git_ssh_user" == "" ] || [ "$git_ssh_domain" == "" ]
  20. then
  21. echo >&2
  22. echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/git/config" >&2
  23. echo >&2
  24. exit
  25. fi
  26. }
  27. function sshGetConfig {
  28. local env=$(getArgument "$1" "Usage getEnvVar [live|stage|git] var" "live stage git")
  29. local suffix=$(getArgument "$2" "Usage getEnvVar [live|stage|git] var" true)
  30. if [ "$env" == "live" ] || [ "$env" == "stage" ]
  31. then
  32. echo "$(eval "echo \"\$ssh_${env}_$suffix\"")"
  33. else
  34. echo "$(eval "echo \"\$${env}_ssh_$suffix\"")"
  35. fi
  36. }
  37. function sshGetPrivateKey
  38. {
  39. local env=$(getArgument "$1" "Usage: sshGetPrivateKey [live|stage|git]" "live stage git")
  40. if [ "$env" == "live" ] || [ "$env" == "stage" ]
  41. then
  42. echo "$(sshGetConfig "$env" "private_key")"
  43. else
  44. echo "$ssh_private_key"
  45. fi
  46. }
  47. function sshGetPublicKey
  48. {
  49. local env=$(getArgument "$1" "Usage: addSSHPublic [live|stage|git]" "live stage git")
  50. if [ "$env" == "live" ] || [ "$env" == "stage" ]
  51. then
  52. echo "$(sshGetConfig "$env" "private_key")"
  53. else
  54. echo "$ssh_private_key"
  55. fi
  56. }
  57. function sshAddKey {
  58. local env="$(getArgument "$1" "Usage: sshAddKey [live|stage|git]" "live stage git")"
  59. local ssh_private_key="$(sshGetPrivateKey "$env")"
  60. local ssh_public_key="$(sshGetPublicKey "$env")"
  61. if [ "$ssh_private_key" != "" ] && [ "$ssh_public_key" != "" ]
  62. then
  63. if [ ! -f "$app_dir/.ssh/$env" ] && [ ! -f "$app_dir/.ssh/$env.pub" ]
  64. then
  65. sshCopyKeys "$env"
  66. fi
  67. else
  68. if [ ! -f "$app_dir/.ssh/$env" ] && [ ! -f "$app_dir/.ssh/$env.pub" ]
  69. then
  70. sshInstallKeys "$env"
  71. fi
  72. fi
  73. ssh-add "$app_dir/.ssh/$env"
  74. }
  75. function sshCopyKeys {
  76. local env=$(getArgument "$1" "Usage: sshCopyKeys [live|stage|git]" "live stage git")
  77. local ssh_private_key="$(sshGetPrivateKey "$env")"
  78. local ssh_public_key="$(sshGetPublicKey "$env")"
  79. if [ ! -f "$ssh_private_key" ] && [ ! -f "$ssh_public_key" ]
  80. then
  81. echo
  82. echoError "Configureg $env key files don't exists" >&2
  83. echo
  84. exit
  85. fi
  86. if [ -f "$app_dir/.ssh/$env" ]
  87. then
  88. echo
  89. echoError "SSH $env private key already exists" >&2
  90. echo
  91. exit
  92. fi
  93. if [ -f "$app_dir/.ssh/$env.pub" ]
  94. then
  95. echo
  96. echoError "SSH $env public key already exists" >&2
  97. echo
  98. exit
  99. fi
  100. sshCopyKey "$env" "$ssh_private_key"
  101. sshCopyKey "$env.pub" "$ssh_public_key"
  102. }
  103. function sshCopyKey {
  104. local name="$(getArgument "$1" "Usage: sshCopyKey [name] [key_path]" true)"
  105. local file="$(getArgument "$2" "Usage: sshCopyKey [name] [key_path]" true)"
  106. cp "$file" "$app_dir/.ssh/$name"
  107. chmod 0600 "$app_dir/.ssh/$name"
  108. }
  109. function sshInstallKeys {
  110. local env=$(getArgument "$1" "Usage: sshInstallKeys [live|stage|git]" "live stage git")
  111. local ssh_private_key="$(sshGetPrivateKey "$env")"
  112. local ssh_public_key="$(sshGetPublicKey "$env")"
  113. local user="$(sshGetConfig "$env" "user")"
  114. local domain="$(sshGetConfig "$env" "domain")"
  115. if [ -f "$ssh_private_key" ] && [ -f "$ssh_public_key" ]
  116. then
  117. echo
  118. echoError "Can't create $env key files, there are already some configured" >&2
  119. echo
  120. exit
  121. fi
  122. if [ -f "$app_dir/.ssh/$env" ]
  123. then
  124. echo
  125. echoError "SSH $env private key already exists" >&2
  126. echo
  127. exit
  128. fi
  129. if [ -f "$app_dir/.ssh/$env.pub" ]
  130. then
  131. echo
  132. echoError "SSH $env public key already exists" >&2
  133. echo
  134. exit
  135. fi
  136. sshGenerateKey "$env"
  137. sshCopyIdKey "$env" "$user@$domain" "$app_dir/.ssh/$env.pub"
  138. }
  139. function sshGenerateKey {
  140. local name="$(getArgument "$1" "Usage: sshGenerateKey [name]" true)"
  141. ssh-keygen -b 4096 -t rsa -f "$app_dir/.ssh/$name" -q -N ""
  142. chmod 0600 "$app_dir/.ssh/$name"
  143. chmod 0600 "$app_dir/.ssh/$name.pub"
  144. }
  145. function sshCopyIdKey {
  146. local name="$(getArgument "$1" "Usage: sshCopyKey [name] [user@host] [file]" true)"
  147. local ssh="$(getArgument "$2" "Usage: sshCopyKey [name] [user@host] [file]" true)"
  148. local file="$(getArgument "$3" "Usage: sshCopyKey [name] [user@host] [file]" true)"
  149. echo "Please enter SSH $name system password:"
  150. ssh-copy-id -i "$file" "$ssh"
  151. }