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.
 
 

181 lines
4.6 KiB

#!/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"
}