diff --git a/Containerfile b/Containerfile index b931b90..4d37bc8 100644 --- a/Containerfile +++ b/Containerfile @@ -26,4 +26,3 @@ COPY --chown=user:user config/nvim/lazyvim.json /home/user/.config/nvim/lazyvim. # === setup container === ENV TZ="Europe/Amsterdam" VOLUME /home/user/.local /home/user/.cache -CMD ["bash", "-l"] diff --git a/enter.sh b/enter.sh index 4b9a27a..b783069 100755 --- a/enter.sh +++ b/enter.sh @@ -3,19 +3,14 @@ # enter.sh v1.0; job79 # # Enter into an existing or new dev container and # # automatically handle dev container updates. # -# # -# TODO # -# ----------------------------------------------- # -# remove --security-opt label=disable # -# configurable mount directories # # =============================================== # -set -e +set -eu log() { printf '\e[%sm%s\e[0m %s\n' "${3:-36}" "${2:-○}" "$1"; } +arg() { echo -n " $@"; } # run_args returns the arguments required for the podman run # command. run_args() { - arg() { echo -n " $@"; } arg "--name $name" # Disable some security settings to make it possible to @@ -54,31 +49,23 @@ fetch=false while test $# -gt 0; do case "$1" in - --image | -i) - shift - image="$1" - ;; - --name | -n) - shift - name="$1" - ;; - --fetch | -f) - fetch=true - ;; - *) log "unknown argument '$1'" 'x' 31 ;; + --image | -i) shift && image="$1" ;; + --fetch | -f) fetch=true ;; + -*) log "unknown argument '$1'" 'x' 31 ;; + *) name="$1" ;; esac shift done -if "$fetch" = true ] || [ "$(podman container inspect "$name" -f {{.State.Running}})" = 'false' ]; then +if [ "$fetch" = true ] || [ "$(podman container inspect "$name" -f {{.State.Running}} 2>&1)" != 'true' ]; then log "fetching updates..." - if [ "$(podman pull -q "$image")" != "$(podman container inspect "$name" -f {{.Image}})" ]; then - log "new container image downloaded" '✓' 32 + if [ "$(podman pull -q "$image")" != "$(podman container inspect "$name" -f {{.Image}} 2>&1)" ]; then + log "container image downloaded" '✓' 32 podman container rm -f -t 1 "$name" 1>/dev/null - podman run -it $(run_args) "$image" - exit + podman run -td $(run_args) "$image" + else + log "no updates available" '✓' 32 fi - log "no updates available" '✓' 32 fi podman start "$name" 1>/dev/null