#!/bin/bash

echo "WARNING: THIS SETUP IS INCOMPATIBLE WITH DIFFERENT BOOTLOADERS THAN GRUB!!!"




sudo apt update
sudo apt upgrade -y
sudo apt-get update
# Note: Storing access tokens in scripts is not recommended due to security concerns
sudo apt install -y pkg-config
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
sudo apt-get install -y libssl-dev
sudo apt install -y build-essential
sudo apt install -y plocate
sudo updatedb 
sudo apt install locate

openssl_dir=$(dirname $(locate openssl.pc | head -n 1))
if [ -n "$openssl_dir" ]; then
  export PKG_CONFIG_PATH=$openssl_dir
  echo "PKG_CONFIG_PATH set to $PKG_CONFIG_PATH"
else
  echo "openssl.pc not found, PKG_CONFIG_PATH not set."
fi

sudo apt install python3-pip

# install nvm too

# npm install -g pnpm



sudo adduser floris-xlx
sudo usermod -aG sudo floris-xlx

sudo adduser xbp
sudo usermod -aG sudo xbp


mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
sudo nano ~/.ssh/authorized_keys


curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
sudo apt install docker-ce

sudo apt install nginx
# Ensure cargo is installed
if ! command -v cargo >/dev/null 2>&1; then
  echo "Cargo is not installed. Please install Rust: https://www.rust-lang.org/tools/install"
  exit 1
fi

# Install deps
sudo apt install sshpass
sudo apt install neofetch


# Install xbp crate
echo "Installing xbp..."
cargo install xbp


# Ensure ~/.cargo/bin is in PATH
if ! echo "$PATH" | grep -q "$HOME/.cargo/bin"; then
  echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.profile
  echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
  echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc
  echo "Updated your shell profile to include Cargo bin path."
fi

echo "Installation complete. You can now run 'xbp' globally."

echo "Installing PM2 process manager daemon."
apt update && apt install sudo curl && curl -sL https://raw.githubusercontent.com/Unitech/pm2/master/packager/setup.deb.sh | sudo -E bash -

echo "Installing PM2 autocomplete"
pm2 completion install


sudo systemctl start docker
sudo reboot


