Wren Linux

wren-linux / extras / claude-regular.sh

#!/bin/bash
# retired: Claude Code running as you can read all your files. Use claude-vm (the most walled off) or claude-code (its own user) instead.
# 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 claude-regular. It can't be installed any more; the rest of it was deleted.
# Usage: bash claude-regular.sh --remove
# summary: Claude Code as you, with its own sandbox on
# security: least
# category: dev
# status: bin:claude-regular bin:claude-open-link
. "$(dirname -- "${BASH_SOURCE[0]}")/../lib.sh"
. "$WREN_DIR/lib/claude-repo.sh"
. "$WREN_DIR/lib/claude-accounts.sh"
if [ "${1:-}" = --manual ]; then echo "Retired: only --remove is left (bash extras/claude-regular.sh --remove)."; exit; fi
need_user

SETTINGS=$HOME/.claude/settings.json
STATE=${XDG_STATE_HOME:-$HOME/.local/state}/wren/claude-regular-settings.json
merge() { python3 -I "$WREN_DIR/lib/claude-settings.py" "$1" "$SETTINGS" "$WREN_DIR/data/claude-regular-settings.json" "$STATE"; }

# account NAME: its folder and the two state files (its own settings, and
# what was added to the first account's to keep it out)
account() {
    [[ $1 =~ ^[a-z][a-z0-9]{0,14}$ ]] || die "An account name is small letters and digits, a letter first, at most 15 (e.g. work)."
    ACCOUNT_DIR=$HOME/.claude-$1
    ACCOUNT_STATE=${STATE%.json}-$1.json
    MAIN_STATE=${STATE%.json}-$1-first.json
}

remove_account() {
    account "$1"
    [ ! -f "$MAIN_STATE" ] || python3 -I "$WREN_DIR/lib/claude-settings.py" remove "$SETTINGS" /dev/null "$MAIN_STATE" || true
    [ ! -f "$ACCOUNT_STATE" ] || python3 -I "$WREN_DIR/lib/claude-settings.py" remove "$ACCOUNT_DIR/settings.json" /dev/null "$ACCOUNT_STATE" || true
    rm -f "$MAIN_STATE" "$ACCOUNT_STATE"
    if [ -d "$ACCOUNT_DIR" ] && ask "Delete $ACCOUNT_DIR (that account's Claude login, memories and settings)?" n; then
        rm -rf "${ACCOUNT_DIR:?}"
        note "Deleted $ACCOUNT_DIR."
    elif [ -d "$ACCOUNT_DIR" ]; then
        note "Kept $ACCOUNT_DIR."
    fi
}

if [ "${1:-}" = --remove ]; then
    # the other accounts first, each with its own question
    for st in "${STATE%.json}"-*-first.json; do
        [ -f "$st" ] || continue
        n=${st##*/claude-regular-settings-}
        remove_account "${n%-first.json}"
    done
    remove_bin claude-regular
    remove_bin claude-open-link
    remove_claude_chooser
    if [ -f "$STATE" ]; then merge remove && note "Took Wren Linux's settings out of $SETTINGS; yours stay."; fi
    # claude-code itself stays while the sandboxed claude needs it
    apt_purge claude-code
    remove_claude_repo_if_unused
    note "Your Claude login and settings stay in ~/.claude."
    exit
fi

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