From cb53921fabe763a2db1f9cfcfedc25a3d3fe9170 Mon Sep 17 00:00:00 2001 From: Bjarn Bronsveld <14638441+bjarn@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:50:52 +0100 Subject: [PATCH] feat(installer): add argument for upgrading agent (#12) --- install-latest.sh | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/install-latest.sh b/install-latest.sh index a72d767..7dcc14b 100755 --- a/install-latest.sh +++ b/install-latest.sh @@ -6,7 +6,9 @@ TOKEN=$1 OS=$2 ARCH=$3 -if [ -z "$TOKEN" ]; then +CHECK_UPGRADE=$4 + +if [ -z "$TOKEN" ] && [ "$CHECK_UPGRADE" != "--upgrade" ]; then echo "Missing token" exit 1 fi @@ -49,25 +51,36 @@ echo -n "Making spectated executable... " chmod +x /usr/bin/spectated echo "done" -# Install service -echo -n "Installing spectated as service... " -/usr/bin/spectated install -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" + # Run auth command + echo -n "Registering this host in Spectate... " + /usr/bin/spectated auth "$TOKEN" + echo "done" +fi -# Start service +# Start or Restart service echo -n "Starting spectated service... " if [[ "$OS" == "linux" ]]; then if [[ -x "$(command -v systemctl)" ]]; then - systemctl start spectated + if [[ "$CHECK_UPGRADE" == "--upgrade" ]]; then + systemctl restart spectated + else + systemctl start spectated + fi else - service spectated start + 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"