67 lines
1.8 KiB
Bash
Executable File
67 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Function to check if a command is available
|
|
command_exists() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
# Check if the script is running with root privileges
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "This script must be run with root privileges."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if Python is installed
|
|
if ! command_exists python3; then
|
|
echo "Python3 is not installed. Please install Python3 first."
|
|
exit 1
|
|
fi
|
|
|
|
# Update system packages
|
|
apt update
|
|
|
|
# Install required packages
|
|
apt install -y python3-pip
|
|
|
|
# Upgrade pip
|
|
pip3 install --upgrade pip
|
|
|
|
# Install JupyterLab
|
|
pip3 install jupyterlab
|
|
|
|
# Create a JupyterLab configuration directory
|
|
mkdir -p /etc/jupyterlab
|
|
|
|
# Generate JupyterLab configuration file
|
|
jupyter lab --generate-config -y
|
|
|
|
# Modify JupyterLab configuration to listen on all available interfaces
|
|
echo "c.ServerApp.ip = '0.0.0.0'" >> /etc/jupyterlab/jupyter_lab_config.py
|
|
|
|
# Create a systemd service file
|
|
cat <<EOF > /etc/systemd/system/jupyterlab.service
|
|
[Unit]
|
|
Description=JupyterLab
|
|
|
|
[Service]
|
|
Type=simple
|
|
PIDFile=/run/jupyterlab.pid
|
|
ExecStart=/usr/local/bin/jupyter lab --config=/etc/jupyterlab/jupyter_lab_config.py
|
|
User=YOUR_USERNAME # Replace this with your username
|
|
WorkingDirectory=/path/to/jupyterlab # Replace this with the directory you want to run JupyterLab from
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# Replace "YOUR_USERNAME" and "/path/to/jupyterlab" with your desired values.
|
|
# Make sure to specify the correct path to the JupyterLab installation directory.
|
|
|
|
# Enable and start the JupyterLab service
|
|
systemctl enable jupyterlab
|
|
systemctl start jupyterlab
|
|
|
|
echo "JupyterLab has been installed and set up as a systemd service."
|
|
echo "You can access it from other computers on the network by opening your browser and navigating to http://YOUR_SERVER_IP_OR_DOMAIN:8888"
|
|
|