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.

161 lines
4.0 KiB

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