Browse Source

refactoring

master
Sven Ullmann 2 years ago
parent
commit
41aad8805d
  1. 2
      plugins/db/src/includes/db
  2. 49
      plugins/plesk/src/commands/create-domain
  3. 13
      plugins/ssh/src/commands/install-keys
  4. 31
      plugins/ssh/src/includes/ssh

2
plugins/db/src/includes/db

@ -64,7 +64,7 @@ then
ssh -p "$sshPort" "$sshUser"@"$sshDomain" "cat \"$(generateMy "$shortname" "$env")\" > ~/$env.my.cnf"
ssh "$sshUser"@"$sshDomain" "mysqldump --defaults-extra-file=~/$env.my.cnf --no-tablespaces \
ssh -p "$sshPort" "$sshUser"@"$sshDomain" "mysqldump --defaults-extra-file=~/$env.my.cnf --no-tablespaces \
$ignoredTables ${mysqldumpParameters[*]} $mode $database | \
LANG=C LC_CTYPE=C LC_ALL=C sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | \
sed -e 's/,NO_AUTO_CREATE_USER//' | gzip -9 > ~/$filenamePrefix.sql.gz"

49
plugins/plesk/src/commands/create-domain

@ -8,55 +8,38 @@ function usage {
echo
echoSubTitle "Usage:"
echo
echo "project-manager plesk:create-domain [shortname] [domain]"
echo "project-manager plesk:create-domain [shortname] [plesk-name] [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")\.//")"
pleskName="$(getArgument "$2" "Plesk name required" true)"
domain="$(getArgument "$3" "Domain required" true)"
escapedPleskName=${pleskName//./\\.}
sshName="$(getConfig "$shortname" "plesk.servers.$escapedPleskName.ssh")"
escapeSSHName=${sshName//./\\.}
user="$(getConfig "$shortname" "ssh.servers.$escapeSSHName.user")"
host="$(getConfig "$shortname" "ssh.servers.$escapeSSHName.host")"
user="$(getConfig "$shortname" "ssh.servers.$escapeSSHName.port")"
echo
echoMainTitle "Adding domain on plesk server"
echo
echoSubTitle "Please verify data"
echo
echo "-- $env"
echo "Domain: $domain"
echo "Sub: $sub"
echo "Plesk: $pleskName"
echo
echo "User: $user"
echo "Host: $host"
echo
echo "Plesk host: $host"
echo "Plesk user: $user"
echo "Doman: $domain"
echo
confirm
pleskAddSSHKey
ssh "$user@$host" "plesk bin subdomain --create '$sub' -domain '$domain' -www-root '/$sub.$domain'"
ssh -p "$port" "$user@$host" "plesk bin site --create '$domain' -webspace-name '$domain' -hosting true"
echo
echoSuccess "Subdomain has been created on plesk"
echoSuccess "Domain $domain has been created on Plesk: $pleskName"
echo

13
plugins/ssh/src/commands/install-keys

@ -8,7 +8,7 @@ function usage {
echo
echoSubTitle "Usage:"
echo
echo "project-manager ssh:install-keys [shortname] [ssh-connection-name] [key-name]"
echo "project-manager ssh:install-keys [shortname] [ssh-connection-name]"
echo
echo "--help Prints this message"
echo
@ -17,13 +17,12 @@ function usage {
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
sshConnectionName="$(getArgument "$2" "SSH connection name required" true)"
escapedSSHConnectionName=${domain//./\\.}
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")"
name="$user@$host"
echo
echoMainTitle "Install ssh keys"
@ -33,15 +32,15 @@ echo
if [ -f "$privateKey" ] && [ -f "$publicKey" ]
then
sshCopyKeyPair "$shortname" "$name" "$privateKey" "$publicKey"
sshCopyKeyPair "$shortname" "$sshConnectionName" "$privateKey" "$publicKey"
fi
if [ false == "$(sshHasKeys "$shortname" "$name")" ]
if [ false == "$(sshHasKeys "$shortname" "$sshConnectionName")" ]
then
sshGenerateKeys "$shortname" "$name"
sshGenerateKeys "$shortname" "$sshConnectionName"
fi
sshInstallRemoteKey "$shortname" "$name" "$user" "$host" "$port"
sshInstallRemoteKey "$shortname" "$sshConnectionName" "$user" "$host" "$port"
echo
echoSuccess "SSH keys installed"

31
plugins/ssh/src/includes/ssh

@ -25,9 +25,8 @@ then
local project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
local tempDir="$project_manager_dir/var/tmp/$customer/$project/ssh-keys"
local sshDir="$project_manager_dir/data/$customer/$project/.ssh"
local date="$(date 'Y.m.d_H:i:s')"
local rand="$shortname-$(cat /proc/sys/kernel/random/uuid)"
local backupDir="$project_manager_dir/.trash/$customer/$project/$rand/.ssh"
local backupDir="$project_manager_dir/.trash/$rand/.ssh"
if [ ! -d "$sshDir" ]; then mkdir -p "$sshDir"; fi
if [ -f "$sshDir/$name" ] || [ -f "$sshDir/$name.pub" ]; then mkdir -p "$backupDir"; fi
@ -44,19 +43,30 @@ then
local name="$(getArgument "$2" "name required" true)"
local privateKeyFile="$(getArgument "$3" "private key file required" true)"
local publicKeyFile="$(getArgument "$4" "public key file required" true)"
local escapedShortname=${shortname//./\\.}
local customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
local project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
local sshDir="$project_manager_dir/data/$customer/$project/.ssh"
local rand="$shortname-$(cat /proc/sys/kernel/random/uuid)"
local trash="$project_manager_dir/.trash/$rand/.ssh"
local getPrivateKey="$(if [ -n "$(cmp "$sshDir/$name" "$privateKeyFile")" ]; then echo true; else echo false; fi;)"
local getPublicKey="$(if [ -n "$(cmp "$sshDir/$name.pub" "$publicKeyFile")" ]; then echo true; else echo false; fi;)"
if [ ! -d "$sshDir" ]; then mkdir -p "$sshDir"; fi
if [ -f "$sshDir/$name" ] || [ -f "$sshDir/$name.pub" ]; then mkdir -p "$backupDir"; fi
if [ -f "$sshDir/$name" ]; then mv "$sshDir/$name" "$backupDir/$name" && chmod 0600 "$backupDir/$name"; fi
if [ -f "$sshDir/$name.pub" ]; then mv "$sshDir/$name" "$backupDir/$name.pub" && chmod 0600 "$backupDir/$name.pub"; fi
if [ -f "$sshDir/$name" ] && [ true == $getPrivateKey ]; then mkdir -p "$trash"; mv "$sshDir/$name" "$trash/$name" && chmod 0600 "$trash/$name"; fi
if [ -f "$sshDir/$name.pub" ] && [ true == $getPublicKey ]; then mkdir -p "$trash"; mv "$sshDir/$name.pub" "$trash/$name.pub" && chmod 0600 "$trash/$name.pub"; fi
cp "$privateKeyFile" "$sshDir/$name"
chmod 0600 "$sshDir/$name"
cp "$publicKeyFile" "$sshDir/$name.pub"
chmod 0600 "$sshDir/$name.pub"
if [ true == $getPrivateKey ]
then
cp "$privateKeyFile" "$sshDir/$name"
chmod 0600 "$sshDir/$name"
fi
if [ true == $getPublicKey ]
then
cp "$publicKeyFile" "$sshDir/$name.pub"
chmod 0600 "$sshDir/$name.pub"
fi
}
function sshInstallRemoteKey {
@ -64,7 +74,8 @@ then
local name="$(getArgument "$2" "name required" true)"
local user="$(getArgument "$3" "user required" true)"
local host="$(getArgument "$4" "host required" true)"
local port="${$(getArgument "$2"):-22}"
local port="${5:-"22"}"
local escapedShortname=${shortname//./\\.}
local customer="$(getConfig false "project_manager.projects.$escapedShortname.customer")"
local project="$(getConfig false "project_manager.projects.$escapedShortname.project")"
local sshDir="$project_manager_dir/data/$customer/$project/.ssh"

Loading…
Cancel
Save