diff --git a/ssh-helper/README.md b/ssh-helper/README.md index 6058901..804e7aa 100644 --- a/ssh-helper/README.md +++ b/ssh-helper/README.md @@ -26,6 +26,12 @@ docker run -it --rm -v $(pwd):/keys/ codeship/ssh-helper prepare The resulting file will be called `codeship.env`, and the value will be appended if that file already exists. +You can also override few variable to have custom keys location and names. + +```shell +docker run -it --rm -v $(pwd):/keys/ --env BASE_FOLDER="/keys" --env KEY_FILE="/keys/my_codeship_deploy_key" --env ENV_FILE="/keys/my_codeship.env" codeship/ssh-helper prepare +``` + ## Write the Environment Variable Back to a File During your Codeship Pro builds, you need to take the environment variable and write it back to a file, to pass to the `ssh` (or similar) commands. diff --git a/ssh-helper/ssh_helper.sh b/ssh-helper/ssh_helper.sh index 1417a6c..6b95167 100644 --- a/ssh-helper/ssh_helper.sh +++ b/ssh-helper/ssh_helper.sh @@ -1,7 +1,7 @@ #!/bin/sh -BASE_FOLDER="/keys" -KEY_FILE="${BASE_FOLDER}/codeship_deploy_key" -ENV_FILE="${BASE_FOLDER}/codeship.env" +[ -z "${BASE_FOLDER}" ] && BASE_FOLDER="/keys" +[ -z "${KEY_FILE}" ] && KEY_FILE="${BASE_FOLDER}/codeship_deploy_key" +[ -z "${ENV_FILE}" ] && ENV_FILE="${BASE_FOLDER}/codeship.env" ACTION=$1 && shift @@ -15,7 +15,7 @@ case "${ACTION}" in ;; write) mkdir -p "${BASE_FOLDER}/.ssh/" - printf "${PRIVATE_SSH_KEY}\n" >> "${BASE_FOLDER}/.ssh/id_rsa" + printf "${PRIVATE_SSH_KEY}\n" > "${BASE_FOLDER}/.ssh/id_rsa" ;; *) echo "Usage: $0 {generate|prepare|write}"