-
Notifications
You must be signed in to change notification settings - Fork 4
/
entrypoint.sh
executable file
·64 lines (53 loc) · 1.68 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
#!/bin/bash
# Import libs
source /usr/local/bin/remote.sh
source /usr/local/bin/${OS}/os.sh
# Default values
TARGET_CLEANUP="${TARGET_CLEANUP:-"true"}"
CHECK_CONNECTION="${CHECK_CONNECTION:-"true"}"
CHECK_CONNECTION_ATTEMPTS=${CHECK_CONNECTION_ATTEMPTS:-30}
CHECK_CONNECTION_DELAY=${CHECK_CONNECTION_DELAY:-10}
# Debug
if [ "${DEBUG:-}" = "true" ]; then
set -xuo
fi
# Validate
if [[ ! remote_required ]] || [[ ! mamp_required ]] || [[ -z "${ASSETS_FOLDER+x}" ]]; then
exit 1
fi
if [ "${CHECK_CONNECTION:-}" = "true" ]; then
check_connection ${CHECK_CONNECTION_ATTEMPTS} ${CHECK_CONNECTION_DELAY}
if [[ $? -gt 0 ]]
then
exit 1
fi
fi
# Create execution folder
echo "Create assets folder on target"
TARGET_FOLDER="${TARGET_FOLDER:-"deliverest-${RANDOM}"}"
$(ssh_cmd "mkdir -p ${TARGET_FOLDER}")
# Copy asset
echo "Copy assets folder to target"
$(scp_to_cmd "${ASSETS_FOLDER}/*" "${TARGET_FOLDER}/")
# Exec command
$(ssh_cmd "$@")
# If remote workload includes a reboot this is the only way to ensure we can
# copy results if any or cleanup
if [ "${CHECK_CONNECTION:-}" = "true" ]; then
check_connection ${CHECK_CONNECTION_ATTEMPTS} ${CHECK_CONNECTION_DELAY}
if [[ $? -gt 0 ]]
then
exit 1
fi
fi
# Copy results
if [[ ! -z "${TARGET_RESULTS+x}" ]]; then
# If exec create some reuslts we define the env and they will be copied to OUTPUT_FOLDER
OUTPUT_FOLDER="${OUTPUT_FOLDER:-"/output"}"
$(scp_from_cmd "${TARGET_FOLDER}/${TARGET_RESULTS}" "${OUTPUT_FOLDER}/")
fi
if [ "${TARGET_CLEANUP:-}" = "true" ]; then
# This will create the cmd based on OS env with the right syntax
cmd="$(remove_folder ${TARGET_FOLDER})"
$(ssh_cmd ${cmd})
fi