#!/bin/bash
version=1.2.13

install_packages make || exit 1

cd /tmp
rm -rf btop
wget https://github.com/aristocratos/btop/releases/download/v${version}/btop-armv7l-linux-musleabihf.tbz || error 'Failed to download "btop-armv7l-linux-musleabihf.tbz"!'
tar -xjf btop-armv7l-linux-musleabihf.tbz || error 'Failed to decompress "btop-armv7l-linux-musleabihf.tbz"!'
cd btop || error 'Could not enter btop directory'
sudo make -B install || error 'Failed to install btop with "sudo make install"!'
rm -rf /tmp/btop /tmp/btop-armv7l-linux-musleabihf.tbz || sudo rm -rf /tmp/btop /tmp/btop-armv7l-linux-musleabihf.tbz || error 'Failed to remove install directory!'

echo "[Desktop Entry]
Name=btop++
GenericName=System Monitor
Comment=Awesome terminal resource monitor and task manager, similar to htop.
Exec=${DIRECTORY}/etc/terminal-run btop 'BTOP++'
Icon=$(dirname "$0")/icon-64.png
Terminal=false
StartupNotify=true
Type=Application
Categories=Utility;" > ~/.local/share/applications/btop.desktop
