Skip to content

Commit

Permalink
Use env_dir instead of env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
simon0191 committed Feb 24, 2017
1 parent f0e52c0 commit 7ced09f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
22 changes: 12 additions & 10 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# bin/compile <build-dir> <cache-dir> <env-dir>

# Generates an SSH config file for connections if a config var exists.

if [[ "$CUSTOM_SSH_KEY" != "" && "$CUSTOM_SSH_KEY_HOSTS" != "" ]]; then
ENV_DIR=$3

if [[ -f $ENV_DIR/CUSTOM_SSH_KEY && -f $ENV_DIR/CUSTOM_SSH_KEY_HOSTS ]]; then

echo "" >&1

# Ensure we have an ssh folder
Expand All @@ -12,25 +15,24 @@ if [[ "$CUSTOM_SSH_KEY" != "" && "$CUSTOM_SSH_KEY_HOSTS" != "" ]]; then
chmod 700 ~/.ssh
fi

# Load the private key into a file.
echo $CUSTOM_SSH_KEY | base64 --decode > ~/.ssh/deploy_key
# Load the private key into custom_key file.
base64 --decode $ENV_DIR/CUSTOM_SSH_KEY > ~/.ssh/custom_key

# Change the permissions on the file to
# be read-only for this user.
chmod 400 ~/.ssh/deploy_key
chmod 400 ~/.ssh/custom_key

# Split $CUSTOM_SSH_KEY_HOSTS
IFS=', ' read -r -a array <<< "$CUSTOM_SSH_KEY_HOSTS"

# Setup the ssh config file.
for element in "${array[@]}"
IFS=',' ;for element in `cat $ENV_DIR/CUSTOM_SSH_KEY_HOSTS`;
do
echo -e "Host $element\n"\
" IdentityFile ~/.ssh/deploy_key\n"\
" IdentityFile ~/.ssh/custom_key\n"\
" IdentitiesOnly yes\n"\
" UserKnownHostsFile=/dev/null\n"\
" StrictHostKeyChecking no"\
>> ~/.ssh/config
done

echo "-----> Successfully added custom SSH key"

fi
9 changes: 2 additions & 7 deletions bin/detect
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env bash
# bin/detect <build-dir>

if [[ "$CUSTOM_SSH_KEY" != "" && "$CUSTOM_SSH_KEY_HOSTS" != "" ]]; then
echo "Custom SSH key and custom SSH key hosts detected"
exit 0
else
echo "Missing CUSTOM_SSH_KEY and CUSTOM_SSH_KEY_HOSTS environment variables"
exit 1
fi
echo "CustomSSHKey"
exit 0
3 changes: 0 additions & 3 deletions bin/release

This file was deleted.

0 comments on commit 7ced09f

Please sign in to comment.