forked from mai-space/action-sshpass-rsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
58 lines (46 loc) · 1.89 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -e
echo "#################################################"
echo "> Starting ${GITHUB_WORKFLOW}:${GITHUB_ACTION}"
# Available env
# echo "INPUT_HOST: ${INPUT_HOST}"
# echo "INPUT_PORT: ${INPUT_PORT}"
# echo "INPUT_USER: ${INPUT_USER}"
# echo "INPUT_PASS: ${INPUT_PASS}"
# echo "INPUT_KEY: ${INPUT_KEY}"
# echo "INPUT_LOCAL: ${INPUT_LOCAL}"
# echo "INPUT_REMOTE: ${INPUT_REMOTE}"
# echo "INPUT_RUN_BEFORE: ${INPUT_RUNBEFORE}"
# echo "INPUT_RUN_AFTER: ${INPUT_RUNAFTER}"
# echo "INPUT_USE_RSYNC_URL: ${INPUT_USERSYNCURL}"
RUNBEFORE="${INPUT_RUNBEFORE/$'\n'/' && '}"
RUNAFTER="${INPUT_RUNAFTER/$'\n'/' && '}"
if [ -z "$INPUT_KEY" ]; then # Password
echo "> Exporting Password"
export SSHPASS=$PASS
echo "> Deploying now"
if [ -z "$USERSYNCURL" ]; then
sshpass -p $INPUT_PASS rsync -avhz --progress --stats -e "ssh -p $INPUT_PORT" $GITHUB_WORKSPACE/$INPUT_LOCAL $INPUT_USER@$INPUT_HOST:$INPUT_REMOTE --delete-during
else
sshpass -p $INPUT_PASS rsync -avhz --progress --stats $GITHUB_WORKSPACE/$INPUT_LOCAL rsync://$INPUT_USER@$INPUT_HOST:$INPUT_PORT$INPUT_REMOTE --delete-during
fi
else
# Private key
pwd
mkdir "/root/.ssh"
echo "$INPUT_KEY" >"/root/.ssh/id_rsa"
chmod 400 "/root/.ssh/id_rsa"
echo "Host *" >"/root/.ssh/config"
echo " AddKeysToAgent yes" >>"/root/.ssh/config"
echo " IdentityFile /root/.ssh/id_rsa" >>"/root/.ssh/config"
cat "/root/.ssh/config"
ls -lha "/root/.ssh/"
echo "> Deploying now"
if [ -z "$USERSYNCURL" ]; then
sshpass -e rsync -avhz --progress --stats $GITHUB_WORKSPACE/$INPUT_LOCAL rsync://$INPUT_USER@$INPUT_HOST:$INPUT_PORT$INPUT_REMOTE --delete-during
else
sshpass -e rsync -avhz --progress --stats -e "ssh -p $INPUT_PORT" $GITHUB_WORKSPACE/$INPUT_LOCAL $INPUT_USER@$INPUT_HOST:$INPUT_REMOTE --delete-during
fi
fi
echo "#################################################"
echo "Completed ${GITHUB_WORKFLOW}:${GITHUB_ACTION}"