-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-latest.sh
executable file
·86 lines (71 loc) · 1.8 KB
/
install-latest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
set -e
TOKEN=$1
OS=$2
ARCH=$3
CHECK_UPGRADE=$4
if [ -z "$TOKEN" ] && [ "$CHECK_UPGRADE" != "--upgrade" ]; then
echo "Missing token"
exit 1
fi
if [ -z "$OS" ]; then
echo "Missing OS"
exit 1
fi
if [ -z "$ARCH" ]; then
echo "Missing ARCH"
exit 1
fi
if [[ "$OS" != "linux" && "$OS" != "darwin" ]]; then
echo "Unsupported operating system: $OS"
exit 1
fi
if [[ "$ARCH" != "amd64" && "$ARCH" != "arm64" ]]; then
echo "Unsupported architecture: $ARCH"
exit 1
fi
# Check if current user has privileges for installing
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
ARTIFACT_URL="https://github.com/spectate/agent/releases/latest/download/spectated_${OS}_${ARCH}.tar.gz"
# Download and install
echo -n "Downloading latest release $ARTIFACT_URL... "
tar -xzf <(curl -Ls "$ARTIFACT_URL") -C /usr/bin
echo "done"
# Make it executable
echo -n "Making spectated executable... "
chmod +x /usr/bin/spectated
echo "done"
if [[ "$CHECK_UPGRADE" != "--upgrade" ]]; then
# Install service
echo -n "Installing spectated as service... "
/usr/bin/spectated install
echo "done"
# Run auth command
echo -n "Registering this host in Spectate... "
/usr/bin/spectated auth "$TOKEN"
echo "done"
fi
# Start or Restart service
echo -n "Starting spectated service... "
if [[ "$OS" == "linux" ]]; then
if [[ -x "$(command -v systemctl)" ]]; then
if [[ "$CHECK_UPGRADE" == "--upgrade" ]]; then
systemctl restart spectated
else
systemctl start spectated
fi
else
if [[ "$CHECK_UPGRADE" == "--upgrade" ]]; then
service spectated restart
else
service spectated start
fi
fi
elif [[ "$OS" == "darwin" ]]; then
launchctl unload -w ~/Library/LaunchAgents/spectated.plist
launchctl load -w ~/Library/LaunchAgents/spectated.plist
fi
echo "done"