diff --git a/bin/project-manager b/bin/project-manager index 130b306..6d8d3d0 100755 --- a/bin/project-manager +++ b/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 diff --git a/etc/.config_template b/etc/.config_template index e60e274..469e3e9 100644 --- a/etc/.config_template +++ b/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 diff --git a/plugins/git/commands/clone b/plugins/git/commands/clone index 7e1cb0d..f97502d 100644 --- a/plugins/git/commands/clone +++ b/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 diff --git a/plugins/plesk/commands/create-database b/plugins/plesk/commands/create-database new file mode 100644 index 0000000..9db419c --- /dev/null +++ b/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 \ No newline at end of file diff --git a/plugins/plesk/commands/create-subdomain b/plugins/plesk/commands/create-subdomain new file mode 100644 index 0000000..11cb258 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/plugins/plesk/etc/.config_template b/plugins/plesk/etc/.config_template new file mode 100644 index 0000000..e317145 --- /dev/null +++ b/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' \ No newline at end of file diff --git a/plugins/plesk/includes/includes b/plugins/plesk/includes/includes new file mode 100644 index 0000000..221cb2e --- /dev/null +++ b/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" +} diff --git a/plugins/ssh/commands/add-key b/plugins/ssh/commands/add-key index e59bca6..17901d7 100644 --- a/plugins/ssh/commands/add-key +++ b/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 diff --git a/plugins/ssh/includes/includes b/plugins/ssh/includes/includes index 41e4de5..aadb08b 100644 --- a/plugins/ssh/includes/includes +++ b/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)" - echo "Please enter SSH $env system password:" - ssh-copy-id -i "$app_dir/.ssh/$env.pub" "$user"@"$domain" + 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" +} \ No newline at end of file