Run agent on install + JIT Token
This commit is contained in:
parent
2336edcf2e
commit
055233e590
1 changed files with 22 additions and 2 deletions
24
install.sh
24
install.sh
|
@ -14,13 +14,31 @@ then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Parameters required
|
# Required parameter
|
||||||
if [ $# -lt 1 ]
|
if [ $# -lt 1 ]
|
||||||
then
|
then
|
||||||
echo -e "| Usage: bash $0 'token'\n|"
|
echo -e "| Usage: bash $0 'token'\n|"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Exchange JIT token for agent token
|
||||||
|
if [[ $1 == jit-* ]]; then
|
||||||
|
# POST request to retrieve token
|
||||||
|
response=$(curl -s -X POST -d "token=$1" https://api.netweak.com/agent/get-token)
|
||||||
|
|
||||||
|
# Check if there's an error
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo -e "|\n| Error: Failed to retrieve token from API. Make sure your installation command is correct.\n|"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extracting token from response
|
||||||
|
token=$(echo "$response" | tr -d '\n')
|
||||||
|
else
|
||||||
|
# Token doesn't start with "jit-", using it as is
|
||||||
|
token=$1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if crontab is installed
|
# Check if crontab is installed
|
||||||
if [ ! -n "$(command -v crontab)" ]
|
if [ ! -n "$(command -v crontab)" ]
|
||||||
then
|
then
|
||||||
|
@ -120,12 +138,14 @@ mkdir -p /etc/netweak/log
|
||||||
|
|
||||||
# Download agent
|
# Download agent
|
||||||
echo -e "| Downloading agent.sh to /etc/netweak\n|\n| + $(curl -JLso /etc/netweak/agent.sh https://github.com/netweak/agent/raw/main/agent.sh)"
|
echo -e "| Downloading agent.sh to /etc/netweak\n|\n| + $(curl -JLso /etc/netweak/agent.sh https://github.com/netweak/agent/raw/main/agent.sh)"
|
||||||
|
|
||||||
|
# Download heartbeat
|
||||||
echo -e "| Downloading heartbeat.sh to /etc/netweak\n|\n| + $(curl -JLso /etc/netweak/heartbeat.sh https://github.com/netweak/agent/raw/main/heartbeat.sh)"
|
echo -e "| Downloading heartbeat.sh to /etc/netweak\n|\n| + $(curl -JLso /etc/netweak/heartbeat.sh https://github.com/netweak/agent/raw/main/heartbeat.sh)"
|
||||||
|
|
||||||
if [ -f /etc/netweak/agent.sh ]
|
if [ -f /etc/netweak/agent.sh ]
|
||||||
then
|
then
|
||||||
# Create auth file
|
# Create auth file
|
||||||
echo "$1" > /etc/netweak/token.conf
|
echo "$token" > /etc/netweak/token.conf
|
||||||
|
|
||||||
# Create user
|
# Create user
|
||||||
useradd netweak -r -d /etc/netweak -s /bin/false
|
useradd netweak -r -d /etc/netweak -s /bin/false
|
||||||
|
|
Loading…
Reference in a new issue