-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_updates.sh
65 lines (49 loc) · 1.91 KB
/
check_updates.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
# Set environment variables
export FILE_NAME=sentry-node-cli-linux.zip
export VERSION_FILE=$(pwd)/current_version.txt
# Get latest release info
release_info=$(curl --silent "https://api.github.com/repos/xai-foundation/sentry/releases/latest")
# Extract the tag_name and browser_download_url for sentry-node-cli-linux.zip
latest_version=$(echo $release_info | jq -r .tag_name | sed 's/v//')
file_url=$(echo $release_info | jq -r '.assets[] | select(.name=="sentry-node-cli-linux.zip") | .browser_download_url')
echo $latest_version
current_version=$(cat $VERSION_FILE | tr -d '[:space:]')
latest_version=$(echo $latest_version | tr -d '[:space:]')
echo "Current version: $current_version"
if [ ! -f "$VERSION_FILE" ]; then
echo Initial ver download
cd $HOME
curl -L --remote-name $file_url
rm -f sentry-node-cli-linux
unzip -o $FILE_NAME
rm -f $FILE_NAME
chmod +x sentry-node-cli-linux
export current_version="$latest_version"
echo "$current_version" > $VERSION_FILE
else
# Update if necessary
if [ "$current_version" != "$latest_version" ]; then
echo "New release found. Updating..."
cd $HOME
curl -L --remote-name $file_url
rm -f sentry-node-cli-linux
unzip -o $FILE_NAME
rm -f $FILE_NAME
chmod +x sentry-node-cli-linux
export current_version="$latest_version"
echo "$current_version" > $VERSION_FILE
# Read the webhook URL from the environment variable
WEBHOOK_URL="${NOTIFICATION_WEBHOOK_OPTIONAL:-}"
# Check if the webhook URL is empty
if [ -z "$WEBHOOK_URL" ]; then
echo "Node updated to $latest_version. Restarting the process..."
else
# If the webhook URL is set, make the POST request
curl -X POST -H "Content-Type: application/json" --data '{"content": "sentry-node-cli updated."}' $WEBHOOK_URL
fi
supervisorctl restart sentry-node-cli
else
echo "No new release found."
fi
fi