#!/bin/bash
DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

rm -f Snapdrop-linux-armv7l.tar.xz

wget https://github.com/chunky-milk/snapdrop-rpi/releases/download/2.0/Snapdrop-linux-armv7l.tar.xz || error "Failed to download archive!"
tar -xvf Snapdrop-linux-armv7l.tar.xz || error "Failed to extract archive!"
rm -f Snapdrop-linux-armv7l.tar.xz

# Desktop entry
echo "[Desktop Entry]
Name=Snapdrop
GenericName=Local File Sharing
Comment=Snapdrop: local file sharing in your browser. Inspired by Apple's Airdrop.
Exec=$HOME/snapdrop/Snapdrop
Icon=$(dirname "$0")/icon-64.png
Terminal=true
StartupNotify=true
Categories=Network;
Type=Application" > ~/.local/share/applications/snapdrop.desktop || error "Failed to create desktop shortcut!"
