#!/bin/bash

# Release channel is passed as first argument.
PLEXAMP_URL=$(curl -s "https://plexamp.plex.tv/headless/version$1.json" | jq -r '.updateUrl')

cd "/home/$USER"

# Download and install.
wget -q "$PLEXAMP_URL" -O plexamp.tar.bz2
rm -rf plexamp.last
mv plexamp plexamp.last
tar xfj plexamp.tar.bz2
rm plexamp.tar.bz2
chown -R "${USER}:${USER}" plexamp

# Restart service.
sudo systemctl -q restart plexamp
