#!/bin/sh

APP=tor-browser-alpha

# CREATE THE DIRECTORY
mkdir -p /opt/"$APP"
cd /opt/"$APP"

# ADD THE REMOVER
echo '#!/bin/sh' >> /opt/"$APP"/remove
echo "rm -R -f /usr/local/share/applications/$APP-AM.desktop /opt/$APP /usr/local/bin/$APP" >> /opt/"$APP"/remove
chmod a+x /opt/"$APP"/remove

# DOWNLOAD THE ARCHIVE
mkdir -p tmp
cd ./tmp

wget "$(curl -Ls https://www.torproject.org/download/alpha/ | tr '><" ' '\n' | grep -i "http.*linux.*x86_64.*tar.xz" | head -1)"
[ -e ./*tar.* ] && tar fx ./*tar.* && rm -f ./*tar.*
cd ..
mv ./tmp/*/Browser/* ./
rm -R ./tmp

# LINK / SCRIPT IN $PATH
ln -s /opt/"$APP"/firefox.real /usr/local/bin/"$APP"

# LAUNCHER
echo "
[Desktop Entry]
Type=Application
Name=Tor Browser (Alpha)
GenericName=Web Browser
Comment=Tor Browser is +1 for privacy and −1 for mass surveillance
Categories=Network;WebBrowser;Security;
Exec=$APP
X-TorBrowser-ExecShell=/opt/$APP/start-tor-browser --detach
Icon=/opt/$APP/browser/chrome/icons/default/default128.png
StartupWMClass=Tor Browser" > /usr/local/share/applications/"$APP"-AM.desktop




