#! /bin/bash

apt update
apt install --yes r-base wget
wget "https://download2.rstudio.org/rstudio-server-1.1.463-amd64.deb"
apt install --yes ./rstudio-server-1.1.463-amd64.deb

echo "http_proxy=http://phugeet.cs.up.ac.za:3128/" >> /etc/R/Renviron.site
echo "https_proxy=http://phugeet.cs.up.ac.za:3128/" >> /etc/R/Renviron.site

systemctl restart rstudio-server

read -p "What username would you like to use?: " USERNAME
read -sp "Enter password for user: " PASSWORD

echo ""

useradd -mg sudo -s /bin/bash $USERNAME
echo -e "$PASSWORD\n$PASSWORD\n" | passwd $USERNAME

IP=$(ip a | grep 192.168 | sed 's/\/.*//g' | sed 's/.*\ //g')

echo "Done setting up R-Studio - you can now go to http://$IP:8787 to log in"
echo "If you want to change your password in the future, run \"passwd $USERNAME\""
