#!/bin/bash

sudo apt-get update

## Repository OAI dependencies
sudo add-apt-repository ppa:ettusresearch/uhd -y
sudo apt-get update -y

## OAI dependencies
## Testar com a libuhd4.4.0 ao invés de libuhd4.2.0u
sudo apt-get install libuhd-dev libdpdk-dev uhd-host -y
sudo apt-get install libuhd4.2.0 libuhd4.4.0 y					# Required for OpenAirInterface install
sudo dpkg -i --force-overwrite /var/cache/apt/archives/libuhd4.2.0_4.2.0.1-0ubuntu1~focal1_amd64.deb
sudo dpkg -i --force-overwrite /var/cache/apt/archives/libuhd4.4.0_4.4.0.0-0ubuntu1~focal1_amd64.deb

# Work directory path is the current directory
WORK_DIR=$HOME

## Install OAI UE and OAI gNB
cd $WORK_DIR/
git clone https://gitlab.eurecom.fr/oai/openairinterface5g.git
cd $WORK_DIR/openairinterface5g
git checkout develop
git config --global user.email "you@example.com"
git config --global user.name "Your Name"

## Download the OAI configuration files (CU/DU, OAI UE, and gNB configuration)
wget -O $WORK_DIR/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf https://projetos.imd.ufrn.br/reginalab/sdran-openairinterface/-/raw/main/openairinterface5g/openairinterface-conf/basic_deployment/ue.conf?inline=false
wget -O $WORK_DIR/openairinterface5g/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf https://projetos.imd.ufrn.br/reginalab/sdran-openairinterface/-/raw/main/openairinterface5g/openairinterface-conf/flexric_gNB_UE/gnb.sa.band78.fr1.106PRB.usrpb210.conf?inline=false

source oaienv
cd cmake_targets
sudo ./build_oai -I -w USRP -i
sudo ./build_oai --gNB --nrUE -c -C -w USRP
