2 Commits
120b4c5493
...
8719b4509f
Author | SHA1 | Message | Date |
---|---|---|---|
Sven Ullmann | 8719b4509f |
Merge remote-tracking branch 'origin/master'
|
2 years ago |
Sven Ullmann | 5aa1c464bc |
refactoring
|
2 years ago |
17 changed files with 314 additions and 400 deletions
-
12plugins/git/etc/config.json
-
7plugins/git/src/includes/bash_header
-
9plugins/plesk/etc/config.json
-
26plugins/plesk/src/commands/configure-ssh
-
62plugins/plesk/src/commands/create-domain
-
10plugins/plesk/src/includes/bash_header
-
181plugins/ssh/bak/includes.sh
-
17plugins/ssh/etc/config.json
-
67plugins/ssh/src/commands/add-key
-
58plugins/ssh/src/commands/configure-ssh
-
48plugins/ssh/src/commands/install-keys
-
4plugins/ssh/src/includes/bash_header
-
140plugins/ssh/src/includes/ssh
-
9src/commands/install-plugin
-
16src/includes/configure-json-file.php
-
38src/includes/main_functions
-
10src/includes/plugin_header
@ -1,10 +1,12 @@ |
|||
{ |
|||
"git": { |
|||
"url": null, |
|||
"ssh_user": null, |
|||
"ssh_domain": null, |
|||
"ssh_private_key": null, |
|||
"ssh_public_key": null, |
|||
"ssh_private_key_passphrase": null |
|||
"ssh": { |
|||
"user": null, |
|||
"domain": null, |
|||
"private_key": null, |
|||
"public_key": null, |
|||
"private_key_passphrase": null |
|||
} |
|||
} |
|||
} |
@ -1,11 +1,6 @@ |
|||
{ |
|||
"plesk": { |
|||
"plesk_host": null, |
|||
"plesk_user": null, |
|||
"plesk_private_key": null, |
|||
"plesk_private_key_passphrase": null, |
|||
"plesk_public_key": null, |
|||
"plesk_db_type": null, |
|||
"plesk_binary": "plesk" |
|||
"servers": { |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
#!/bin/bash |
|||
|
|||
### DO NOT EDIT THIS FILE |
|||
|
|||
function usage { |
|||
echo |
|||
echoMainTitle "Configures Plesk Server Connection" |
|||
echo |
|||
echoSubTitle "Usage:" |
|||
echo |
|||
echo "project-manager plesk:configure-ssh [shortname] [plesk-name] [ssh-connection-name]" |
|||
echo |
|||
echo "--help Prints this message" |
|||
echo |
|||
} |
|||
|
|||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header" |
|||
|
|||
pleskName="$(getArgument "$2" "Plesk name required" true)" |
|||
sshConnectionName="$(getArgument "$3" "SSH connection name required" true)" |
|||
escapedPleskName=${pleskName//./\\.} |
|||
setConfig "$shortname" "plesk.servers.$escapedPleskName.ssh" "$sshConnectionName" |
|||
|
|||
echo |
|||
echoSuccess "SSH Connection ($sshConnectionName) setted for Plesk: $pleskName" |
|||
echo |
@ -0,0 +1,62 @@ |
|||
#!/bin/bash |
|||
|
|||
### DO NOT EDIT THIS FILE |
|||
|
|||
function usage { |
|||
echo |
|||
echoMainTitle "Creates a domain on plesk server" |
|||
echo |
|||
echoSubTitle "Usage:" |
|||
echo |
|||
echo "project-manager plesk:create-domain [shortname] [domain]" |
|||
echo |
|||
echo "--help Prints this message" |
|||
echo |
|||
} |
|||
|
|||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header" |
|||
domain="$(getArgument "$2" "domain required" true)" |
|||
escapedDomain=${domain//./\\.} |
|||
host="$(getConfig "$shortname" "ssh.servers.$escapedDomain.host")" |
|||
user="$(getConfig "$shortname" "ssh.servers.$escapedDomain.user")" |
|||
port="$(getConfig "$shortname" "ssh.servers.$escapedDomain.port")" |
|||
|
|||
split=($(echo $domain | tr "." "\n")) |
|||
count="${#split[@]}" |
|||
((length=$count-2)) |
|||
sub='' |
|||
for i in "${!split[@]}" |
|||
do |
|||
((j=$i+1)) |
|||
if [ "$j" -lt "$length" ] |
|||
then |
|||
sub+="${split[$i]}." |
|||
fi |
|||
if [ "$j" -eq "$length" ] |
|||
then |
|||
sub+="${split[$i]}" |
|||
fi |
|||
done |
|||
domain="$(echo "$domain" | sed "s/$(sedEscape "$sub")\.//")" |
|||
|
|||
echo |
|||
echoMainTitle "Adding domain on plesk server" |
|||
echo |
|||
echoSubTitle "Please verify data" |
|||
echo |
|||
echo "-- $env" |
|||
echo "Domain: $domain" |
|||
echo "Sub: $sub" |
|||
echo |
|||
echo "Plesk host: $host" |
|||
echo "Plesk user: $user" |
|||
echo |
|||
confirm |
|||
|
|||
pleskAddSSHKey |
|||
|
|||
ssh "$user@$host" "plesk bin subdomain --create '$sub' -domain '$domain' -www-root '/$sub.$domain'" |
|||
|
|||
echo |
|||
echoSuccess "Subdomain has been created on plesk" |
|||
echo |
@ -0,0 +1,10 @@ |
|||
#!/bin/bash |
|||
|
|||
### DO NOT EDIT THIS FILE |
|||
|
|||
source "$project_manager_dir/src/includes/bash_header" |
|||
|
|||
shortname="$(getArgument "$1" "shortname required" true)" |
|||
escapedShortname=${shortname//./\\.} |
|||
customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")" |
|||
project="$(getConfig false "project_manager.projects.$escapedShortname.project")" |
@ -1,181 +0,0 @@ |
|||
#!/bin/bash |
|||
|
|||
### DO NOT EDIT THIS FILE |
|||
|
|||
ssh_included=true |
|||
|
|||
function sshValidate { |
|||
if [ "$ssh_stage_user" == "" ] || [ "$ssh_stage_domain" == "" ] || [ "$ssh_live_user" == "" ] || [ "$ssh_live_domain" == "" ] |
|||
then |
|||
echo >&2 |
|||
echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/ssh/config" >&2 |
|||
echo >&2 |
|||
exit |
|||
fi |
|||
|
|||
if [ "$git_included" == "" ] |
|||
then |
|||
echo >&2 |
|||
echoError "Plugin \"git\" has to be included" >&2 |
|||
echo >&2 |
|||
exit |
|||
fi |
|||
|
|||
if [ "$git_ssh_user" == "" ] || [ "$git_ssh_domain" == "" ] |
|||
then |
|||
echo >&2 |
|||
echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/git/config" >&2 |
|||
echo >&2 |
|||
exit |
|||
fi |
|||
} |
|||
|
|||
|
|||
function sshGetConfig { |
|||
local env=$(getArgument "$1" "Usage getEnvVar [live|stage|git] var" "live stage git") |
|||
local suffix=$(getArgument "$2" "Usage getEnvVar [live|stage|git] var" true) |
|||
|
|||
if [ "$env" == "live" ] || [ "$env" == "stage" ] |
|||
then |
|||
echo "$(eval "echo \"\$ssh_${env}_$suffix\"")" |
|||
else |
|||
echo "$(eval "echo \"\$${env}_ssh_$suffix\"")" |
|||
fi |
|||
} |
|||
|
|||
function sshGetPrivateKey |
|||
{ |
|||
local env=$(getArgument "$1" "Usage: sshGetPrivateKey [live|stage|git]" "live stage git") |
|||
|
|||
if [ "$env" == "live" ] || [ "$env" == "stage" ] |
|||
then |
|||
echo "$(sshGetConfig "$env" "private_key")" |
|||
else |
|||
echo "$ssh_private_key" |
|||
fi |
|||
} |
|||
|
|||
function sshGetPublicKey |
|||
{ |
|||
local env=$(getArgument "$1" "Usage: addSSHPublic [live|stage|git]" "live stage git") |
|||
|
|||
if [ "$env" == "live" ] || [ "$env" == "stage" ] |
|||
then |
|||
echo "$(sshGetConfig "$env" "private_key")" |
|||
else |
|||
echo "$ssh_private_key" |
|||
fi |
|||
} |
|||
|
|||
function sshAddKey { |
|||
local env="$(getArgument "$1" "Usage: sshAddKey [live|stage|git]" "live stage git")" |
|||
local ssh_private_key="$(sshGetPrivateKey "$env")" |
|||
local ssh_public_key="$(sshGetPublicKey "$env")" |
|||
|
|||
if [ "$ssh_private_key" != "" ] && [ "$ssh_public_key" != "" ] |
|||
then |
|||
if [ ! -f "$app_dir/.ssh/$env" ] && [ ! -f "$app_dir/.ssh/$env.pub" ] |
|||
then |
|||
sshCopyKeys "$env" |
|||
fi |
|||
else |
|||
if [ ! -f "$app_dir/.ssh/$env" ] && [ ! -f "$app_dir/.ssh/$env.pub" ] |
|||
then |
|||
sshInstallKeys "$env" |
|||
fi |
|||
fi |
|||
ssh-add "$app_dir/.ssh/$env" |
|||
} |
|||
|
|||
function sshCopyKeys { |
|||
local env=$(getArgument "$1" "Usage: sshCopyKeys [live|stage|git]" "live stage git") |
|||
local ssh_private_key="$(sshGetPrivateKey "$env")" |
|||
local ssh_public_key="$(sshGetPublicKey "$env")" |
|||
|
|||
if [ ! -f "$ssh_private_key" ] && [ ! -f "$ssh_public_key" ] |
|||
then |
|||
echo |
|||
echoError "Configureg $env key files don't exists" >&2 |
|||
echo |
|||
exit |
|||
fi |
|||
|
|||
if [ -f "$app_dir/.ssh/$env" ] |
|||
then |
|||
echo |
|||
echoError "SSH $env private key already exists" >&2 |
|||
echo |
|||
exit |
|||
fi |
|||
|
|||
if [ -f "$app_dir/.ssh/$env.pub" ] |
|||
then |
|||
echo |
|||
echoError "SSH $env public key already exists" >&2 |
|||
echo |
|||
exit |
|||
fi |
|||
|
|||
sshCopyKey "$env" "$ssh_private_key" |
|||
sshCopyKey "$env.pub" "$ssh_public_key" |
|||
} |
|||
|
|||
function sshCopyKey { |
|||
local name="$(getArgument "$1" "Usage: sshCopyKey [name] [key_path]" true)" |
|||
local file="$(getArgument "$2" "Usage: sshCopyKey [name] [key_path]" true)" |
|||
|
|||
cp "$file" "$app_dir/.ssh/$name" |
|||
chmod 0600 "$app_dir/.ssh/$name" |
|||
} |
|||
|
|||
function sshInstallKeys { |
|||
local env=$(getArgument "$1" "Usage: sshInstallKeys [live|stage|git]" "live stage git") |
|||
local ssh_private_key="$(sshGetPrivateKey "$env")" |
|||
local ssh_public_key="$(sshGetPublicKey "$env")" |
|||
local user="$(sshGetConfig "$env" "user")" |
|||
local domain="$(sshGetConfig "$env" "domain")" |
|||
|
|||
if [ -f "$ssh_private_key" ] && [ -f "$ssh_public_key" ] |
|||
then |
|||
echo |
|||
echoError "Can't create $env key files, there are already some configured" >&2 |
|||
echo |
|||
exit |
|||
fi |
|||
|
|||
if [ -f "$app_dir/.ssh/$env" ] |
|||
then |
|||
echo |
|||
echoError "SSH $env private key already exists" >&2 |
|||
echo |
|||
exit |
|||
fi |
|||
|
|||
if [ -f "$app_dir/.ssh/$env.pub" ] |
|||
then |
|||
echo |
|||
echoError "SSH $env public key already exists" >&2 |
|||
echo |
|||
exit |
|||
fi |
|||
|
|||
sshGenerateKey "$env" |
|||
sshCopyIdKey "$env" "$user@$domain" "$app_dir/.ssh/$env.pub" |
|||
} |
|||
|
|||
function sshGenerateKey { |
|||
local name="$(getArgument "$1" "Usage: sshGenerateKey [name]" true)" |
|||
|
|||
ssh-keygen -b 4096 -t rsa -f "$app_dir/.ssh/$name" -q -N "" |
|||
chmod 0600 "$app_dir/.ssh/$name" |
|||
chmod 0600 "$app_dir/.ssh/$name.pub" |
|||
} |
|||
|
|||
function sshCopyIdKey { |
|||
local name="$(getArgument "$1" "Usage: sshCopyKey [name] [user@host] [file]" true)" |
|||
local ssh="$(getArgument "$2" "Usage: sshCopyKey [name] [user@host] [file]" true)" |
|||
local file="$(getArgument "$3" "Usage: sshCopyKey [name] [user@host] [file]" true)" |
|||
|
|||
echo "Please enter SSH $name system password:" |
|||
ssh-copy-id -i "$file" "$ssh" |
|||
} |
@ -1,20 +1,5 @@ |
|||
{ |
|||
"ssh": { |
|||
"stage": { |
|||
"user": null, |
|||
"domain": null, |
|||
"port": null, |
|||
"private_key": null, |
|||
"public_key": null, |
|||
"key_passphrase": null |
|||
}, |
|||
"live": { |
|||
"user": null, |
|||
"domain": null, |
|||
"port": null, |
|||
"private_key": null, |
|||
"public_key": null, |
|||
"key_passphrase": null |
|||
} |
|||
"servers": {} |
|||
} |
|||
} |
@ -1,67 +0,0 @@ |
|||
#!/bin/bash |
|||
|
|||
### DO NOT EDIT THIS FILE |
|||
|
|||
function usage { |
|||
echo |
|||
echoMainTitle "Create, move the ssh keys and install them to server" |
|||
echo |
|||
echoSubTitle "Usage:" |
|||
echo |
|||
echo "project-manager ssh:add-key [project-shortname] [env]" |
|||
echo |
|||
echo " [env] could be live, stage or git" |
|||
echo |
|||
echo "--help Prints this message" |
|||
echo |
|||
} |
|||
|
|||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header" |
|||
env="$(getArgument "$2" "$(usage)" "live stage git")" |
|||
sshValidate |
|||
|
|||
ssh_private_key="$(sshGetConfig "$env" "private_key")" |
|||
ssh_public_key="$(sshGetConfig "$env" "public_key")" |
|||
ssh_user="$(sshGetConfig "$env" "user")" |
|||
ssh_domain="$(sshGetConfig "$env" "domain")" |
|||
|
|||
echo |
|||
echoMainTitle "Adding SSH Keys" |
|||
echo |
|||
echoSubTitle "Please verify data" |
|||
echo |
|||
echo "-- $env" |
|||
echo "Private key: $ssh_private_key" |
|||
echo "Public key: $ssh_public_key" |
|||
echo |
|||
confirm |
|||
|
|||
if [ "$ssh_private_key" != "" ] |
|||
then |
|||
target="$app_dir/.ssh/$env" |
|||
if [ -f "$source" ] && [ ! -f "$target" ] |
|||
then |
|||
cp "$ssh_private_key" "target" |
|||
chmod 0600 "$target" |
|||
fi |
|||
fi |
|||
|
|||
if [ "$ssh_public_key" != "" ] |
|||
then |
|||
target="$app_dir/.ssh/$env.pub" |
|||
if [ -f "$source" ] && [ ! -f "$target" ] |
|||
then |
|||
cp "$ssh_public_key" "target" |
|||
chmod 0600 "$target" |
|||
fi |
|||
fi |
|||
|
|||
if [ "$ssh_private_key" == "" ] && [ "$ssh_public_key" == "" ] && [ ! -f "$app_dir/.ssh/$env" ] && [ ! -f "$app_dir/.ssh/$env.pub" ] |
|||
then |
|||
ssh-keygen -b 4096 -t rsa -f "$app_dir/.ssh/$env" -q -N "" |
|||
chmod 0600 "$app_dir/.ssh/$env" |
|||
chmod 0600 "$app_dir/.ssh/$env.pub" |
|||
ssh-copy-id -i "$app_dir/.ssh/$env.pub" "$ssh_user"@"$ssh_domain" |
|||
fi |
|||
|
|||
ssh-add "$app_dir/.ssh/$env" |
@ -0,0 +1,58 @@ |
|||
#!/bin/bash |
|||
|
|||
### DO NOT EDIT THIS FILE |
|||
|
|||
function usage { |
|||
echo |
|||
echoMainTitle "Configure Plugin SSH Domain" |
|||
echo |
|||
echoSubTitle "Usage:" |
|||
echo |
|||
echo "project-manager ssh:configure-ssh [shortname] [ssh-connection-name]" |
|||
echo |
|||
echo "--help Prints this message" |
|||
echo |
|||
} |
|||
|
|||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header" |
|||
|
|||
sshConnectionName="$(getArgument "$2" "SSH connection name required" true)" |
|||
escapedSSHConnectionName=${sshConnectionName//./\\.} |
|||
user="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.user")" |
|||
host="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.host")" |
|||
port="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.port")" |
|||
privateKey="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.private_key")" |
|||
publicKey="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.public_key")" |
|||
|
|||
echo |
|||
echoMainTitle "Configure SSH Connection" |
|||
echo |
|||
echoSubTitle "Please configure ssh connection: $sshConnectionName" |
|||
echo |
|||
|
|||
user=$(readConsole "User" false false "$user"); |
|||
host="$(readConsole "Host" false false "$host")" |
|||
port="$(readConsole "Port" false false "$port")" |
|||
privateKey="$(readConsole "Private Key File" false false "$privateKey")" |
|||
publicKey="$(readConsole "Public Key File" false false "$publicKey")" |
|||
|
|||
echo |
|||
echoSmall "Validate Data:" |
|||
echo |
|||
echo "User: $user" |
|||
echo "Host: $host" |
|||
echo "Port: $port" |
|||
echo "Private Key File: $privateKey" |
|||
echo "Public Key File: $publicKey" |
|||
echo |
|||
confirm |
|||
|
|||
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.user" "$user" |
|||
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.host" "$host" |
|||
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.port" "$port" |
|||
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.private_key" "$privateKey" |
|||
setConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.public_key" "$publicKey" |
|||
|
|||
echo |
|||
echoSuccess "Configuration written" |
|||
echo |
@ -0,0 +1,48 @@ |
|||
#!/bin/bash |
|||
|
|||
### DO NOT EDIT THIS FILE |
|||
|
|||
function usage { |
|||
echo |
|||
echoMainTitle "Generate ssh keys" |
|||
echo |
|||
echoSubTitle "Usage:" |
|||
echo |
|||
echo "project-manager ssh:install-keys [shortname] [ssh-connection-name] [key-name]" |
|||
echo |
|||
echo "--help Prints this message" |
|||
echo |
|||
} |
|||
|
|||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header" |
|||
|
|||
sshConnectionName="$(getArgument "$2" "SSH connection name required" true)" |
|||
escapedSSHConnectionName=${domain//./\\.} |
|||
user="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.user")" |
|||
host="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.host")" |
|||
port="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.port")" |
|||
privateKey="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.private_key")" |
|||
publicKey="$(getConfig "$shortname" "ssh.servers.$escapedSSHConnectionName.public_key")" |
|||
name="$user@$host" |
|||
|
|||
echo |
|||
echoMainTitle "Install ssh keys" |
|||
echo |
|||
echoSubTitle "SSH keys for connection: $sshConnectionName" |
|||
echo |
|||
|
|||
if [ -f "$privateKey" ] && [ -f "$publicKey" ] |
|||
then |
|||
sshCopyKeyPair "$shortname" "$name" "$privateKey" "$publicKey" |
|||
fi |
|||
|
|||
if [ false == "$(sshHasKeys "$shortname" "$name")" ] |
|||
then |
|||
sshGenerateKeys "$shortname" "$name" |
|||
fi |
|||
|
|||
sshInstallRemoteKey "$shortname" "$name" "$user" "$host" "$port" |
|||
|
|||
echo |
|||
echoSuccess "SSH keys installed" |
|||
echo |
@ -0,0 +1,10 @@ |
|||
#!/bin/bash |
|||
|
|||
### DO NOT EDIT THIS FILE |
|||
|
|||
source "$project_manager_dir/src/includes/bash_header" |
|||
|
|||
shortname="$(getArgument "$1" "shortname required" true)" |
|||
escapedShortname=${shortname//./\\.} |
|||
customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")" |
|||
project="$(getConfig false "project_manager.projects.$escapedShortname.project")" |
Write
Preview
Loading…
Cancel
Save
Reference in new issue