summaryrefslogtreecommitdiffstats
path: root/scripts/auto-opencode-setup.sh
diff options
context:
space:
mode:
authorOpen-IOV <dev@open-iov.org>2026-09-23 05:44:08 -0400
committerOpen-IOV <dev@open-iov.org>2026-09-23 05:46:43 -0400
commit68cdd7728a7cc6715bbbff7decfe2b11c3bdf558 (patch)
tree3dc8ce2e6af313a97ec6852f5c663a9a93665d2e /scripts/auto-opencode-setup.sh
downloadopen-iov-68cdd7728a7cc6715bbbff7decfe2b11c3bdf558.tar.gz
open-iov-68cdd7728a7cc6715bbbff7decfe2b11c3bdf558.zip
Open-IOV: initial public release
Open-IOV virtualizes NVIDIA GPUs so that unmodified guest drivers run with real GPU functionality - CUDA first, 3D and video to follow - on unmodified hosts, without a proprietary vGPU license and without patching any driver, firmware or hypervisor. Core principle: emulate the interface, pass through the work. kernel/ open-iov-vfio.ko - host VFIO mdev driver: virtual GPU device (PCI config space, BAR shadows, MSI-X), GSP boot emulation, GSP-RM message-queue/RPC emulation, memory model (GPU-VA to guest-PA discovery) and the semaphore-completion service that advances guest UVM progress. userspace/ libiov.so management API and examples. tools/ guest diagnostics, firmware analysis wrappers, RM probes. scripts/ stack manager, VM harness, build/load/test automation. config/ hardware/version profiles (the portability surface). docs/ documentation tree - start at docs/README.md. wiki/ long-form firmware and protocol deep dives. Status: initialization works end to end for a stock 570.144 Linux guest on Turing (TU104): driver probe, nvidia-smi, the full GSP-RM control battery, object creation and the early CUDA/UVM start-up path. GPU work forwarding - the step that makes CUDA kernels execute on real hardware - is the active work item; see docs/04-implementation/01-known-knowns-and-unknowns.md. License: BSD-3-Clause for the project; GPL-2.0 for kernel modules that link GPL-only kernel interfaces. See LICENSE and docs/09-reference/legal-and-licensing.md.
Diffstat (limited to 'scripts/auto-opencode-setup.sh')
-rwxr-xr-xscripts/auto-opencode-setup.sh327
1 files changed, 327 insertions, 0 deletions
diff --git a/scripts/auto-opencode-setup.sh b/scripts/auto-opencode-setup.sh
new file mode 100755
index 0000000..4126d3d
--- /dev/null
+++ b/scripts/auto-opencode-setup.sh
@@ -0,0 +1,327 @@
+#!/bin/bash
+# auto-opencode-setup.sh - Configure auto-opencode session on login
+# Usage: sudo ./auto-opencode-setup.sh [enable|disable] [graphical|multi-user] [auto-login]
+
+set -euo pipefail
+
+AUTO_OPENCODE_DIR="$HOME/.config/auto-opencode"
+AUTO_OPENCODE_SCRIPT="$AUTO_OPENCODE_DIR/auto-opencode.sh"
+AUTO_OPENCODE_MARKER="$AUTO_OPENCODE_DIR/enabled"
+AUTO_LOGIN_MARKER="$AUTO_OPENCODE_DIR/auto-login"
+TARGET_MARKER="$AUTO_OPENCODE_DIR/target"
+
+log_info() { echo -e "\033[0;34m[INFO]\033[0m $1"; }
+log_ok() { echo -e "\033[0;32m[OK]\033[0m $1"; }
+log_warn() { echo -e "\033[1;33m[WARN]\033[0m $1"; }
+log_error() { echo -e "\033[0;31m[ERROR]\033[0m $1"; }
+
+usage() {
+ cat <<EOF
+Usage: $0 [enable|disable] [graphical|multi-user] [auto-login] [auto-opencode]
+
+Configure auto-opencode session on login.
+
+Commands:
+ enable - Enable auto-opencode
+ disable - Disable auto-opencode
+ status - Show current configuration
+
+Options:
+ graphical|multi-user - Boot target (default: graphical)
+ auto-login - Enable automatic login (graphical: GDM, multi-user: getty)
+ auto-opencode - Start opencode tmux session on login
+
+Examples:
+ $0 enable graphical auto-login auto-opencode
+ $0 enable multi-user auto-opencode
+ $0 disable
+ $0 status
+EOF
+}
+
+create_auto_opencode_script() {
+ mkdir -p "$AUTO_OPENCODE_DIR"
+
+ cat > "$AUTO_OPENCODE_SCRIPT" <<'SCRIPTEOF'
+#!/bin/bash
+# auto-opencode.sh - Runs on login to start opencode tmux session
+# This script is sourced from .zprofile (multi-user) or .xprofile (graphical)
+
+AUTO_OPENCODE_DIR="$HOME/.config/auto-opencode"
+AUTO_OPENCODE_MARKER="$AUTO_OPENCODE_DIR/enabled"
+AUTO_LOGIN_MARKER="$AUTO_OPENCODE_DIR/auto-login"
+
+# Check if auto-opencode is enabled
+[[ -f "$AUTO_OPENCODE_MARKER" ]] || exit 0
+
+# Prevent multiple runs
+if [[ -n "$AUTO_OPENCODE_STARTED" ]]; then
+ exit 0
+fi
+export AUTO_OPENCODE_STARTED=1
+
+# Only run in interactive shells
+[[ $- == *i* ]] || exit 0
+
+# Check if tmux is available
+command -v tmux &>/dev/null || exit 0
+command -v opencode &>/dev/null || exit 0
+
+# Check if we're already in tmux
+[[ -n "$TMUX" ]] && exit 0
+
+# Target directory
+TARGET_DIR="__OPEN_IOV_PARENT__"
+
+# Session name
+SESSION_NAME="auto-opencode"
+
+# Check if session already exists
+if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
+ echo "Attaching to existing $SESSION_NAME session..."
+ exec tmux attach-session -t "$SESSION_NAME"
+fi
+
+# Create new tmux session with opencode
+echo "Starting auto-opencode session..."
+cd "$TARGET_DIR"
+
+# Start tmux session
+tmux new-session -d -s "$SESSION_NAME" -c "$TARGET_DIR" \
+ "opencode --dangerously-skip-permissions"
+
+# Wait a moment for opencode to start
+sleep 2
+
+# Send initial commands to read AGENTS.md and handoff
+tmux send-keys -t "$SESSION_NAME" "cat AGENTS.md" Enter
+sleep 1
+tmux send-keys -t "$SESSION_NAME" "cat Handoff-vGPU-IO.md" Enter
+sleep 1
+
+# Attach to session
+exec tmux attach-session -t "$SESSION_NAME"
+SCRIPTEOF
+
+ # Bake in the repo parent dir (resolved at setup time)
+ local repo_parent
+ repo_parent="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
+ sed -i "s|__OPEN_IOV_PARENT__|$repo_parent|g" "$AUTO_OPENCODE_SCRIPT"
+ chmod +x "$AUTO_OPENCODE_SCRIPT"
+ log_ok "Created auto-opencode script: $AUTO_OPENCODE_SCRIPT"
+}
+
+setup_graphical_autologin() {
+ log_info "Setting up graphical auto-login (GDM)..."
+
+ # Create GDM custom.conf for auto-login
+ sudo mkdir -p /etc/gdm3
+ sudo tee /etc/gdm3/custom.conf > /dev/null <<EOF
+[daemon]
+AutomaticLoginEnable=true
+AutomaticLogin=${USER}
+WaylandEnable=false
+
+[security]
+
+[xdmcp]
+
+[chooser]
+
+[debug]
+EOF
+
+ # Add auto-opencode to graphical session startup
+ mkdir -p $HOME/.config/autostart
+ cat > $HOME/.config/autostart/auto-opencode.desktop <<EOF
+[Desktop Entry]
+Type=Application
+Name=Auto OpenCode
+Exec=$HOME/.config/auto-opencode/auto-opencode.sh
+Hidden=false
+NoDisplay=false
+X-GNOME-Autostart-enabled=true
+EOF
+
+ log_ok "Graphical auto-login configured"
+}
+
+setup_multiuser_autologin() {
+ log_info "Setting up multi-user auto-login (getty)..."
+
+ # Create systemd override for getty@tty1
+ sudo mkdir -p /etc/systemd/system/getty@tty1.service.d
+ sudo tee /etc/systemd/system/getty@tty1.service.d/autologin.conf > /dev/null <<EOF
+[Service]
+ExecStart=
+ExecStart=-/sbin/agetty --autologin rmcore --noclear %I \$TERM
+EOF
+
+ # Add auto-opencode to .zprofile for multi-user login
+ if ! grep -q "auto-opencode.sh" $HOME/.zprofile 2>/dev/null; then
+ cat >> $HOME/.zprofile <<'EOF'
+
+# Auto-opencode on login
+if [[ -f $HOME/.config/auto-opencode/auto-opencode.sh ]]; then
+ source $HOME/.config/auto-opencode/auto-opencode.sh
+fi
+EOF
+ fi
+
+ log_ok "Multi-user auto-login configured"
+}
+
+disable_autologin() {
+ log_info "Disabling auto-login..."
+
+ # Remove GDM auto-login
+ if [[ -f /etc/gdm3/custom.conf ]]; then
+ sudo sed -i '/^AutomaticLoginEnable=/d' /etc/gdm3/custom.conf
+ sudo sed -i '/^AutomaticLogin=/d' /etc/gdm3/custom.conf
+ fi
+
+ # Remove getty auto-login
+ sudo rm -f /etc/systemd/system/getty@tty1.service.d/autologin.conf
+
+ # Remove autostart desktop entry
+ rm -f $HOME/.config/autostart/auto-opencode.desktop
+
+ # Remove from .zprofile
+ sed -i '/auto-opencode.sh/d' $HOME/.zprofile 2>/dev/null || true
+
+ log_ok "Auto-login disabled"
+}
+
+enable_auto_opencode() {
+ local target="${1:-graphical}"
+ local auto_login="${2:-false}"
+ local auto_opencode="${3:-false}"
+
+ log_info "Enabling auto-opencode (target: $target, auto-login: $auto_login, auto-opencode: $auto_opencode)"
+
+ create_auto_opencode_script
+
+ # Set target
+ echo "$target" > "$TARGET_MARKER"
+
+ # Set boot target
+ sudo systemctl set-default "$target.target"
+ log_ok "Boot target set to $target.target"
+
+ # Handle auto-login
+ if [[ "$auto_login" == "true" ]]; then
+ touch "$AUTO_LOGIN_MARKER"
+ if [[ "$target" == "graphical" ]]; then
+ setup_graphical_autologin
+ else
+ setup_multiuser_autologin
+ fi
+ else
+ rm -f "$AUTO_LOGIN_MARKER"
+ disable_autologin
+ fi
+
+ # Handle auto-opencode
+ if [[ "$auto_opencode" == "true" ]]; then
+ touch "$AUTO_OPENCODE_MARKER"
+ log_ok "Auto-opencode enabled"
+ else
+ rm -f "$AUTO_OPENCODE_MARKER"
+ log_ok "Auto-opencode disabled"
+ fi
+
+ log_ok "Configuration complete"
+}
+
+disable_auto_opencode() {
+ log_info "Disabling auto-opencode..."
+
+ rm -f "$AUTO_OPENCODE_MARKER"
+ rm -f "$AUTO_LOGIN_MARKER"
+ rm -f "$TARGET_MARKER"
+
+ disable_autologin
+
+ # Remove auto-opencode script
+ rm -f "$AUTO_OPENCODE_SCRIPT"
+
+ log_ok "Auto-opencode disabled"
+}
+
+show_status() {
+ echo "═══════════════════════════════════════════════════════════════"
+ echo " AUTO-OPENCODE STATUS"
+ echo "═══════════════════════════════════════════════════════════════"
+
+ if [[ -f "$AUTO_OPENCODE_MARKER" ]]; then
+ echo " Auto-opencode: ENABLED"
+ else
+ echo " Auto-opencode: DISABLED"
+ fi
+
+ if [[ -f "$AUTO_LOGIN_MARKER" ]]; then
+ echo " Auto-login: ENABLED"
+ else
+ echo " Auto-login: DISABLED"
+ fi
+
+ if [[ -f "$TARGET_MARKER" ]]; then
+ echo " Boot target: $(cat "$TARGET_MARKER")"
+ else
+ echo " Boot target: $(systemctl get-default | sed 's/.target$//')"
+ fi
+
+ echo " Current default: $(systemctl get-default)"
+ echo "═══════════════════════════════════════════════════════════════"
+}
+
+main() {
+ local action="${1:-status}"
+ shift || true
+
+ local target="graphical"
+ local auto_login="false"
+ local auto_opencode="false"
+
+ # Parse remaining arguments
+ for arg in "$@"; do
+ case "$arg" in
+ graphical|multi-user)
+ target="$arg"
+ ;;
+ auto-login|auto-login=on)
+ auto_login="true"
+ ;;
+ auto-login=off)
+ auto_login="false"
+ ;;
+ auto-opencode|auto-opencode=on)
+ auto_opencode="true"
+ ;;
+ auto-opencode=off)
+ auto_opencode="false"
+ ;;
+ *)
+ log_warn "Unknown argument: $arg"
+ ;;
+ esac
+ done
+
+ case "$action" in
+ enable)
+ enable_auto_opencode "$target" "$auto_login" "$auto_opencode"
+ ;;
+ disable)
+ disable_auto_opencode
+ ;;
+ status)
+ show_status
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+}
+
+main "$@" \ No newline at end of file