#!/usr/bin/env bash
# packages that aren't in any package manages. They are either
# added to `apt` or installed manually

### APT-added packages ###

# Wez's Terminal emulator
# SEE: https://wezfurlong.org/wezterm/install/linux.html#installing-on-ubuntu
curl -fsSL https://apt.fury.io/wez/gpg.key | sudo gpg --yes --dearmor -o /usr/share/keyrings/wezterm-fury.gpg
echo 'deb [signed-by=/usr/share/keyrings/wezterm-fury.gpg] https://apt.fury.io/wez/ * *' | sudo tee /etc/apt/sources.list.d/wezterm.list

# Brave browser
# SEE: https://brave.com/linux/#debian-ubuntu-mint
sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main"|sudo tee /etc/apt/sources.list.d/brave-browser-release.list

# fastfetch, a neofetch and screenfetch drop-in replacement
sudo add-apt-repository -y ppa:zhangsongcui3371/fastfetch

# install
sudo apt update
sudo apt install -y wezterm-nightly brave-browser fastfetch

### Others ###

# deb-get
# SEE: https://github.com/wimpysworld/deb-get#install
curl -sL https://raw.githubusercontent.com/wimpysworld/deb-get/main/deb-get | sudo -E bash -s install deb-get

# LaTeX
# TeX Live is available for Ubuntu and is in the Universe repository. This will install a basic subset of TeX Live's functionality. To install the complete TeX Live distribution, install texlive-full. Installing TeX Live directly does not interfere with Ubuntu, and ensures that you have the latest releases of all TeX and LaTeX packages. The downside is that you periodically have to update your installation manually, using the TeX Live Package Manager.
#apt install -y texlive-full # latex from ubuntu
# NOTE: https://www.tug.org/texlive/quickinstall.html
(cd /tmp ; \
  wget https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz ; \
  zcat < install-tl-unx.tar.gz | tar xf - ; \
  cd install-tl-*/ ; \
  sudo perl ./install-tl --no-interaction)
sudo chown -R $USER:$USER /usr/local/texlive/ # change ownership to user
# TODO: if the some packages fail, it prompts a message suggesting you to run
# `tlmgr update --all --reinstall-forcibly-removed` to try to resintall them
# you should create a return value handling to run it in case any package fails

# jq: Command-line JSON processor
curl --fail --location https://github.com/jqlang/jq/releases/latest/download/jq-linux-amd64 --output $HOME/.local/bin/jq
chmod u+x $HOME/.local/bin/jq

# xml2json
(
  git clone https://github.com/Cheedoong/xml2json /tmp/xml2json
  cd /tmp/xml2json
  make
  mv xml2json $HOME/.local/bin
)

# rust
# SEE: https://www.rust-lang.org/tools/install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "${XDG_DATA_HOME}/cargo/env"

exit 0