-
-
Notifications
You must be signed in to change notification settings - Fork 140
/
run-agent
executable file
·93 lines (74 loc) · 2.09 KB
/
run-agent
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
87
88
89
90
91
92
93
#!/bin/sh
set -e
usage() {
cat <<EOF
Runs a native agent with the provided git tag. Optionally, it can receive -t <tenant_id>, -s <server_address>, and -o "<KEY=VALUE>" parameters, which are used during agent initialization. Leave these parameters blank for default values.
When <tag> is '.', the agent will be built in the current Git state and named 'latest'.
Usage:
$0 <tag> [-t <tenant_id>] [-s <server_address>] [-o <KEY=VALUE>]
Examples:
$0 .
$0 v0.15.0
$0 v0.15.0 -t 00000000-0000-4000-0000-000000000000 -s http://127.0.0.1 -o "KEEPALIVE_INTERVAL=30 PREFERRED_HOSTNAME=127.0.0.2"
EOF
exit 0
}
if [ "$#" -eq 0 ]; then
usage
fi
. "$(dirname "$0")/utils"
tag="$1"
shift
tenant_id="00000000-0000-4000-0000-000000000000"
server_address="http://127.0.0.1"
additional_env=""
# Processa as flags usando getopts
while [ "$#" -gt 0 ]; do
case "$1" in
-t)
tenant_id="$2"
shift 2
;;
-s)
server_address="$2"
shift 2
;;
-o)
additional_env="$2"
shift 2
;;
--help)
usage
;;
*)
echo "Invalid option: $1"
usage
;;
esac
done
if [ "$tag" = "." ]; then
tag="latest"
fi
echo "Tenant ID: $tenant_id"
echo "Server Address: $server_address"
echo "Additional Environment Variables: $additional_env"
if [ ! -d ./bin/agent ]; then
mkdir -p ./bin/agent
fi
if [ "$tag" = "latest" ]; then
cd ./agent
go build -ldflags "-X main.AgentVersion=$tag" -o "./../bin/agent/$tag"
cd ./..
elif [ ! -f ./bin/agent/$tag ]; then
check_bin "git"
echo "No '$tag' agent found. Building one."
branch=$(git symbolic-ref --short HEAD)
(
git checkout $tag
cd ./agent
go build -ldflags "-X main.AgentVersion=${tag:1}" -o "./../bin/agent/$tag" # Remove the 'v' from the beginning of the tag.
cd ./..
git switch $branch
)
fi
sudo -E TENANT_ID=$tenant_id SERVER_ADDRESS=$server_address $additional_env PRIVATE_KEY=/tmp/test.pk ./bin/agent/$tag