Wren Linux

wren-linux / extras / opencode-vm.sh

#!/bin/bash
# retired: a second copy of claude-vm's machinery, for little use. claude-vm stays: wrenctl install claude-vm.
# What is left of this extra is its --remove, for whoever still has it set up: update.sh offers it,
# and so does wrenctl remove opencode-vm. It can't be installed any more; the rest of it was deleted.
# Usage: bash opencode-vm.sh --remove
# summary: opencode in a disposable VM (no shared folder)
# security: most
# category: dev
# status: bin:opencode-vm file:/usr/local/libexec/opencode-vm-session
. "$(dirname -- "${BASH_SOURCE[0]}")/../lib.sh"
if [ "${1:-}" = --manual ]; then echo "Retired: only --remove is left (bash extras/opencode-vm.sh --remove)."; exit; fi
need_user

AGENT=opencode-vm
AGENT_HOME=/home/$AGENT
SESSION=/usr/local/libexec/opencode-vm-session
MOCKVPS=/usr/local/libexec/opencode-vm-mockvps-kvm
SUDOERS=/etc/sudoers.d/wren-opencode-vm
FIREWALL=/etc/wren/opencode-vm.nft
UNIT=/etc/systemd/system/wren-opencode-vm-firewall.service
PROVISION_DST=$AGENT_HOME/.config/opencode-vm/provision.sh
VM_USER=agent

if [ "${1:-}" = --remove ]; then
    remove_bin opencode-vm
    sudo systemctl disable --now wren-opencode-vm-firewall.service >/dev/null 2>&1 || true
    sudo nft delete table inet wren_opencode_vm 2>/dev/null || true
    sudo rm -f "$SUDOERS" "$SESSION" "$MOCKVPS" "$FIREWALL" "$UNIT"
    remove_no_abstract
    remove_net_check
    sudo systemctl daemon-reload >/dev/null 2>&1 || true
    sudo rmdir /usr/local/libexec /etc/wren 2>/dev/null || true
    if id "$AGENT" >/dev/null 2>&1; then
        if ask "Delete the user $AGENT and its home folder $AGENT_HOME (the VM disk, its ssh key and settings)?" n; then
            sudo pkill -KILL -u "$AGENT" 2>/dev/null || true
            sudo userdel -r "$AGENT" 2>/dev/null || sudo userdel "$AGENT"
            note "Removed the user $AGENT and its VM."
        else
            note "Kept the user $AGENT and $AGENT_HOME (the VM is still there)."
        fi
    fi
    # QEMU and friends go unless another script's marker still needs them
    apt_purge qemu-system-x86 qemu-utils socat nftables
    note "Removed the opencode-vm sandbox. The Claude extras, if installed, are untouched."
    exit
fi

die "Retired: claude-vm stays (wrenctl install claude-vm). Only --remove is left."