Browse Source

plesk magic ;)

master
Sven Ullmann 2 years ago
parent
commit
45dfa080e3
  1. 7
      bin/project-manager
  2. 22
      etc/.config_template
  3. 7
      plugins/git/commands/clone
  4. 69
      plugins/plesk/commands/create-database
  5. 62
      plugins/plesk/commands/create-subdomain
  6. 10
      plugins/plesk/etc/.config_template
  7. 59
      plugins/plesk/includes/includes
  8. 5
      plugins/ssh/commands/add-key
  9. 36
      plugins/ssh/includes/includes

7
bin/project-manager

@ -137,7 +137,12 @@ else
echo
exit
else
source "$file" "${*:2}"
if [ "${#@}" -eq 1 ]
then
source "$file" "${*:2}"
else
source "$file" "${@:2}"
fi
fi
echo

22
etc/.config_template

@ -8,29 +8,35 @@ app_project_manager_dir=''
### STAGE
# stage domain
stage_domain=''
# url to stage
stage_url=''
# The httpdocs folder on your server
stage_httpdocs_path=''
# subpath from httpdocs to your installation of the project
stage_httpdocs_git_subpath=''
### LIVE
# live domain
live_domain=''
# url to live
live_url=''
# The httpdocs folder on your server
live_httpdocs_path=''
# subpath from httpdocs to your installation of the project
live_httpdocs_git_subpath=''
### LOCAL STAGE
# url to your project on the local machine
local_stage_host=''
local_url=''
### LOCAL LIVE
# url to your project on the local machine
local_live_host=''
local_url=''
### POST SCRIPT

7
plugins/git/commands/clone

@ -15,13 +15,6 @@ function usage {
source "$project_manager_dir/bin/includes/project_header"
gitValidate
help="$(getParameter "--help" false "$@")"
if [ "$help" == true ] || [ "$1" == "" ]
then
usage
exit
fi
if [ "$git_url" == "" ]
then
echo

69
plugins/plesk/commands/create-database

@ -0,0 +1,69 @@
#!/bin/bash
function usage {
echo
echoMainTitle "Creates a database on plesk server"
echo
echoSubTitle "Usage:"
echo
echo "project-manager plesk:create-database [project-shortname] [env]"
echo
echo " [env] could be live or stage"
echo
echo "--help Prints this message"
echo
}
source "$project_manager_dir/bin/includes/project_header"
env="$(getArgument "$2" "$(usage)" "live stage")"
pleskValidate "$env"
db_user="$(dbGetConfig "$env" "user")"
db_password="$(dbGetConfig "$env" "password")"
db_database="$(dbGetConfig "$env" "database")"
domain="$(getConfig "$env" "domain")"
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 database on plesk server"
echo
echoSubTitle "Please verify data"
echo
echo "-- $env"
echo "Domain: $domain"
echo
echo "Database name: $db_database"
echo "Database user: $db_user"
echo
echo "Plesk host: $plesk_host"
echo "Plesk user: $plesk_user"
echo "Plesk private key: $plesk_private_key"
echo "Plesk public key: $plesk_public_key"
echo
confirm
pleskAddSSHKey
ssh "$plesk_user@$plesk_host" "plesk bin database --create '$db_database' -domain '$domain' -type '$plesk_db_type' -server 'localhost'"
ssh "$plesk_user@$plesk_host" "plesk bin database --create-dbuser '$db_user' -passwd '$db_password' -domain '$domain' -database '$db_database' -server 'localhost'"
echo
echoSuccess "Database has been created on plesk"
echo

62
plugins/plesk/commands/create-subdomain

@ -0,0 +1,62 @@
#!/bin/bash
function usage {
echo
echoMainTitle "Creates a subdomain on plesk server"
echo
echoSubTitle "Usage:"
echo
echo "project-manager plesk:create-subdomain [project-shortname] [env]"
echo
echo " [env] could be live or stage"
echo
echo "--help Prints this message"
echo
}
source "$project_manager_dir/bin/includes/project_header"
env="$(getArgument "$2" "$(usage)" "live stage")"
pleskValidate "$env"
domain="$(getConfig "$env" "domain")"
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 subdomain on plesk server"
echo
echoSubTitle "Please verify data"
echo
echo "-- $env"
echo "Domain: $domain"
echo "Sub: $sub"
echo
echo "Plesk host: $plesk_host"
echo "Plesk user: $plesk_user"
echo "Plesk private key: $plesk_private_key"
echo "Plesk public key: $plesk_public_key"
echo
confirm
pleskAddSSHKey
ssh "$plesk_user@$plesk_host" "plesk bin subdomain --create '$sub' -domain '$domain' -www-root '/$sub.$domain'"
echo
echoSuccess "Subdomain has been created on plesk"
echo

10
plugins/plesk/etc/.config_template

@ -0,0 +1,10 @@
#!/bin/bash
plesk_host=''
plesk_user=''
plesk_private_key=''
plesk_public_key=''
plesk_db_type='mysql'
plesk_binary='plesk'

59
plugins/plesk/includes/includes

@ -0,0 +1,59 @@
#!/bin/bash
plesk_included=true
function pleskValidate {
local env=$(getArgument "$1" "Usage: pleskValidate [live|stage]" "live stage")
if [ "$ssh_included" == "" ]
then
echo >&2
echoError "Plugin \"ssh\" has to be included" >&2
echo >&2
exit
fi
if [ "$db_included" == "" ]
then
echo >&2
echoError "Plugin \"db\" has to be included" >&2
echo >&2
exit
fi
if [ "$plesk_host" == "" ] || [ "$plesk_user" == "" ]
then
echo >&2
echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/plesk/config" >&2
echo >&2
exit
fi
if [ "$(dbGetConfig "$env" "user")" == "" ] || [ "$(dbGetConfig "$env" "database")" == "" ] || [ "$(dbGetConfig "$env" "password")" == "" ]
then
echo >&2
echoError "Please configure $project_manager_dir/data/$customer/$project/etc/plugins/db/config" >&2
echo >&2
exit
fi
}
function pleskAddSSHKey {
if [ ! -f "$plesk_private_key" ] && [ ! -f "$app_dir/.ssh/plesk" ]
then
sshGenerateKey "plesk"
sshCopyIdKey "plesk" "$plesk_user@$plesk_host" "$app_dir/.ssh/plesk.pub"
fi
if [ -f "$plesk_private_key" ] && [ ! -f "$app_dir/.ssh/plesk" ]
then
sshCopyKey "plesk" "$plesk_private_key"
fi
if [ -f "$plesk_public_key" ] && [ ! -f "$app_dir/.ssh/plesk.pub" ]
then
sshCopyKey "plesk.pub" "$plesk_private_key"
fi
ssh-add "$app_dir/.ssh/plesk"
}

5
plugins/ssh/commands/add-key

@ -23,11 +23,6 @@ ssh_public_key="$(sshGetConfig "$env" "public_key")"
ssh_user="$(sshGetConfig "$env" "user")"
ssh_domain="$(sshGetConfig "$env" "domain")"
echo "$ssh_private_key"
echo "$ssh_public_key"
echo "$ssh_user"
echo "$ssh_domain"
echo
echoMainTitle "Adding SSH Keys"
echo

36
plugins/ssh/includes/includes

@ -114,11 +114,16 @@ function sshCopyKeys {
exit
fi
cp "$ssh_private_key" "$app_dir/.ssh/$env"
chmod 0600 "$app_dir/.ssh/$env"
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 "$ssh_public_key" "$app_dir/.ssh/$env.pub"
chmod 0600 "$app_dir/.ssh/$env.pub"
cp "$file" "$app_dir/.ssh/$name"
chmod 0600 "$app_dir/.ssh/$name"
}
function sshInstallKeys {
@ -152,10 +157,23 @@ function sshInstallKeys {
exit
fi
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"
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 $env system password:"
ssh-copy-id -i "$app_dir/.ssh/$env.pub" "$user"@"$domain"
echo "Please enter SSH $name system password:"
ssh-copy-id -i "$file" "$ssh"
}
Loading…
Cancel
Save