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.
70 lines
1.6 KiB
70 lines
1.6 KiB
#!/bin/bash
|
|
|
|
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 "$project_manager_dir/bin/includes/project_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 "$ssh_private_key"
|
|
echo "$ssh_public_key"
|
|
echo "$ssh_user"
|
|
echo "$ssh_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"
|