Last active
April 15, 2026 12:11
-
-
Save nazt/6b2d7b3c55e2fda10ea2d4eb214e89fb to your computer and use it in GitHub Desktop.
Unified Colab bootstrap — one script, parameterized (replaces 3 separate gists)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # === Unified Colab Bootstrap === | |
| # Usage (in Colab notebook): | |
| # !curl -fsSL <raw-url> | bash -s colab | |
| # !curl -fsSL <raw-url> | bash -s colab2 | |
| # !curl -fsSL <raw-url> | bash -s colab3 | |
| # | |
| # Tokens are embedded per-VM. Override via env var if needed. | |
| set -euo pipefail | |
| NAME="${1:-colab}" | |
| echo "=== ${NAME}.laris.co bootstrap ===" | |
| # Embedded tokens (from CF tunnel config, one per VM) | |
| TOKEN_COLAB="eyJhIjoiYTVlYWJkYzJiMTFhYWU5YmQ1YWY0NmJkNmE4ODE3OWUiLCJ0IjoiZjY3ZjRjMmYtYmViYS00ZTc2LWJhNzQtZTFjYjNjMDA5ODEyIiwicyI6Ik5HSXhOV0UyT1RZdE5UVTVPQzAwWVdJeExUZ3dNRFl0WXpJeVl6RTROMlkzTTJRMCJ9" | |
| TOKEN_COLAB2="eyJhIjoiYTVlYWJkYzJiMTFhYWU5YmQ1YWY0NmJkNmE4ODE3OWUiLCJ0IjoiNzc0NDNhMjItYmI1Ni00OWZiLTgxYzgtZmZiM2E2NmY3OWNmIiwicyI6IllUZ3pZamd3WVRZdE5HRXhNaTAwWm1Jd0xXRmpOall0WkdZeFptTmlPR0l6T0dRdyJ9" | |
| # NOTE: colab3 needs its own token — currently shares colab2's (routing bug!) | |
| TOKEN_COLAB3="$TOKEN_COLAB2" | |
| # Resolve: env var overrides embedded token | |
| case "$NAME" in | |
| colab) TOKEN="${CF_TUNNEL_TOKEN:-$TOKEN_COLAB}" ;; | |
| colab2) TOKEN="${CF_TUNNEL_TOKEN_COLAB2:-$TOKEN_COLAB2}" ;; | |
| colab3) TOKEN="${CF_TUNNEL_TOKEN_COLAB3:-$TOKEN_COLAB3}" ;; | |
| *) echo "Unknown VM: $NAME (use: colab, colab2, colab3)"; exit 1 ;; | |
| esac | |
| # Kill existing tunnel | |
| pkill -f 'cloudflared tunnel run' 2>/dev/null || true | |
| pkill -x cloudflared 2>/dev/null || true | |
| sleep 1 | |
| echo "[1/4] Installing cloudflared..." | |
| curl -fsSL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 \ | |
| -o /usr/local/bin/cloudflared && chmod +x /usr/local/bin/cloudflared | |
| echo "[2/4] Setting up SSH..." | |
| apt-get update -qq && apt-get install -y -qq openssh-server > /dev/null 2>&1 | |
| mkdir -p /run/sshd /root/.ssh && chmod 700 /root/.ssh | |
| curl -fsSL https://github.com/nazt.keys > /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys | |
| sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config | |
| sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config | |
| pkill -x sshd 2>/dev/null || true; /usr/sbin/sshd | |
| echo "[3/4] Starting tunnel (${NAME}.laris.co)..." | |
| nohup /usr/local/bin/cloudflared tunnel --no-autoupdate run --token "$TOKEN" > /tmp/cf-${NAME}.log 2>&1 & | |
| sleep 3 | |
| pgrep -f 'cloudflared.*tunnel.*run' > /dev/null || { echo "Tunnel failed:"; tail -5 /tmp/cf-${NAME}.log; exit 1; } | |
| echo "[4/4] Fixing GPU libs..." | |
| echo "/usr/lib64-nvidia" | tee /etc/ld.so.conf.d/zz-colab-nvidia.conf > /dev/null; ldconfig 2>/dev/null | |
| echo "=== ${NAME}.laris.co ready ===" | |
| echo "GPU: $(nvidia-smi --query-gpu=name,memory.total --format=csv,noheader 2>/dev/null || echo none)" | |
| echo "SSH: ssh ${NAME}.laris.co" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment