-
Notifications
You must be signed in to change notification settings - Fork 10
/
entrypoint.sh
86 lines (66 loc) · 2.67 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/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_EXTRA: ${INPUT_EXTRA}"
# echo "INPUT_REMOTE: ${INPUT_REMOTE}"
# echo "INPUT_RUN_BEFORE: ${INPUT_RUNBEFORE}"
# echo "INPUT_RUN_AFTER: ${INPUT_RUNAFTER}"
RUNBEFORE="${INPUT_RUNBEFORE/$'\n'/' && '}"
RUNAFTER="${INPUT_RUNAFTER/$'\n'/' && '}"
if [ -z "$INPUT_KEY" ]
then # Password
echo "> Exporting Password"
export SSHPASS=$PASS
[[ -z "${INPUT_RUNBEFORE}" ]] && {
echo "> Executing commands before deployment"
sshpass -e ssh -o StrictHostKeyChecking=no -p $INPUT_PORT $INPUT_USER@$INPUT_HOST "$RUNBEFORE"
}
echo "> Deploying now"
if [ -z "$INPUT_EXTRA" ]
then
sh -c "sshpass -p $INPUT_PASS rsync -avhz --progress --stats -e 'ssh -p $INPUT_PORT' $GITHUB_WORKSPACE/$INPUT_LOCAL $INPUT_USER@$INPUT_HOST:$INPUT_REMOTE"
else
EXTRA="$INPUT_EXTRA"
sh -c "sshpass -p $INPUT_PASS rsync -avhz $EXTRA --progress --stats -e 'ssh -p $INPUT_PORT' $GITHUB_WORKSPACE/$INPUT_LOCAL $INPUT_USER@$INPUT_HOST:$INPUT_REMOTE"
fi
[[ -z "${INPUT_RUNAFTER}" ]] && {
echo "> Executing commands after deployment"
sshpass -e ssh -o StrictHostKeyChecking=no -p $INPUT_PORT $INPUT_USER@$INPUT_HOST "$RUNAFTER"
}
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/"
[[ -z "${INPUT_RUNBEFORE}" ]] && {
echo "> Executing commands before deployment"
sshpass -e ssh -o StrictHostKeyChecking=no -p $INPUT_PORT $INPUT_USER@$INPUT_HOST "$RUNBEFORE"
}
echo "> Deploying now"
if [ -z "$INPUT_EXTRA" ]
then
EXTRA="$INPUT_EXTRA"
sh -c "sshpass -e rsync -avhz --progress --stats -e 'ssh -p $INPUT_PORT' $GITHUB_WORKSPACE/$INPUT_LOCAL $INPUT_USER@$INPUT_HOST:$INPUT_REMOTE"
else
sh -c "sshpass -e rsync -avhz --progress $EXTRA --stats -e 'ssh -p $INPUT_PORT' $GITHUB_WORKSPACE/$INPUT_LOCAL $INPUT_USER@$INPUT_HOST:$INPUT_REMOTE"
fi
[[ -z "${INPUT_RUNAFTER}" ]] && {
echo "> Executing commands after deployment"
sshpass -e ssh -o StrictHostKeyChecking=no -p $INPUT_PORT $INPUT_USER@$INPUT_HOST "$RUNAFTER"
}
fi
echo "#################################################"
echo "Completed ${GITHUB_WORKFLOW}:${GITHUB_ACTION}"