-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
43 lines (35 loc) · 1.18 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
#!/bin/sh -l
set -euo pipefail
TEMP_SSH_PRIVATE_KEY_FILE='../private_key.pem'
TEMP_SFTP_FILE='../sftp'
# Save private key to a file
printf "%s" "$5" >$TEMP_SSH_PRIVATE_KEY_FILE
chmod 600 $TEMP_SSH_PRIVATE_KEY_FILE
# SFTP file transfer
echo 'sftp start'
printf "%s" "put -r $6 $7" >$TEMP_SFTP_FILE
sshpass -p $2 sftp -oBatchMode=no -b $TEMP_SFTP_FILE -P $4 $8 -o StrictHostKeyChecking=no -i $TEMP_SSH_PRIVATE_KEY_FILE $1@$3
# Create body and signature
body="{}"
signature="$(echo -n "$body" | openssl sha1 -hmac "$10" -binary | xxd -p)"
signature=$(echo -n "$signature")
# Debugging information
base64_encoded=$(echo "$9" | base64)
echo "$base64_encoded"
echo "$body"
echo "$signature"
# Send curl request and capture result
if [ ! -z "$9" ]; then
response=$(curl --location --request POST "$9" \
--data-raw "$body" \
--header 'Content-Type: application/json' \
--header "X-Hub-Signature: $signature" \
--write-out '%{http_code}')
# Check if the HTTP response code indicates a failure
if [ "$response" -ne 200 ]; then
echo "Deployment failed. Server responded with HTTP code $response"
exit 1
fi
fi
echo 'deploy successful'
exit 0