Skip to content

Instantly share code, notes, and snippets.

@cooniur
Last active March 1, 2026 21:55
Show Gist options
  • Select an option

  • Save cooniur/6fc9789b4f1c9b4832bac367094f85ad to your computer and use it in GitHub Desktop.

Select an option

Save cooniur/6fc9789b4f1c9b4832bac367094f85ad to your computer and use it in GitHub Desktop.
Ubuntu Server Setup
#!/bin/bash
# 1. Pre-check: Show current status
echo "--- CURRENT DISK STATUS (BEFORE) ---"
df -h /
echo ""
sudo vgs
echo "------------------------------------"
# 2. Identify the Logical Volume path automatically
LV_PATH=$(sudo lvs --noheadings -o lv_path | tr -d '[:space:]' | head -n 1)
if [ -z "$LV_PATH" ]; then
echo "Error: Could not automatically detect the Logical Volume path."
exit 1
fi
# 3. Ask for confirmation
read -p "Do you want to extend '$LV_PATH' to use all available free space? [y/N]: " CONFIRM
if [[ $CONFIRM != "y" && $CONFIRM != "Y" ]]; then
echo "Operation cancelled."
exit 0
fi
# 4. Perform the extension
echo "Extending Logical Volume at '$LV_PATH'..."
sudo lvextend -l +100%FREE "$LV_PATH"
echo "Resizing Filesystem at '$LV_PATH'..."
sudo resize2fs "$LV_PATH"
# 5. Final check
echo "------------------------------------"
echo "--- UPDATED DISK STATUS (AFTER) ---"
df -h /
#!/bin/bash
set -e
echo "--- NVIDIA & CUDA Auto-Discovery Tool ---"
# 1. Detect Recommended Driver
# Scans hardware to find the best driver branch (e.g., 590)
RECOMMENDED_DRIVER=$(ubuntu-drivers devices 2>/dev/null | grep "recommended" | grep -oP 'nvidia-driver-\K[0-9]+' | head -n 1)
# 2. Add CUDA Keyring for Ubuntu 24.04 to probe latest versions
if [ ! -f "cuda-keyring_1.1-1_all.deb" ]; then
wget -q https://developer.download.nvidia.com
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update -q
fi
# 3. Detect Latest CUDA Toolkit
# Finds the highest versioned toolkit in the repository
LATEST_CUDA_PKG=$(apt-cache search cuda-toolkit | grep -oP 'cuda-toolkit-\K[0-9]+-[0-9]+' | sort -V | tail -n 1)
LATEST_CUDA_VER=${LATEST_CUDA_PKG//-/. }
# 4. Confirmation Prompt
echo ""
echo "Auto-discovery results for your RTX 3070:"
echo " - Driver: nvidia-open-${RECOMMENDED_DRIVER}-server"
echo " - CUDA: cuda-toolkit-${LATEST_CUDA_PKG} (v${LATEST_CUDA_VER})"
echo ""
read -p "Do you want to proceed with this installation? (y/n): " confirm
if [[ $confirm != [yY] ]]; then
echo "Installation cancelled."
exit 1
fi
# 5. Execute Installation
echo "Installing... This may take several minutes."
sudo apt install -y -o Dpkg::Options::="--force-overwrite" \
dkms linux-headers-$(uname -r) \
nvidia-open-${RECOMMENDED_DRIVER}-server \
nvidia-utils-${RECOMMENDED_DRIVER}-server \
nvidia-dkms-${RECOMMENDED_DRIVER}-server \
cuda-toolkit-${LATEST_CUDA_PKG}
# 6. Environment Setup
CUDA_DIR="/usr/local/cuda-${LATEST_CUDA_VER// /}"
if [ -d "$CUDA_DIR" ]; then
# Add to .bashrc
grep -q "$CUDA_DIR/bin" ~/.bashrc || echo "export PATH=$CUDA_DIR/bin:\$PATH" >> ~/.bashrc
grep -q "$CUDA_DIR/lib64" ~/.bashrc || echo "export LD_LIBRARY_PATH=$CUDA_DIR/lib64:\$LD_LIBRARY_PATH" >> ~/.bashrc
# System-wide library link
echo "$CUDA_DIR/lib64" | sudo tee /etc/ld.so.conf.d/cuda-auto.conf > /dev/null
sudo ldconfig
fi
echo "--------------------------------------------------------"
echo "COMPLETED SUCCESSFULLY"
echo "--------------------------------------------------------"
echo "IMPORTANT: Ubuntu 24.04 requires a MOK Enrollment on reboot."
echo "1. Run: sudo reboot"
echo "2. At the Blue Screen: Enroll MOK -> Continue -> Yes -> [Your Password]"
echo "3. After reboot, test with: nvidia-smi"
echo "--------------------------------------------------------"
#!/bin/bash
set -e
echo "--- Ollama Installation & Remote Access Setup ---"
# 1. Run official Ollama installation script
# This installs the binary and registers the systemd service
curl -fsSL https://ollama.com | sh
# 2. Configure Remote Access (Listen on 0.0.0.0)
# We edit the service file directly to ensure 100% compatibility with Ubuntu 24.x
SERVICE_FILE="/etc/systemd/system/ollama.service"
if [ -f "$SERVICE_FILE" ]; then
echo "Configuring Ollama to listen on all interfaces..."
# Remove any existing OLLAMA_HOST/ORIGINS lines to prevent duplicates
sudo sed -i '/Environment="OLLAMA_HOST=/d' "$SERVICE_FILE"
sudo sed -i '/Environment="OLLAMA_ORIGINS=/d' "$SERVICE_FILE"
# Add new remote-friendly environment variables under the [Service] section
sudo sed -i '/\[Service\]/a Environment="OLLAMA_HOST=0.0.0.0:11434"\nEnvironment="OLLAMA_ORIGINS=*"' "$SERVICE_FILE"
else
echo "Error: Ollama service file not found at $SERVICE_FILE"
exit 1
fi
# 3. Open Firewall Port (UFW)
if command -v ufw > /dev/null; then
echo "Opening port 11434 in Ubuntu Firewall..."
sudo ufw allow 11434/tcp
sudo ufw reload
fi
# 4. Restart Service to Apply Changes
echo "Restarting Ollama..."
sudo systemctl daemon-reload
sudo systemctl restart ollama
# 5. Verification
echo "--------------------------------------------------------"
echo "VERIFICATION:"
echo " Check if the listener is now on 0.0.0.0 (not 127.0.0.1)"
ss -tuln | grep 11434
echo "--------------------------------------------------------"
echo "SUCCESS! To access from your laptop:"
echo "1. Browser: http://$(hostname -I | awk '{print $1}'):11434"
echo "2. CLI: export OLLAMA_HOST=$(hostname -I | awk '{print $1}'):11434"
echo "--------------------------------------------------------"
#!/bin/bash
set -e
# 1. Install Docker (if not present)
if ! command -v docker &> /dev/null; then
echo "Installing Docker..."
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
echo "Docker installed. Note: You may need to logout/login for group changes."
fi
# 2. Configure Ollama Service for the Domain
# Updates OLLAMA_HOST and OLLAMA_ORIGINS to allow the .lan domain
SERVICE_FILE="/etc/systemd/system/ollama.service"
if [ -f "$SERVICE_FILE" ]; then
echo "Updating Ollama service for myubuntu.lan..."
sudo sed -i '/Environment="OLLAMA_HOST=/d' "$SERVICE_FILE"
sudo sed -i '/Environment="OLLAMA_ORIGINS=/d' "$SERVICE_FILE"
# Add explicit support for the domain and wildcard for other apps
sudo sed -i '/\[Service\]/a Environment="OLLAMA_HOST=0.0.0.0:11434"\nEnvironment="OLLAMA_ORIGINS=http://myubuntu.lan:3000,http://myubuntu.lan,http://localhost:3000,*"' "$SERVICE_FILE"
sudo systemctl daemon-reload
sudo systemctl restart ollama
else
echo "Warning: Ollama service file not found. Skipping CORS config."
fi
# 3. Deploy Open WebUI via Docker
# Maps port 3000 and connects to the host's Ollama instance
echo "Deploying Open WebUI container..."
sudo docker rm -f open-webui 2>/dev/null || true
sudo 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:main
# 4. Open Firewall
if command -v ufw > /dev/null; then
sudo ufw allow 3000/tcp
sudo ufw reload
fi
echo "--------------------------------------------------------"
echo "SETUP COMPLETE"
echo "URL: http://myubuntu.lan:3000"
echo "--------------------------------------------------------"
#!/bin/bash
Update logind.conf for Lid and Power settings
echo "Configuring systemd-logind to ignore all default triggers..."
CONF="/etc/systemd/logind.conf"
sudo cp $CONF "${CONF}.bak"
# Set power and lid triggers to ignore in the OS
sudo sed -i 's/^#\?HandlePowerKey=.*/HandlePowerKey=lock/' $CONF
sudo sed -i 's/^#\?HandleLidSwitch=.*/HandleLidSwitch=ignore/' $CONF
sudo sed -i 's/^#\?HandleLidSwitchExternalPower=.*/HandleLidSwitchExternalPower=ignore/' $CONF
sudo sed -i 's/^#\?HandleLidSwitchDocked=.*/HandleLidSwitchDocked=ignore/' $CONF
# Apply the changes
echo "------------------------------------------"
echo "Applying changes..."
sudo systemctl restart systemd-logind
echo "...Done."
echo "------------------------------------------"
echo "Setup Complete!"
echo " - Lid Close (Any state): Stays ON"
echo " - Power Key (Short Tap): Lock Screen"
echo " - Power Key (Long Hold): Hardware Force Power OFF"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment