27 lines
816 B
Bash
27 lines
816 B
Bash
|
#!/bin/sh
|
||
|
|
||
|
export USERNAME=$1
|
||
|
export SSH_KEY=$2
|
||
|
export FOLDER=$3
|
||
|
export DESTINATION=$4
|
||
|
|
||
|
# make sure the ssh agent is running
|
||
|
eval $(ssh-agent -s)
|
||
|
# Inject the remote's private key
|
||
|
echo "$SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
||
|
mkdir -p ~/.ssh
|
||
|
chmod 700 ~/.ssh
|
||
|
# Append keyscan output into known hosts
|
||
|
ssh-keyscan skynet.skynet.ie >> ~/.ssh/known_hosts
|
||
|
chmod 644 ~/.ssh/known_hosts
|
||
|
|
||
|
|
||
|
# ensure teh public_html is created and has right permissions
|
||
|
ssh -vvv -i ~/.ssh/id_rsa ${USERNAME}@skynet.skynet.ie "mkdir -p ~/public_html && chmod 711 ~ || true && chmod -R 755 ~/public_html || true"
|
||
|
|
||
|
# ensure output folder exists
|
||
|
ssh -v ${USERNAME}@skynet.skynet.ie "mkdir -p ~/public_html/${DESTINATION}"
|
||
|
|
||
|
# copy files across
|
||
|
scp -v -r ${FOLDER}/* ${USERNAME}@skynet.skynet.ie:/home/${USERNAME}/public_html/${DESTINATION}
|