Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux Installer Script #871

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ea1ecc4
Linux installer script
justinh-rahb Feb 23, 2024
84126e3
Merge branch 'open-webui:main' into installer
justinh-rahb Feb 23, 2024
d950e38
Merge branch 'open-webui:main' into installer
justinh-rahb Feb 23, 2024
ee348e7
Merge branch 'open-webui:main' into installer
justinh-rahb Feb 25, 2024
cdded36
Merge branch 'open-webui:main' into installer
justinh-rahb Mar 4, 2024
26f8b72
Merge branch 'open-webui:main' into installer
justinh-rahb Mar 18, 2024
ff05d23
Merge branch 'open-webui:main' into installer
justinh-rahb Mar 19, 2024
1fd9f3b
Merge branch 'open-webui:main' into installer
justinh-rahb Apr 16, 2024
2869bfb
Refacs
justinh-rahb Apr 16, 2024
501c3f8
More refac
justinh-rahb Apr 16, 2024
be44c3d
Add `--no-ollama` flag
justinh-rahb Apr 16, 2024
13806fa
Add repo clone function and `INSTALL_PATH`
justinh-rahb Apr 16, 2024
ee8a91b
Refac clone function
justinh-rahb Apr 16, 2024
b8285d5
Restore `install_openwebui_docker()`
justinh-rahb Apr 16, 2024
2ed6ccd
Don't exit after Ollama install
justinh-rahb Apr 16, 2024
ecb1cbd
Refac
justinh-rahb Apr 16, 2024
7c91829
`run-ollama-docker.sh` already asks for GPUs
justinh-rahb Apr 16, 2024
0f607b4
Fix path issue
justinh-rahb Apr 16, 2024
ac90019
`git pull` if repo exists
justinh-rahb Apr 16, 2024
7c056f0
`install.sh` bootstrap script
justinh-rahb Apr 16, 2024
25f218a
Deploy `install.sh` to GH Pages
justinh-rahb Apr 16, 2024
30b5d57
Configure Ollama envvars
justinh-rahb Apr 16, 2024
4174683
Add systemd service for WebUI
justinh-rahb Apr 16, 2024
054a4a9
Include systemd service file
justinh-rahb Apr 16, 2024
c92f8f3
Copy `.env.example` to `/etc/open-webui/env` for systemd
justinh-rahb Apr 16, 2024
32caf80
Messages
justinh-rahb Apr 16, 2024
608eb97
Merge branch 'open-webui:main' into installer
justinh-rahb Apr 17, 2024
af72b27
Merge branch 'open-webui:main' into installer
justinh-rahb Apr 27, 2024
06ae271
Merge branch 'open-webui:main' into installer
justinh-rahb May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy Install Script

on:
push:
paths:
- 'install.sh' # Only run workflow if install.sh is changed
branches:
- main # Set this to your default branch

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Prepare GitHub Pages directory
run: |
mkdir -p gh-pages-content
cp install.sh gh-pages-content/install.sh

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./gh-pages-content
keep_files: false # Replace all content with the content in publish_dir
270 changes: 270 additions & 0 deletions install-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
#!/bin/bash

# Initialize flags and installation path
NO_DOCKER=0
NO_OLLAMA=0
INSTALL_PATH="$HOME/.open-webui/source"

# Parse command-line arguments
for arg in "$@"; do
case $arg in
--no-docker)
NO_DOCKER=1
shift # Remove --no-docker from processing
;;
--no-ollama)
NO_OLLAMA=1
shift # Remove --no-ollama from processing
;;
--install-path)
INSTALL_PATH="$2"
shift # Remove argument name
shift # Remove argument value
;;
*)
# Unknown option
;;
esac
done

# Define the base directory as the installation path
BASE_DIR=$(mkdir -p "$INSTALL_PATH" && cd "$INSTALL_PATH" && pwd)
cd "$BASE_DIR"

echo "Installation will proceed in directory: $BASE_DIR"

# Function to clone the Open WebUI repository
clone_repository() {
if [ -d "$BASE_DIR/open-webui/.git" ]; then
echo "The Open WebUI repository already exists at $BASE_DIR/open-webui."
echo "Pulling updates from the remote repository..."
cd "$BASE_DIR/open-webui" && git pull
else
echo "Cloning Open WebUI repository into $BASE_DIR/open-webui..."
git clone https://github.com/open-webui/open-webui.git "$BASE_DIR/open-webui"
fi
}

# Function to check if Docker is installed
check_docker() {
echo "Checking for Docker..."
if ! command -v docker &> /dev/null; then
echo "Docker could not be found. Would you like to install Docker? (y/n)"
read -r choice
if [ "$choice" = "y" ]; then
install_docker
else
justinh-rahb marked this conversation as resolved.
Show resolved Hide resolved
echo "Docker is required for the Docker-based installation."
echo "Would you like to proceed with the Docker-less installation? (y/N)"
read -r proceed
if [ "$proceed" != "y" ]; then
echo "Exiting the installation script."
exit 0
fi
clone_repository
dockerless_install
exit 0
fi
else
echo "Docker is already installed."
fi
}

# Function to install Docker
install_docker() {
echo "Installing Docker..."
curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo docker run --rm hello-world
if [ $? -ne 0 ]; then
echo "Docker installation failed. Please check the error messages above."
exit 1
fi
echo "Docker has been successfully installed."
clone_repository
}

# Function to check for Node.js
check_nodejs() {
if ! command -v node &> /dev/null; then
install_nodejs
else
echo "Node.js is already installed."
fi
}

# Function to create and enable a systemd service for Open WebUI
create_openwebui_service() {
echo "Creating systemd service for Open WebUI..."
local repo_service_path="$BASE_DIR/open-webui/open-webui.service"
local systemd_service_path="/etc/systemd/system/open-webui.service"
local env_source_path="$BASE_DIR/open-webui/.env.example"
local env_dest_path="/etc/open-webui/env"

# Check if the systemd service file exists in the repository
if [ -f "$repo_service_path" ]; then
# Copy the service file to the systemd directory
sudo cp "$repo_service_path" "$systemd_service_path"
else
echo "Failed to locate the systemd service file in the repository. Please ensure it exists at $repo_service_path."
exit 1
fi

# Ensure the environment file exists and copy it
if [ -f "$env_source_path" ]; then
echo "Setting up environment file..."
sudo mkdir -p $(dirname "$env_dest_path") # Ensure the destination directory exists
sudo cp "$env_source_path" "$env_dest_path"
else
echo "Environment file not found at $env_source_path. Continuing without custom environment settings."
fi

# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable the service to start at boot
sudo systemctl enable open-webui.service
# Start the service
sudo systemctl start open-webui.service

echo "Open WebUI systemd service has been installed and started."
}

# Function to create systemd override for Ollama
configure_ollama_systemd() {
echo "Configuring systemd service for Ollama..."
local systemd_dir="/etc/systemd/system/ollama.service.d"
local override_conf="$systemd_dir/override.conf"

# Ensure the systemd directory exists
sudo mkdir -p $systemd_dir

# Create or truncate the override file
echo "Creating or clearing override configuration for Ollama..."
sudo tee $override_conf <<EOF
[Service]
Environment="OLLAMA_HOST=0.0.0.0"
Environment="OLLAMA_ORIGINS=*"
EOF

# Reload systemd to apply changes and restart the service
sudo systemctl daemon-reload
sudo systemctl restart ollama
echo "Ollama systemd service configured with overrides."
}

# Function to install Node.js using nvm
install_nodejs() {
echo "Node.js not found. Installing Node.js using nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source "$HOME/.nvm/nvm.sh"
nvm install 20
}

# Function to install Miniconda for Python
install_miniconda() {
echo "Installing Miniconda for Python dependencies..."
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
bash miniconda.sh -b -p $HOME/miniconda
source "$HOME/miniconda/etc/profile.d/conda.sh"
conda init
conda create -y -n openwebui python=3.11
conda activate openwebui
}

# Function to install Open WebUI with Docker
install_openwebui_docker() {
echo "Installing Open WebUI with Docker..."
docker pull ghcr.io/open-webui/open-webui:latest
docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:latest
echo "Open WebUI has been installed and started with Docker. Access it at http://localhost:3000"
}

# Function for Docker-less installation
dockerless_install() {
echo "Starting Docker-less installation..."

cd "$BASE_DIR/open-webui" # Change directory to the repository

# Check and install Node.js if necessary
check_nodejs

# Install Miniconda and Python Environment
install_miniconda

cp -RPp .env.example .env

if command -v npm &> /dev/null; then
npm install
npm run build
else
echo "npm is not available after Node.js installation. Exiting."
exit 1
fi

cd ./backend
pip install -r requirements.txt -U
echo "Open WebUI has been installed and started without Docker."

# Create and start the systemd service
create_openwebui_service
}

# Main script starts here
echo "Starting the Open WebUI installation script..."

if [ "$NO_DOCKER" -eq 1 ]; then
justinh-rahb marked this conversation as resolved.
Show resolved Hide resolved
echo "Proceeding with Docker-less installation due to --no-docker flag."
clone_repository
dockerless_install
echo "Installation process has completed."
exit 0
fi

# Step 1: Check for Docker
check_docker

# Skip Ollama-related options if --no-ollama flag is set
if [ "$NO_OLLAMA" -eq 0 ]; then
echo "Would you like to install Ollama directly (not inside Docker)? (y/n)"
read -r install_ollama_directly

if [ "$install_ollama_directly" = "y" ]; then
curl -fsSL https://ollama.com/install.sh | sh
echo "Ollama has been installed directly on the system."
configure_ollama_systemd
# No exit here; continue to WebUI installation
else
echo "Proceeding with Docker-based installation options..."
echo "Would you like to install Ollama inside Docker? (y/n)"
read -r install_ollama

if [ "$install_ollama" = "y" ]; then
echo "Installing Ollama with Docker..."
# Direct call to the script without GPU check, as the script handles it internally
(cd "$BASE_DIR/open-webui" && chmod +x run-ollama-docker.sh && ./run-ollama-docker.sh)
echo "Ollama has been installed with Docker."
# Continue to Docker Compose or direct WebUI installation
fi
fi
fi

# Ask about Docker Compose only if Ollama wasn't installed by previous options
echo "Would you like to deploy Open WebUI and Ollama together using Docker Compose? (y/n)"
read -r deploy_compose

if [ "$deploy_compose" = "y" ]; then
echo "Enable GPU support? (y/n)"
read -r enable_gpu
compose_cmd="./run-compose.sh"
if [ "$enable_gpu" = "y" ]; then
compose_cmd+=" --enable-gpu"
fi
echo "Running: $compose_cmd"
# Ensure script is run from the correct directory
(cd "$BASE_DIR/open-webui" && chmod +x $compose_cmd && ./$compose_cmd)
else
# If not using Docker Compose, just install Open WebUI with Docker
install_openwebui_docker
fi

echo "Installation process has completed."
47 changes: 47 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# Function to detect operating system
detect_os() {
OS="$(uname -s)"
case "$OS" in
Linux*)
MACHINE="Linux"
if grep -qi microsoft /proc/version; then
# Check if we're on WSL (Windows Subsystem for Linux)
MACHINE="WSL"
fi
;;
Darwin*)
MACHINE="MacOS"
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
MACHINE="Windows"
;;
*)
MACHINE="UNKNOWN:$OS"
;;
esac
echo $MACHINE
}

# Run the OS detection
OS=$(detect_os)

# Only proceed with the installation if the machine is plain Linux (not WSL)
if [ "$OS" = "Linux" ]; then
echo "Detected Linux environment. Starting the Open WebUI installation..."

# Define the URL of the main installation script
INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/open-webui/open-webui/installer/install-linux.sh"

# Fetch and execute the installation script
curl -fsSL "$INSTALL_SCRIPT_URL" | bash

echo "Thank you for being a user of Open WebUI! Be sure to visit https://openwebui.com/ for the latest updates and news."
elif [ "$OS" = "WSL" ]; then
echo "Detected Windows Subsystem for Linux (WSL). This installer is intended for native Linux environments only. Please visit https://docs.openwebui.com/getting-started/ for instructions on how to install Open WebUI on Windows."
exit 1
else
echo "Detected $OS. This installer only supports Linux environments. Please visit https://docs.openwebui.com/getting-started/ for instructions on how to install Open WebUI on your operating system."
exit 1
fi
14 changes: 14 additions & 0 deletions open-webui.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Open WebUI Service
After=network.target

[Service]
Type=simple
User=$(whoami)
# Ensure bash is used to execute the start script
ExecStart=/bin/bash $BASE_DIR/open-webui/backend/start.sh
Restart=always
EnvironmentFile=-/etc/open-webui/env

[Install]
WantedBy=multi-user.target