#!/bin/bash set -euo pipefail TOOLBX_NAME="toolbx" LIB_HOME="${HOME}/.local/share/eyedevelop/shell-utils/toolbx" delete_toolbox() { podman rm -f "${TOOLBX_NAME}" } create_toolbox() { local image podman_args image="debian:bookworm" podman_args=( "--name=${TOOLBX_NAME}" "--hostuser=${USER}" "--env=_REAL_USER=${USER}" "--userns=keep-id" "--security-opt=label=disable" "--network=host" "--hostname=toolbox" "--volume=${HOME}:/home/${USER}" "--user=root" "--entrypoint=/entrypoint.sh" ) while [[ "$#" -ge 1 ]]; do case "$1" in -i|--image) image="$2" shift shift ;; -p|--privileged) podman_args+=("--privileged") shift ;; esac done podman_args+=("$image") if podman container exists toolbx; then echo "[!] Toolbx container already exists. Want to replace?" echo -n "(Y/n) > " read -r opt if [[ "${opt,,}" == "n" ]]; then echo "[!] Aborting." return 1 fi delete_toolbox fi podman create "${podman_args[@]}" >/dev/null podman cp "${LIB_HOME}/container_setup.sh" "${TOOLBX_NAME}":/entrypoint.sh >/dev/null podman cp "${LIB_HOME}/container_autoshell.sh" "${TOOLBX_NAME}":/autoshell.sh &>/dev/null podman start "${TOOLBX_NAME}" >/dev/null echo "[+] Created!" } enter_toolbox() { if ! podman container exists "${TOOLBX_NAME}"; then create_toolbox fi podman exec -it "${TOOLBX_NAME}" "/autoshell.sh" "${SHELL}" } print_usage() { echo "--- Primitive container-based toolbox utility ---" echo "Usage: $0 " echo "Commands:" echo " enter -- Enter the toolbox." echo " create [opts] [command...] -- Create a new toolbox." echo " -i|--image -- The image to use to create the toolbox with." echo " -p|--privileged -- Whether the toolbox is privileged or not." echo " delete -- Delete the current toolbox." echo echo "If no command is specified, enter is assumed." } if [[ "$#" -lt 1 ]]; then print_usage return 1 fi while [[ "$#" -ge 1 ]]; do COMMAND="$1"; shift case "${COMMAND}" in enter) enter_toolbox "$@" ;; create) create_toolbox "$@" ;; delete) delete_toolbox "$@" ;; *) enter_toolbox "$@" ;; esac done