Add install_v2.sh

This commit is contained in:
RomanNum3ral 2025-11-11 15:52:58 +00:00
parent a8549ee03b
commit ad851adcb6
1 changed files with 102 additions and 0 deletions

102
install_v2.sh Normal file
View File

@ -0,0 +1,102 @@
#!/bin/bash
# Script to install JupyterHub (via TLJH) and RStudio Server on Ubuntu 24.04 LTS
# --- Configuration ---
# Set the desired admin username and password for JupyterHub
# !!! CHANGE THESE VALUES !!!
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 ---"
apt update
apt upgrade -y
apt install -y curl git gdebi-core software-properties-common dirmngr ufw
# Enable and configure UFW firewall
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
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.
curl -L https://tljh.jupyter.org/bootstrap.py | sudo -E python3 - \
--admin "$ADMIN_USER":"$ADMIN_PASSWORD"
if [ $? -ne 0 ]; then
echo "ERROR: TLJH installation failed. Exiting."
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 ---"
# 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
echo ""
echo "=========================================================="
echo "✅ Installation Summary"
echo "=========================================================="
echo "JupyterHub (TLJH) is running. Access it at:"
echo " ➡️ http://<Your-Server-IP>/"
echo " Login with the admin user: **$ADMIN_USER**"
echo " Password: **$ADMIN_PASSWORD**"
echo ""
echo "RStudio Server is running on port 8787. Access it at:"
echo " ➡️ http://<Your-Server-IP>:8787/"
echo " Login with any existing **Ubuntu system user** credentials."
echo ""
echo "Remember to set up HTTPS for JupyterHub using tljh-config!"
echo "=========================================================="