Files
claude-hub/scripts/archived/one-time/cleanup-scripts.sh
Jonathan Flatt 07b6e01040 Reorganize scripts into structured directory layout and consolidate functionality
This commit reorganizes all scripts in the repository into a more structured directory layout for better maintainability:
- Categorizes scripts by functionality (setup, build, aws, runtime, security, utils)
- Organizes test scripts into logical categories
- Consolidates redundant scripts with unified interfaces
- Adds backward compatibility wrappers
- Adds detailed SCRIPTS.md documentation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-21 00:19:07 +00:00

263 lines
8.5 KiB
Bash
Executable File

#!/bin/bash
set -e
# Script to clean up redundant scripts after reorganization
echo "Starting script cleanup..."
# Create a backup directory for redundant scripts
BACKUP_DIR="./scripts/archived"
mkdir -p "$BACKUP_DIR"
echo "Created backup directory: $BACKUP_DIR"
# Function to archive a script instead of deleting it
archive_script() {
local script=$1
if [ -f "$script" ]; then
echo "Archiving $script to $BACKUP_DIR"
git mv "$script" "$BACKUP_DIR/$(basename $script)"
else
echo "Warning: $script not found, skipping"
fi
}
# Archive redundant test scripts
echo "Archiving redundant test scripts..."
archive_script "test/claude/test-direct-claude.sh" # Duplicate of test-claude-direct.sh
archive_script "test/claude/test-claude-version.sh" # Can be merged with test-claude-installation.sh
# Archive obsolete AWS credential scripts
echo "Archiving obsolete AWS credential scripts..."
archive_script "scripts/aws/update-aws-creds.sh" # Obsolete, replaced by profile-based auth
# Archive temporary/one-time setup scripts
echo "Moving one-time setup scripts to archived directory..."
mkdir -p "$BACKUP_DIR/one-time"
git mv "scripts/utils/prepare-clean-repo.sh" "$BACKUP_DIR/one-time/"
git mv "scripts/utils/fix-credential-references.sh" "$BACKUP_DIR/one-time/"
# Archive redundant container test scripts that can be consolidated
echo "Archiving redundant container test scripts..."
archive_script "test/container/test-container-privileged.sh" # Can be merged with test-basic-container.sh
# Archive our temporary reorganization scripts
echo "Archiving temporary reorganization scripts..."
git mv "reorganize-scripts.sh" "$BACKUP_DIR/one-time/"
git mv "script-organization.md" "$BACKUP_DIR/one-time/"
# After archiving, create a consolidated container test script
echo "Creating consolidated container test script..."
cat > test/container/test-container.sh << 'EOF'
#!/bin/bash
# Consolidated container test script
# Usage: ./test-container.sh [basic|privileged|cleanup]
set -e
TEST_TYPE=${1:-basic}
case "$TEST_TYPE" in
basic)
echo "Running basic container test..."
# Basic container test logic from test-basic-container.sh
docker run --rm -it \
-e REPO_FULL_NAME="owner/test-repo" \
-e ISSUE_NUMBER="1" \
-e IS_PULL_REQUEST="false" \
-e COMMAND="echo 'Basic container test'" \
-e GITHUB_TOKEN="${GITHUB_TOKEN:-test-token}" \
claude-code-runner:latest
;;
privileged)
echo "Running privileged container test..."
# Privileged container test logic from test-container-privileged.sh
docker run --rm -it \
--privileged \
-e REPO_FULL_NAME="owner/test-repo" \
-e ISSUE_NUMBER="1" \
-e IS_PULL_REQUEST="false" \
-e COMMAND="echo 'Privileged container test'" \
-e GITHUB_TOKEN="${GITHUB_TOKEN:-test-token}" \
claude-code-runner:latest
;;
cleanup)
echo "Running container cleanup test..."
# Container cleanup test logic from test-container-cleanup.sh
docker run --rm -it \
-e REPO_FULL_NAME="owner/test-repo" \
-e ISSUE_NUMBER="1" \
-e IS_PULL_REQUEST="false" \
-e COMMAND="echo 'Container cleanup test'" \
-e GITHUB_TOKEN="${GITHUB_TOKEN:-test-token}" \
claude-code-runner:latest
;;
*)
echo "Unknown test type: $TEST_TYPE"
echo "Usage: ./test-container.sh [basic|privileged|cleanup]"
exit 1
;;
esac
echo "Test complete!"
EOF
chmod +x test/container/test-container.sh
# Create a consolidated Claude test script
echo "Creating consolidated Claude test script..."
cat > test/claude/test-claude.sh << 'EOF'
#!/bin/bash
# Consolidated Claude test script
# Usage: ./test-claude.sh [direct|installation|no-firewall|response]
set -e
TEST_TYPE=${1:-direct}
case "$TEST_TYPE" in
direct)
echo "Testing direct Claude integration..."
# Direct Claude test logic from test-claude-direct.sh
docker run --rm -it \
-e REPO_FULL_NAME="owner/test-repo" \
-e ISSUE_NUMBER="1" \
-e IS_PULL_REQUEST="false" \
-e COMMAND="echo 'Direct Claude test'" \
-e GITHUB_TOKEN="${GITHUB_TOKEN:-test-token}" \
-e ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-test-key}" \
claude-code-runner:latest
;;
installation)
echo "Testing Claude installation..."
# Installation test logic from test-claude-installation.sh and test-claude-version.sh
docker run --rm -it \
-e REPO_FULL_NAME="owner/test-repo" \
-e ISSUE_NUMBER="1" \
-e IS_PULL_REQUEST="false" \
-e COMMAND="claude-cli --version && claude --version" \
-e GITHUB_TOKEN="${GITHUB_TOKEN:-test-token}" \
claude-code-runner:latest
;;
no-firewall)
echo "Testing Claude without firewall..."
# Test logic from test-claude-no-firewall.sh
docker run --rm -it \
-e REPO_FULL_NAME="owner/test-repo" \
-e ISSUE_NUMBER="1" \
-e IS_PULL_REQUEST="false" \
-e COMMAND="echo 'Claude without firewall test'" \
-e GITHUB_TOKEN="${GITHUB_TOKEN:-test-token}" \
-e DISABLE_FIREWALL=true \
claude-code-runner:latest
;;
response)
echo "Testing Claude response..."
# Test logic from test-claude-response.sh
docker run --rm -it \
-e REPO_FULL_NAME="owner/test-repo" \
-e ISSUE_NUMBER="1" \
-e IS_PULL_REQUEST="false" \
-e COMMAND="claude \"Tell me a joke\"" \
-e GITHUB_TOKEN="${GITHUB_TOKEN:-test-token}" \
-e ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-test-key}" \
claude-code-runner:latest
;;
*)
echo "Unknown test type: $TEST_TYPE"
echo "Usage: ./test-claude.sh [direct|installation|no-firewall|response]"
exit 1
;;
esac
echo "Test complete!"
EOF
chmod +x test/claude/test-claude.sh
# Create a consolidated build script
echo "Creating consolidated build script..."
cat > scripts/build/build.sh << 'EOF'
#!/bin/bash
# Consolidated build script
# Usage: ./build.sh [claude|claudecode|production]
set -e
BUILD_TYPE=${1:-claudecode}
case "$BUILD_TYPE" in
claude)
echo "Building Claude container..."
docker build -f Dockerfile.claude -t claude-container:latest .
;;
claudecode)
echo "Building Claude Code runner Docker image..."
docker build -f Dockerfile.claudecode -t claude-code-runner:latest .
;;
production)
if [ ! -d "./claude-config" ]; then
echo "Error: claude-config directory not found."
echo "Please run ./scripts/setup/setup-claude-auth.sh first and copy the config."
exit 1
fi
echo "Building production image with pre-authenticated config..."
cp Dockerfile.claudecode Dockerfile.claudecode.backup
# Production build logic from update-production-image.sh
# ... (truncated for brevity)
docker build -f Dockerfile.claudecode -t claude-code-runner:production .
;;
*)
echo "Unknown build type: $BUILD_TYPE"
echo "Usage: ./build.sh [claude|claudecode|production]"
exit 1
;;
esac
echo "Build complete!"
EOF
chmod +x scripts/build/build.sh
# Update documentation to reflect the changes
echo "Updating documentation..."
sed -i 's|test-direct-claude.sh|test-claude.sh direct|g' SCRIPTS.md
sed -i 's|test-claude-direct.sh|test-claude.sh direct|g' SCRIPTS.md
sed -i 's|test-claude-version.sh|test-claude.sh installation|g' SCRIPTS.md
sed -i 's|test-claude-installation.sh|test-claude.sh installation|g' SCRIPTS.md
sed -i 's|test-claude-no-firewall.sh|test-claude.sh no-firewall|g' SCRIPTS.md
sed -i 's|test-claude-response.sh|test-claude.sh response|g' SCRIPTS.md
sed -i 's|test-basic-container.sh|test-container.sh basic|g' SCRIPTS.md
sed -i 's|test-container-privileged.sh|test-container.sh privileged|g' SCRIPTS.md
sed -i 's|test-container-cleanup.sh|test-container.sh cleanup|g' SCRIPTS.md
sed -i 's|build-claude-container.sh|build.sh claude|g' SCRIPTS.md
sed -i 's|build-claudecode.sh|build.sh claudecode|g' SCRIPTS.md
sed -i 's|update-production-image.sh|build.sh production|g' SCRIPTS.md
# Create a final wrapper script for backward compatibility
cat > build-claudecode.sh << 'EOF'
#!/bin/bash
# Wrapper script for backward compatibility
echo "This script is now located at scripts/build/build.sh"
exec scripts/build/build.sh claudecode "$@"
EOF
chmod +x build-claudecode.sh
# After all operations are complete, clean up this script too
echo "Script cleanup complete!"
echo
echo "Note: This script (cleanup-scripts.sh) has completed its job and can now be removed."
echo "After verifying the changes, you can remove it with:"
echo "rm cleanup-scripts.sh"
echo
echo "To commit these changes, run:"
echo "git add ."
echo "git commit -m \"Clean up redundant scripts and consolidate functionality\""