137 lines
4.0 KiB
Bash
Executable File
137 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Open interactive shell in 3DS development container
|
|
# Usage: ./scripts/container-shell.sh [project-path] [podman-args...]
|
|
#
|
|
# All arguments after project-path are passed to podman/docker run before the container name
|
|
# This allows mounting additional volumes, setting environment variables, etc.
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Print colored message
|
|
print_msg() {
|
|
local color=$1
|
|
shift
|
|
echo -e "${color}$*${NC}"
|
|
}
|
|
|
|
# Print usage
|
|
usage() {
|
|
cat << 'EOF'
|
|
Usage: ./scripts/container-shell.sh [project-path] [podman-args...]
|
|
|
|
Open interactive bash shell in 3DS development container with project mounted.
|
|
|
|
Arguments:
|
|
project-path Path to project directory (default: current directory)
|
|
podman-args Additional arguments passed to podman/docker run
|
|
|
|
Examples:
|
|
# Shell in current directory
|
|
./scripts/container-shell.sh
|
|
|
|
# Shell in specific project
|
|
./scripts/container-shell.sh ~/my-3ds-game
|
|
|
|
# With additional volume mount
|
|
./scripts/container-shell.sh ~/my-game -v /data:/data:z
|
|
|
|
# With environment variable
|
|
./scripts/container-shell.sh ~/my-game -e DEBUG=1
|
|
|
|
# Multiple extra arguments
|
|
./scripts/container-shell.sh ~/my-game -v /data:/data:z -e DEBUG=1 --network=host
|
|
|
|
Inside the container:
|
|
- Project is mounted at /project
|
|
- Working directory is /project
|
|
- All devkitARM tools are in PATH
|
|
- Run 'make' to build your project
|
|
- Run 'exit' or Ctrl+D to leave
|
|
|
|
Environment Variables:
|
|
CONTAINER_RUNTIME Container runtime to use (podman or docker, default: auto-detect)
|
|
|
|
EOF
|
|
exit 1
|
|
}
|
|
|
|
# Detect container runtime
|
|
detect_runtime() {
|
|
if [ -n "$CONTAINER_RUNTIME" ]; then
|
|
echo "$CONTAINER_RUNTIME"
|
|
return
|
|
fi
|
|
|
|
if command -v podman &> /dev/null; then
|
|
echo "podman"
|
|
elif command -v docker &> /dev/null; then
|
|
echo "docker"
|
|
else
|
|
print_msg "$RED" "Error: Neither podman nor docker found in PATH"
|
|
print_msg "$YELLOW" "Please install podman (recommended) or docker"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Main
|
|
main() {
|
|
# Show help
|
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|
usage
|
|
fi
|
|
|
|
# Determine project path
|
|
local project_path="${1:-.}"
|
|
shift || true # Remove first arg if present, don't fail if no args
|
|
|
|
# Resolve absolute path
|
|
project_path=$(cd "$project_path" 2>/dev/null && pwd) || {
|
|
print_msg "$RED" "Error: Project path does not exist: ${1:-.}"
|
|
exit 1
|
|
}
|
|
|
|
# Collect remaining arguments for podman/docker run
|
|
local extra_args=("$@")
|
|
|
|
local runtime
|
|
runtime=$(detect_runtime)
|
|
|
|
local image_name="tomusan/devkitarm-3ds:latest"
|
|
|
|
print_msg "$BLUE" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
print_msg "$GREEN" "3DS Development Container Shell"
|
|
print_msg "$BLUE" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo
|
|
print_msg "$YELLOW" "Project: $project_path"
|
|
print_msg "$YELLOW" "Runtime: $runtime"
|
|
print_msg "$YELLOW" "Image: $image_name"
|
|
if [ ${#extra_args[@]} -gt 0 ]; then
|
|
print_msg "$YELLOW" "Extra: ${extra_args[*]}"
|
|
fi
|
|
echo
|
|
print_msg "$GREEN" "Type 'exit' or press Ctrl+D to leave the container"
|
|
echo
|
|
print_msg "$BLUE" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo
|
|
|
|
# Run container with interactive shell
|
|
# Project mounted to /project, any extra args passed to podman/docker run
|
|
"$runtime" run -it --rm \
|
|
-v "$project_path:/project:z" \
|
|
"${extra_args[@]}" \
|
|
"$image_name" \
|
|
bash
|
|
}
|
|
|
|
main "$@"
|