#!/bin/bash
version=1.4.7

install_packages make || exit 1

cd /tmp
rm -rf btop
wget https://github.com/aristocratos/btop/releases/download/v${version}/btop-aarch64-unknown-linux-musl.tar.gz || error 'Failed to download "btop-aarch64-unknown-linux-musl.tar.gz"!'
tar -xzf btop-aarch64-unknown-linux-musl.tar.gz || error 'Failed to decompress "btop-aarch64-unknown-linux-musl.tar.gz"!'
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-aarch64-unknown-linux-musl.tar.gz || sudo rm -rf /tmp/btop /tmp/btop-aarch64-unknown-linux-musl.tar.gz || 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
