mirror of
https://github.com/casjaysdevdocker/claude
synced 2026-06-24 02:01:03 -04:00
9114c4098d
Migrate claude Docker image to the new build-time config architecture. - rootfs/root/docker/setup/03-files.sh: rewrite to canonical form with /tmp/bin, /tmp/var, /tmp/etc, /tmp/usr handlers - rootfs/usr/local/etc/docker/functions/entrypoint.sh: update to latest template - rootfs/usr/local/etc/docker/init.d/*.sh: fix $(basename) UUOC; move inline comments above code lines - rootfs/tmp/etc/: add service config files (claude ) deployed to /etc/ at build time - rootfs/usr/local/share/template-files/: delete; config now deployed via /tmp/etc/ and /tmp/usr/ at build time rootfs/root/docker/setup/03-files.sh rootfs/tmp/ rootfs/usr/local/etc/docker/functions/entrypoint.sh rootfs/usr/local/etc/docker/init.d/01-dockerd.sh rootfs/usr/local/etc/docker/init.d/99-claude.sh rootfs/usr/local/share/template-files/config/claude/settings.json rootfs/usr/local/share/template-files/config/env/default.sample rootfs/usr/local/share/template-files/config/env/examples/00-directory.sh rootfs/usr/local/share/template-files/config/env/examples/addresses.sh rootfs/usr/local/share/template-files/config/env/examples/certbot.sh rootfs/usr/local/share/template-files/config/env/examples/couchdb.sh rootfs/usr/local/share/template-files/config/env/examples/dockerd.sh rootfs/usr/local/share/template-files/config/env/examples/global.sh rootfs/usr/local/share/template-files/config/env/examples/healthcheck.sh rootfs/usr/local/share/template-files/config/env/examples/mariadb.sh rootfs/usr/local/share/template-files/config/env/examples/mongodb.sh rootfs/usr/local/share/template-files/config/env/examples/networking.sh rootfs/usr/local/share/template-files/config/env/examples/other.sh rootfs/usr/local/share/template-files/config/env/examples/php.sh rootfs/usr/local/share/template-files/config/env/examples/postgres.sh rootfs/usr/local/share/template-files/config/env/examples/redis.sh rootfs/usr/local/share/template-files/config/env/examples/services.sh rootfs/usr/local/share/template-files/config/env/examples/ssl.sh rootfs/usr/local/share/template-files/config/env/examples/supabase.sh rootfs/usr/local/share/template-files/config/env/examples/webservers.sh rootfs/usr/local/share/template-files/config/env/examples/zz-entrypoint.sh rootfs/usr/local/share/template-files/config/.gitkeep rootfs/usr/local/share/template-files/data/.gitkeep rootfs/usr/local/share/template-files/defaults/.gitkeep
99 lines
3.9 KiB
Bash
Executable File
99 lines
3.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# shellcheck shell=bash
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
##@Version : 202601221200-git
|
|
# @@Author : CasjaysDev
|
|
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
|
# @@License : MIT
|
|
# @@Copyright : Copyright 2026 CasjaysDev
|
|
# @@Created : Wed Jan 22 12:00:00 PM EST 2026
|
|
# @@File : 99-claude.sh
|
|
# @@Description : Init script to run Claude Code CLI
|
|
# @@Changelog : newScript
|
|
# @@TODO : Better documentation
|
|
# @@Other :
|
|
# @@Resource :
|
|
# @@Terminal App : no
|
|
# @@sudo/root : no
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
SCRIPT_NAME="${0##*/}"
|
|
SCRIPT_PID_FILE="/run/init.d/$SCRIPT_NAME.pid"
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Set env/config variables
|
|
CLAUDE_CONFIG_DIR="${CLAUDE_CONFIG_DIR:-/config/claude}"
|
|
CLAUDE_SETTINGS_FILE="${CLAUDE_SETTINGS_FILE:-$CLAUDE_CONFIG_DIR/settings.json}"
|
|
CLAUDE_WORK_DIR="${CLAUDE_WORK_DIR:-${PWD:-/app}}"
|
|
CLAUDE_ADDITIONAL_ARGS="${CLAUDE_ADDITIONAL_ARGS:-}"
|
|
ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-}"
|
|
# Tell init system this service doesn't use traditional PID tracking
|
|
SERVICE_USES_PID="no"
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Show authentication info
|
|
if [ -n "$ANTHROPIC_API_KEY" ]; then
|
|
echo "Using Anthropic API key from environment"
|
|
else
|
|
echo "No API key detected - Claude Code will prompt for authentication"
|
|
echo "You can use either:"
|
|
echo " 1. Anthropic API key: -e ANTHROPIC_API_KEY=your_key"
|
|
echo " 2. Claude Pro subscription: Claude Code will authenticate interactively"
|
|
fi
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Ensure claude config directory exists
|
|
mkdir -p "$CLAUDE_CONFIG_DIR" 2>/dev/null || true
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Initialize settings.json if it doesn't exist
|
|
if [ ! -f "$CLAUDE_SETTINGS_FILE" ]; then
|
|
if [ -f "/etc/claude/settings.json" ]; then
|
|
echo "Initializing Claude Code settings from template"
|
|
cp -f "/etc/claude/settings.json" "$CLAUDE_SETTINGS_FILE"
|
|
fi
|
|
fi
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Set up symlink for settings in home directory
|
|
mkdir -p "$HOME/.claude" 2>/dev/null || true
|
|
if [ ! -L "$HOME/.claude/settings.json" ]; then
|
|
ln -sf "$CLAUDE_SETTINGS_FILE" "$HOME/.claude/settings.json" 2>/dev/null || true
|
|
fi
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Change to working directory
|
|
cd "$CLAUDE_WORK_DIR" || exit 1
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Write PID file
|
|
echo $$ >"$SCRIPT_PID_FILE"
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Start Claude Code CLI
|
|
echo "Starting Claude Code CLI in persistent screen session..."
|
|
echo "Working directory: $CLAUDE_WORK_DIR"
|
|
echo "Settings: $CLAUDE_SETTINGS_FILE"
|
|
echo ""
|
|
echo "To attach to Claude session: docker exec -it <container> screen -r claude"
|
|
echo "To detach from session: Ctrl+A then D"
|
|
echo "To list sessions: screen -ls"
|
|
echo "---"
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# Check if screen session already exists
|
|
if screen -list | grep -q "\.claude[[:space:]]"; then
|
|
echo "Claude screen session already running"
|
|
exit 0
|
|
else
|
|
# Start claude in a detached screen session named "claude"
|
|
screen -dmS claude bash -c "cd '$CLAUDE_WORK_DIR' && claude --dangerously-skip-permissions $CLAUDE_ADDITIONAL_ARGS"
|
|
|
|
# Wait a moment for screen to initialize
|
|
sleep 2
|
|
|
|
# Verify screen session was created
|
|
if screen -list | grep -q "\.claude[[:space:]]"; then
|
|
echo "Claude screen session started successfully"
|
|
echo "Attach with: screen -r claude"
|
|
exit 0
|
|
else
|
|
echo "Failed to start Claude screen session" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
# ex: ts=2 sw=2 et filetype=sh
|