From 500c6034dd56cdf868539b2e1bedbb0c5fe3d7f7 Mon Sep 17 00:00:00 2001 From: maurice Date: Fri, 28 Aug 2026 16:37:53 +0200 Subject: [PATCH] Big boom --- build.sh | 6 +- container/Containerfile | 107 ++++++++++++ {containers/base => container}/config/bashrc | 5 +- container/config/bin/host | 6 + {containers/base => container}/config/git | 0 .../config/helix/config.toml | 0 container/config/helix/languages.toml | 33 ++++ containers/android/Containerfile | 20 --- containers/base/Containerfile | 53 ------ containers/base/config/bin/host | 4 - containers/base/config/helix/languages.toml | 12 -- containers/base/install-roslyn.sh | 9 - containers/flutter/Containerfile | 11 -- containers/rider/Containerfile | 18 -- containers/rider/config.sh | 4 - devc.sh | 165 +++++++----------- example-bashrc | 28 --- 17 files changed, 213 insertions(+), 268 deletions(-) create mode 100644 container/Containerfile rename {containers/base => container}/config/bashrc (84%) create mode 100755 container/config/bin/host rename {containers/base => container}/config/git (100%) rename {containers/base => container}/config/helix/config.toml (100%) create mode 100644 container/config/helix/languages.toml delete mode 100644 containers/android/Containerfile delete mode 100644 containers/base/Containerfile delete mode 100755 containers/base/config/bin/host delete mode 100644 containers/base/config/helix/languages.toml delete mode 100644 containers/base/install-roslyn.sh delete mode 100644 containers/flutter/Containerfile delete mode 100644 containers/rider/Containerfile delete mode 100644 containers/rider/config.sh delete mode 100644 example-bashrc diff --git a/build.sh b/build.sh index e1f4c26..4e56e4d 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,3 @@ #!/bin/sh -cd containers/base -podman build -t git.plabble.org/maurice/base:main . -cd ../rider -podman build -t git.plabble.org/maurice/rider:main . \ No newline at end of file +cd container && \ +podman build -t git.plabble.org/maurice/devc:main . \ No newline at end of file diff --git a/container/Containerfile b/container/Containerfile new file mode 100644 index 0000000..5d5a7ff --- /dev/null +++ b/container/Containerfile @@ -0,0 +1,107 @@ +FROM quay.io/fedora/fedora:44 + +# === install system packages === +RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \ + dnf update -y && \ + dnf -y --setopt=keepcache=1 --setopt=install_weak_deps=False install \ + bash-completion git-core curl awk jq rg zip unzip which \ + host-spawn wl-copy gcc helix helix-themes rsync python3 python3-pip dotnet-sdk-10.0 openssl-devel + +# === setup user === +RUN useradd -ms /bin/bash user && \ + echo 'user ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/user && \ + mkdir -p /run/user/1000 && \ + chown user:user /run/user/1000 + +# === Add host entry for podman & XDG open === +RUN ln -s /usr/local/bin/host /usr/local/bin/podman && \ + ln -s /usr/local/bin/host /usr/local/bin/xdg-open + +COPY config/bin /usr/local/bin + +# === languages & SDKs === + +# Golang +RUN GO_VERSION=$(curl -sL "https://go.dev/VERSION?m=text" | head -n 1 | tr -d '\r\n') && \ + curl -sL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" | tar xz -C /usr/local && \ + ln -sf /usr/local/go/bin/go /usr/local/bin/go && \ + ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt && \ + export GOPATH=/usr/local/go && \ + go install golang.org/x/tools/gopls@latest && \ + ln -sf /usr/local/go/bin/gopls /usr/local/bin/gopls + +# Deno +RUN export DENO_INSTALL=/usr/local/deno && \ + curl -fsSL https://deno.land/install.sh | sh && \ + ln -sf /usr/local/deno/bin/deno /usr/local/bin/deno + +# Rust +RUN export RUSTUP_HOME=/usr/local/rust && \ + export CARGO_HOME=/usr/local/rust && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path && \ + ln -sf /usr/local/rust/bin/rustc /usr/local/bin/rustc && \ + ln -sf /usr/local/rust/bin/cargo /usr/local/bin/cargo && \ + ln -sf /usr/local/rust/bin/rustup /usr/local/bin/rustup && \ + ln -sf /usr/local/rust/bin/rustfmt /usr/local/bin/rustfmt && \ + ln -sf /usr/local/rust/bin/clippy /usr/local/bin/clippy && \ + ln -sf /usr/local/rust/bin/rust-analyzer /usr/local/bin/rust-analyzer && \ + rustup component add rustfmt clippy rust-analyzer && \ + curl https://drager.github.io/wasm-pack/installer/init.sh -sSf | sh +# cargo install cargo-generate && \ +# cargo install cargo-expand + +# Dotnet +RUN dotnet tool install --global dotnet-ef && \ + mkdir -p /usr/local/bin/omnisharp && \ + curl -L https://github.com/OmniSharp/omnisharp-roslyn/releases/latest/download/omnisharp-linux-x64-net6.0.tar.gz \ + | tar xz -C /usr/local/bin/omnisharp && \ + chmod +x /usr/local/bin/omnisharp/OmniSharp + +# PHP +RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \ + dnf -y install https://rpm.henderkes.com/static-php-1-0.noarch.rpm && \ + dnf -y module enable php-zts:static-8.5 && \ + dnf install -y \ + frankenphp \ + php-zts-dom \ + php-zts-xml \ + php-zts-tokenizer \ + php-zts-session \ + php-zts-posix \ + php-zts-fileinfo \ + php-zts-simplexml \ + php-zts-xmlreader \ + php-zts-xmlwriter \ + php-zts-soap \ + php-zts-gd \ + php-zts-pdo_mysql \ + php-zts-pcntl \ + php-zts-zip \ + php-zts-exif \ + php-zts-bcmath \ + php-zts-mysqli \ + php-zts-imagick \ + php-zts-grpc && \ + curl -fsSL https://getcomposer.org/installer | \ + php -- --install-dir=/usr/local/bin --filename=composer + +# === install language servers, tools === +RUN deno i -g -f -A --root /usr/local/bin npm:npm npm:bash-language-server npm:vscode-langservers-extracted npm:dockerfile-language-server-nodejs \ + npm:typescript npm:typescript-language-server + +USER user +WORKDIR /home/user +RUN mkdir -p .config .local .cache + +COPY --chown=user:user config/bashrc .bashrc +COPY --chown=user:user config/git .config/git/config +COPY --chown=user:user config/helix/ .config/helix/ + +# === Cleanup build dependencies === +USER root +RUN dnf remove -y openssl-devel && dnf clean all && \ + rm -rf /tmp/* && rm -rf /root/* + +USER user + +VOLUME /home/user diff --git a/containers/base/config/bashrc b/container/config/bashrc similarity index 84% rename from containers/base/config/bashrc rename to container/config/bashrc index c1191d0..36cd0f3 100644 --- a/containers/base/config/bashrc +++ b/container/config/bashrc @@ -5,6 +5,9 @@ export EDITOR=hx \ WAYLAND_DISPLAY=wayland-0 \ XDG_RUNTIME_DIR=/run/user/1000 \ SSH_AUTH_SOCK=/run/user/1000/ssh-auth-sock \ + CARGO_HOME=/usr/local/rust \ + RUSTUP_HOME=/usr/local/rust \ + GOPATH=/usr/local/go \ PS1="\[\e[30;46m\] \h | \w \[\e[0;36m\]î‚°\[\e[m\] " \ TZ="Europe/Amsterdam" \ SHELL="/bin/bash" @@ -13,7 +16,7 @@ export EDITOR=hx \ pbcopy() { curl -sF "content=<-" "https://paste.plabble.org/$2?lang=$1" && echo; } alias random="cat /dev/urandom | tr -dc '[:alpha:]' | fold -w ${1:-20} | head -n 1" -# Git aliases +# === Git aliases === alias gc="git commit -m" alias ga="git add -A" alias gf="git fetch" diff --git a/container/config/bin/host b/container/config/bin/host new file mode 100755 index 0000000..0610301 --- /dev/null +++ b/container/config/bin/host @@ -0,0 +1,6 @@ +#!/bin/bash +export DBUS_SESSION_BUS_ADDRESS="unix:path=/tmp/bus" + +cmd="${0##*/}" +[[ "$cmd" == "host" ]] && unset cmd +exec host-spawn -cwd "${PWD/#$HOME/$HOST_HOME}" ${cmd:+"$cmd"} "$@ \ No newline at end of file diff --git a/containers/base/config/git b/container/config/git similarity index 100% rename from containers/base/config/git rename to container/config/git diff --git a/containers/base/config/helix/config.toml b/container/config/helix/config.toml similarity index 100% rename from containers/base/config/helix/config.toml rename to container/config/helix/config.toml diff --git a/container/config/helix/languages.toml b/container/config/helix/languages.toml new file mode 100644 index 0000000..6861f1e --- /dev/null +++ b/container/config/helix/languages.toml @@ -0,0 +1,33 @@ +# C# +[language-server.omnisharp] +command = "/usr/local/bin/omnisharp/OmniSharp" +args = [ "--languageserver" ] + +# Rust +[language-server.rust-analyzer.config.check] +command = "clippy" + +[language-server.deno-lsp] +command = "deno" +args = ["lsp"] +config.deno.enable = true + +[[language]] +name = "rust" +formatter = { command = "rustfmt" } + +# TS +[[language]] +name = "typescript" +roots = ["deno.json", "deno.jsonc", "package.json"] +file-types = ["ts", "tsx"] +auto-format = true +language-servers = ["deno-lsp"] + +# JS +[[language]] +name = "javascript" +roots = ["deno.json", "deno.jsonc", "package.json"] +file-types = ["js", "jsx"] +auto-format = true +language-servers = ["deno-lsp"] \ No newline at end of file diff --git a/containers/android/Containerfile b/containers/android/Containerfile deleted file mode 100644 index 95ece7a..0000000 --- a/containers/android/Containerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM git.plabble.org/maurice/base:main -ARG studio_version="2025.3.2.6" -ARG download_uri="https://redirector.gvt1.com/edgedl/android/studio/ide-zips/${studio_version}/android-studio-${studio_version}-linux.tar.gz" - -USER root -# === setup GUI === -RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \ - dnf -y --setopt=keepcache=1 install libXext libXrender libXtst libX11 freetype freetype-devel mesa-libGLU -USER user - -RUN curl -Lo /tmp/studio.tar.gz "${download_uri}" && \ - mkdir /home/user/AndroidStudio && \ - mkdir /home/user/Android && \ - tar -zxf /tmp/studio.tar.gz -C /home/user/AndroidStudio && \ - rm /tmp/studio.tar.gz && \ - mv /home/user/AndroidStudio/android-studio*/* /home/user/AndroidStudio - -RUN echo 'alias studio="$HOME/AndroidStudio/bin/studio"' >> /home/user/.bashrc -RUN echo 'export ANDROID_HOME="$HOME/Android/Sdk"' >> /home/user/.bashrc -RUN echo 'export PATH="$ANDROID_HOME/platform-tools:$PATH"' >> /home/user/.bashrc diff --git a/containers/base/Containerfile b/containers/base/Containerfile deleted file mode 100644 index 0bd01d4..0000000 --- a/containers/base/Containerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM quay.io/fedora/fedora:43 - -# === install system packages === -RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \ - dnf update -y && \ - dnf -y --setopt=keepcache=1 install \ - procps ping bash-completion glibc-langpack-en openssl-devel \ - host-spawn dbus-launch \ - git pnpm helix zip rsync \ - dotnet-sdk-10.0 - -# === setup user === -RUN useradd -ms /bin/bash user && \ - usermod -aG wheel user && sed -i '/NOPASSWD/s/^#//g' /etc/sudoers && \ - mkdir -p /run/user/1000 && chown user:user /run/user/1000 - -# === Add host entry for podman === -RUN ln -s /usr/local/bin/host /usr/local/bin/podman - -# === root language servers === -COPY install-roslyn.sh /tmp/install-roslyn.sh -RUN chmod +x /tmp/install-roslyn.sh && /tmp/install-roslyn.sh && rm /tmp/omnisharp.tar.gz && rm /tmp/install-roslyn.sh -# RUN go install golang.org/x/tools/gopls@latest - -USER user -WORKDIR /home/user -RUN mkdir .config .local .cache - -COPY --chown=user:user config/bashrc .bashrc -COPY --chown=user:user config/git .config/git/config -COPY --chown=user:user config/helix/ .config/helix/ -COPY config/bin /usr/local/bin - -# === Setup PNPM & install language servers, tools === -RUN /bin/bash -c ". /home/user/.bashrc && pnpm setup && . /home/user/.bashrc && pnpm i -g deno bash-language-server vscode-langservers-extracted dockerfile-language-server-nodejs \ - typescript typescript-language-server" - -RUN dotnet tool install --global dotnet-ef && \ - echo 'export PATH="$PATH:/home/user/.dotnet/tools:/home/user/.cargo/env"' >> /home/user/.bashrc - -# === Rust, WASM toolchain === -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -RUN . /home/user/.bashrc && rustup component add rust-analyzer && \ - curl https://drager.github.io/wasm-pack/installer/init.sh -sSf | sh && \ - cargo install cargo-generate && \ - cargo install cargo-expand - -# === Cleanup build dependencies === -USER root -RUN dnf remove -y openssl-devel && dnf clean all && rm -rf /home/user/.cargo -USER user - -VOLUME /home/user diff --git a/containers/base/config/bin/host b/containers/base/config/bin/host deleted file mode 100755 index f8fe5ed..0000000 --- a/containers/base/config/bin/host +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -export DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/bus -host-spawn -cwd "${PWD/#$HOME/$HOST_HOME}" \ - $([ "$(basename "$0")" != "host" ] && echo "$(basename "$0")") "$@" diff --git a/containers/base/config/helix/languages.toml b/containers/base/config/helix/languages.toml deleted file mode 100644 index f1dbd9a..0000000 --- a/containers/base/config/helix/languages.toml +++ /dev/null @@ -1,12 +0,0 @@ -# C# -[language-server.omnisharp] -command = "/home/user/.omnisharp/OmniSharp" -args = [ "--languageserver" ] - -# Rust -[language-server.rust-analyzer.config.check] -command = "clippy" - -[[language]] -name = "rust" -formatter = { command = "rustfmt" } \ No newline at end of file diff --git a/containers/base/install-roslyn.sh b/containers/base/install-roslyn.sh deleted file mode 100644 index 865c354..0000000 --- a/containers/base/install-roslyn.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -version="v1.39.15" -arch="linux-x64" -link="https://github.com/OmniSharp/omnisharp-roslyn/releases/download/$version/omnisharp-$arch-net6.0.tar.gz" - -curl -Lo /tmp/omnisharp.tar.gz $link -mkdir /home/user/.omnisharp -tar -zxf /tmp/omnisharp.tar.gz -C /home/user/.omnisharp/ -chown -R user:user /home/user/.omnisharp \ No newline at end of file diff --git a/containers/flutter/Containerfile b/containers/flutter/Containerfile deleted file mode 100644 index 36b1d2d..0000000 --- a/containers/flutter/Containerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM git.plabble.org/maurice/base:main -ARG flutter_version="3.41.4-stable" -ARG download_uri="https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${flutter_version}.tar.xz" - -RUN mkdir /home/user/Flutter && \ - curl -Lo /tmp/flutter.tar.xz "${download_uri}" && \ - tar -xf /tmp/flutter.tar.xz -C /home/user/Flutter && \ - rm /tmp/flutter.tar.xz - -RUN echo 'export PATH="$HOME/Flutter/flutter/bin:$PATH"' >> /home/user/.bashrc -RUN echo 'export FLUTTER_ROOT="$HOME/Flutter/flutter"' >> /home/user/.bashrc \ No newline at end of file diff --git a/containers/rider/Containerfile b/containers/rider/Containerfile deleted file mode 100644 index 0a431ee..0000000 --- a/containers/rider/Containerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM git.plabble.org/maurice/base:main -ARG rider_version="2025.3.3" -ARG download_uri="https://download.jetbrains.com/rider/JetBrains.Rider-${rider_version}.tar.gz" - -USER root - -# === setup GUI === -RUN --mount=type=cache,id=dnf-cache,target=/var/cache/libdnf5 \ - dnf -y --setopt=keepcache=1 install libXext libXrender libXtst libX11 freetype freetype-devel -USER user - -RUN curl -Lo /tmp/rider.tar.gz "${download_uri}" && \ - mkdir /home/user/Rider && \ - tar -zxf /tmp/rider.tar.gz -C /home/user/Rider && \ - rm /tmp/rider.tar.gz && \ - mv /home/user/Rider/JetBrains*/* /home/user/Rider - -RUN echo 'alias rider="$HOME/Rider/bin/rider"' >> /home/user/.bashrc diff --git a/containers/rider/config.sh b/containers/rider/config.sh deleted file mode 100644 index e0535ed..0000000 --- a/containers/rider/config.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -mkdir -p /tmp/joypet-sockets -arg "-p 7777:7777" -arg "-v /tmp/joypet-sockets:/var/run/joypet-sockets:Z" \ No newline at end of file diff --git a/devc.sh b/devc.sh index c9d15bf..9ef7ac4 100755 --- a/devc.sh +++ b/devc.sh @@ -1,125 +1,82 @@ #!/bin/bash # =============================================== # -# devc.sh v2.0; job79, maurice # -# Dev container enter script. Handles setting up # -# different dev containers, resuming sessions and # -# automatic container updates. # +# devc.sh v2.1; job79, maurice # +# Dev container entry script. # # =============================================== # -set -eu -log() { printf '\e[%sm%s\e[0m %s\n' "${3:-36}" "${2:-â—‹}" "$1"; } -arg() { echo -n " $@"; } +set -euo pipefail +log() { echo -e "\e[36mâ—‹\e[0m $1"; } +die() { echo -e "\e[31mx\e[0m $1" && exit 1; } -# run_args returns the podman run arguments required for -# starting a new container. +# default_args configures standard container options. default_args() { - arg "--name $name" - arg "--hostname $name" + run_opts+=( + "--name" "$name" + "--hostname" "$name" + "--network" "devc" + "--pull=newer" # Update image. + "--userns=keep-id" # Map host user. + "-v" "$name:/home/user:copy" # Persistent home volume. + "-v" "dnf-cache:/var/cache/libdnf5" # Cache dnf metadata. + ) - # Pull newer container image if available. - # arg "--pull=newer" + # Unix sockets require SELinux label disable. + [[ -d /sys/fs/selinux ]] && run_opts+=("--security-opt" "label=disable") - # Use keep-id so the container user matches the host user. - arg "--userns=keep-id" + # Desktop integration (Wayland, SSH). + [[ -e "/run/user/$UID/wayland-0" ]] && run_opts+=("-v" "/run/user/$UID/wayland-0:/run/user/1000/wayland-0") + [[ -e "${SSH_AUTH_SOCK:-}" ]] && run_opts+=("-v" "$SSH_AUTH_SOCK:/run/user/1000/ssh-auth-sock") - # Disable selinux labeling so unix sockets can be mounted - # without problems. - arg "--security-opt label=disable" - - # Mount the wayland socket. Required to get the system - # clipboard (wl-copy) and gui applications working. - [ -e "/run/user/$UID/wayland-0" ] && arg "-v /run/user/$UID/wayland-0:/run/user/1000/wayland-0" - - # Mount the ssh socket to get ssh working. - [ -e "$SSH_AUTH_SOCK" ] && arg "-v $SSH_AUTH_SOCK:/run/user/1000/ssh-auth-sock" - - # Make the user home dir a volume so it survives container - # restarts. Use copy to keep the files from the image. - arg "-v $name:/home/user:copy" - - # If there is custom configuration for the container, load - # it here. - config_file="$(dirname "$(realpath "$0")")/containers/$name/config.sh" - [ -f "$config_file" ] && source "${config_file}" + # Load custom container config. + local config_file="${BASH_SOURCE[0]%/*}/container/config.sh" + [[ -f "$config_file" ]] && source "$config_file" || true } -# param_args returns the podman run arguments based on the -# arguments provided to this script. +# param_args parses CLI arguments into podman run options. param_args() { - while test $# -gt 0; do + while (($# > 0)); do case "$1" in - -gpu) # Enable gpu acceleration. - arg "--device /dev/dri" ;; - -kvm) # Enable KVM - arg "--device /dev/kvm" ;; - -usb) # Enable USB access - arg "--device /dev/bus/usb" ;; - -host-spawn) # Enable spawning host commands from inside the container using host-spawn. - arg "-v /run/user/$UID/bus:/tmp/bus" - arg "-e HOST_HOME=$HOME" # Used to translate paths. - ;; - -net) # Enable network 'dev-'' and 'devc' - arg "--network dev-$name --network devc" - ;; - -mnt) # Mount directory. - shift - arg "-w /workdir/" - arg "-v $1:/workdir/$([ ! -d "$1" ] && echo $1)" - ;; - -mdf) # Mount dev folder - arg "-v $HOME/dev:/home/user/dev" - ;; - -x11) # Enable X11 support. - arg "-v /tmp/.X11-unix:/tmp/.X11-unix" - arg "-v $XAUTHORITY:/run/user/1000/.Xauthority:ro" - arg "-e DISPLAY=$DISPLAY" - arg "-e XAUTHORITY=/run/user/1000/.Xauthority" - ;; - *) # Use unknown arguments a podman arguments. - arg "$1" ;; + -gpu) run_opts+=("--device" "/dev/dri") ;; + -kvm) run_opts+=("--device" "/dev/kvm") ;; + -usb) run_opts+=("--device" "/dev/bus/usb") ;; + -host-spawn) run_opts+=("-v" "/run/user/$UID/bus:/tmp/bus" "-e" "HOST_HOME=$HOME") ;; + -container-sock) run_opts+=("-v" "$XDG_RUNTIME_DIR/podman/podman.sock:/var/run/docker.sock") ;; + -x11) run_opts+=("-v" "/tmp/.X11-unix:/tmp/.X11-unix" "-v" "$XAUTHORITY:/run/user/1000/.Xauthority:ro" "-e" "DISPLAY=$DISPLAY" "-e" "XAUTHORITY=/run/user/1000/.Xauthority") ;; + -mnt) shift && run_opts+=("-w" "/mnt/" "-v" "$1:/mnt/$([[ -d "$1" ]] || echo "file")") ;; + *) run_opts+=("$1") ;; esac shift done } -### MAIN ### -# Get the devcontainer name from the first argument. If not -# provided, use the last used name when possible. -if [[ $# -gt 0 ]] && [[ ${1:-} != -* ]]; then - image="$1" - [[ "$image" != *:* ]] && image="$image:main" - echo "$image" >"$HOME/.local/share/devc-previous-container" - shift -elif [ -f "$HOME/.local/share/devc-previous-container" ]; then - image=$(<"$HOME/.local/share/devc-previous-container") -else - log "no container name specified" 'x' 31 - exit 1 -fi -name="${image%:*}" +main() { + local state_file="$HOME/.local/share/devc-previous-container" + local image="devc" -# Get container registry from the DEVC_REGISTRY env -# variable. -if [ -n "${DEVC_REGISTRY:-}" ]; then - registry="$DEVC_REGISTRY" -else - log "registry unknown; set the DEVC_REGISTRY environment variable" 'x' 31 - exit 1 -fi + # Resolve container name (CLI arg > Last used > Error). + if [[ $image && $image != -* ]]; then + shift + [[ $image != *:* ]] && image+=":main" + echo "$image" >"$state_file" + elif [[ -f $state_file ]]; then + image=$(<$state_file) + else + die "no container name specified" + fi + local name="${image%:*}" -# Get container command from the DEVC_COMMAND env variable -# if set, else use bash -l. -if [ -z "${DEVC_COMMAND:-}" ]; then - DEVC_COMMAND="bash -l" -fi + # Start/Restart if not running or if arguments change configuration. + if [[ -z "$(podman ps -q -f name="^$name$" -f status=running)" ]] || (($# > 0)); then + log "starting $image..." -# When container is not running or arguments are provided, -# recreate it. -if [ "$(podman container inspect "$name" -f {{.State.Running}} 2>&1)" != 'true' ] || [[ $# -gt 0 ]]; then - log "starting devcontainer..." - podman network create --ignore "dev-$name" - podman network create --ignore "devc" - podman container rm -f -t 0 "$name" 1>/dev/null - podman run -td $(default_args) $(param_args $@) "$registry/$image" -fi + default_args + param_args "$@" -podman exec --detach-keys "ctrl-@" -it "$name" ${DEVC_COMMAND:-} + [[ -n "${DEVC_REGISTRY:-}" ]] || die "registry unknown; set the DEVC_REGISTRY environment variable" + podman network create devc --ignore > /dev/null 2>&1 + podman run --replace --stop-timeout 0 -td "${run_opts[@]}" "$DEVC_REGISTRY/$image" + fi + + exec podman exec --detach-keys "ctrl-@,ctrl-@" -it "$name" ${DEVC_COMMAND:-bash -l} +} + +main "$@" diff --git a/example-bashrc b/example-bashrc deleted file mode 100644 index 5d2a215..0000000 --- a/example-bashrc +++ /dev/null @@ -1,28 +0,0 @@ -# Tools -pbcopy() { curl -sF "content=<-" "https://paste.plabble.org/$2?lang=$1" && echo; } -alias code="flatpak run com.visualstudio.code" -alias random="cat /dev/urandom | tr -dc '[:alpha:]' | fold -w ${1:-20} | head -n 1" - -# Dev containers -export DEVC_REGISTRY="git.plabble.org/maurice" - -function devc() { - "$HOME/dev/devcontainer/devc.sh" "$@" -mdf -} - -alias rider="DEVC_COMMAND=/home/user/Rider/bin/rider devc rider -x11 -host-spawn -net" -alias flutter="devc flutter -x11 -host-spawn -kvm -usb -gpu" -alias androidstudio="DEVC_COMMAND=/home/user/AndroidStudio/bin/studio devc android -x11 -host-spawn -kvm -usb -gpu" - -function hx() { - arg="${1:-.}" - DEVC_COMMAND="hx $arg" devc fedora -mnt $arg -} - -# Git aliases -alias gc="git commit -m" -alias ga="git add -A" -alias gf="git fetch" -alias gp="git pull" -alias gpp="git push" -alias gs="git status"