diff --git a/install_v2.sh b/install_v2.sh index 60e8abf..3742113 100644 --- a/install_v2.sh +++ b/install_v2.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Script to install JupyterHub (via TLJH) and RStudio Server on Ubuntu 24.04 LTS +# Script to install RStudio Server and then JupyterHub (via TLJH) on Ubuntu 24.04 LTS # --- Configuration --- # Set the desired admin username and password for JupyterHub @@ -8,31 +8,60 @@ ADMIN_USER="your_admin_user" ADMIN_PASSWORD="your_admin_password" # RStudio Server .deb package URL for Ubuntu 22/24 (noble/jammy) -# Always check the Posit website for the latest version and correct URL RSTUDIO_DEB_URL="https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2023.12.1-402-amd64.deb" RSTUDIO_DEB_FILENAME="rstudio-server.deb" # --------------------- -echo "--- Updating and installing prerequisites ---" +echo "--- Installing base prerequisites and updating system ---" apt update apt upgrade -y -apt install -y curl git gdebi-core software-properties-common dirmngr ufw +# Install key dependencies including PAM components and gdebi +apt install -y curl git gdebi-core software-properties-common dirmngr ufw libpam-systemd libnss-systemd -# Enable and configure UFW firewall +# --- Configure Firewall (UFW) --- echo "--- Configuring UFW firewall ---" -ufw allow 80/tcp # For JupyterHub/TLJH (HTTP) -ufw allow 443/tcp # For JupyterHub/TLJH (HTTPS) -ufw allow 8787/tcp # For RStudio Server -ufw enable -y +ufw allow 80/tcp # For JupyterHub/TLJH (HTTP) +ufw allow 443/tcp # For JupyterHub/TLJH (HTTPS) +ufw allow 8787/tcp # For RStudio Server +ufw --force enable echo "Firewall configured: Ports 80, 443, and 8787 allowed." -# ---------------------------------------------------- -# 1. Install The Littlest JupyterHub (TLJH) -# ---------------------------------------------------- -echo "--- Installing The Littlest JupyterHub (TLJH) ---" -# TLJH is a robust and easy way to install a single-server JupyterHub instance. -# It automatically installs Python, JupyterHub, a proxy, and configuration. +--- +## 1. Install R and RStudio Server First 📦 +echo "--- Installing R and RStudio Server ---" +# 1a. Install R base and add the CRAN repository +echo "--- Adding CRAN repository and installing R ---" +# Add key for CRAN +wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/cran_ubuntu_key.gpg >/dev/null + +# Add CRAN repository for Ubuntu Noble (24.04) +add-apt-repository -y "deb https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/" +apt update +apt install -y r-base r-base-dev + +# 1b. Download and Install RStudio Server +echo "--- Downloading and installing RStudio Server ---" +wget "$RSTUDIO_DEB_URL" -O "$RSTUDIO_DEB_FILENAME" +gdebi --n "$RSTUDIO_DEB_FILENAME" +rm "$RSTUDIO_DEB_FILENAME" + +# 1c. Set Explicit R Path (Crucial for stability) +echo "--- Setting RStudio R path configuration ---" +echo "rsession-which-r=/usr/bin/R" | sudo tee -a /etc/rstudio/rserver.conf + +# 1d. Create and secure RStudio session directory (Crucial for preventing permission errors) +echo "--- Fixing RStudio session permissions ---" +mkdir -p /var/lib/rstudio/sessions +chown -R rstudio-server:rstudio-server /var/lib/rstudio +systemctl restart rstudio-server +echo "RStudio Server installed and configured." + +--- +## 2. Install The Littlest JupyterHub (TLJH) +echo "--- Installing The Littlest JupyterHub (TLJH) ---" + +# TLJH installs Python, JupyterHub, the proxy, and creates the admin user curl -L https://tljh.jupyter.org/bootstrap.py | sudo -E python3 - \ --admin "$ADMIN_USER":"$ADMIN_PASSWORD" @@ -41,50 +70,19 @@ if [ $? -ne 0 ]; then exit 1 fi echo "JupyterHub (TLJH) installed successfully." -echo "JupyterHub will be accessible via HTTP on port 80/443." -# ---------------------------------------------------- -# 2. Install R and RStudio Server -# ---------------------------------------------------- -echo "--- Installing R and RStudio Server ---" +--- +## 3. Final Compatibility Fix (The most important step for RStudio after TLJH) +# TLJH installs its own PAM configuration. We must tell RStudio to use the standard system PAM profile for sessions. +echo "--- Applying TLJH/RStudio compatibility fix ---" +ln -s /etc/pam.d/login /etc/pam.d/rstudio -# 2a. Install R base and add the CRAN repository -echo "--- Adding CRAN repository and installing R ---" -# Key for CRAN -wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/cran_ubuntu_key.gpg >/dev/null - -# Add CRAN repository (noble is Ubuntu 24.04 codename) -# We use the older 'jammy-cran40' as the noble repository might not be fully populated yet or for compatibility -add-apt-repository -y "deb https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/" -apt update -apt install -y r-base - -# 2b. Download and Install RStudio Server -echo "--- Downloading and installing RStudio Server ---" -wget "$RSTUDIO_DEB_URL" -O "$RSTUDIO_DEB_FILENAME" - -# Use gdebi to install the .deb package and resolve dependencies -gdebi --n "$RSTUDIO_DEB_FILENAME" - -# Clean up -rm "$RSTUDIO_DEB_FILENAME" - -if [ $? -ne 0 ]; then - echo "WARNING: RStudio Server installation might have failed. Check dependencies." -else - echo "RStudio Server installed successfully." -fi - -# ---------------------------------------------------- -# 3. Final Verification and Instructions -# ---------------------------------------------------- -echo "--- Verification and Next Steps ---" -echo "JupyterHub Status:" -systemctl status jupyterhub --no-pager - -echo "RStudio Server Status (should be active):" -systemctl status rstudio-server --no-pager +# Restart both services one last time +systemctl restart rstudio-server +systemctl restart jupyterhub +--- +## 4. Final Verification and Instructions echo "" echo "==========================================================" echo "✅ Installation Summary" @@ -96,7 +94,5 @@ echo " Password: **$ADMIN_PASSWORD**" echo "" echo "RStudio Server is running on port 8787. Access it at:" echo " ➡️ http://:8787/" -echo " Login with any existing **Ubuntu system user** credentials." -echo "" -echo "Remember to set up HTTPS for JupyterHub using tljh-config!" +echo " Login with the **$ADMIN_USER** credentials created by TLJH." echo "==========================================================" \ No newline at end of file