feat: add DEVC_COMMAND option
This commit is contained in:
35
devc.sh
35
devc.sh
@@ -33,13 +33,13 @@ default_args() {
|
|||||||
[ -e "$SSH_AUTH_SOCK" ] && arg "-v $SSH_AUTH_SOCK:/run/user/1000/ssh-auth-sock"
|
[ -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
|
# Make the user home dir a volume so it survives container
|
||||||
# restarts. Use copy to keep the homedir files from the image.
|
# restarts. Use copy to keep the files from the image.
|
||||||
arg "-v $name:/home/user:copy"
|
arg "-v $name:/home/user:copy"
|
||||||
|
|
||||||
# If there is custom configuration for the container, load
|
# If there is custom configuration for the container, load
|
||||||
# it here.
|
# it here.
|
||||||
config_file="$(dirname "$(realpath "$0")")/containers/$name/config.sh"
|
config_file="$(dirname "$(realpath "$0")")/containers/$name/config.sh"
|
||||||
[ -f "${config_file}" ] && source "${config_file}"
|
[ -f "$config_file" ] && source "${config_file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# param_args returns the podman run arguments based on the
|
# param_args returns the podman run arguments based on the
|
||||||
@@ -56,8 +56,8 @@ param_args() {
|
|||||||
;;
|
;;
|
||||||
-x11) # Enable X11 support.
|
-x11) # Enable X11 support.
|
||||||
arg "-e DISPLAY=$DISPLAY"
|
arg "-e DISPLAY=$DISPLAY"
|
||||||
arg "-v /tmp/.X11-unix:/tmp/.X11-unix"
|
|
||||||
arg "-e XAUTHORITY=/run/user/1000/.Xauthority"
|
arg "-e XAUTHORITY=/run/user/1000/.Xauthority"
|
||||||
|
arg "-v /tmp/.X11-unix:/tmp/.X11-unix"
|
||||||
arg "-v $XAUTHORITY:/run/user/1000/.Xauthority:ro"
|
arg "-v $XAUTHORITY:/run/user/1000/.Xauthority:ro"
|
||||||
;;
|
;;
|
||||||
*) # Use unknown arguments a podman arguments.
|
*) # Use unknown arguments a podman arguments.
|
||||||
@@ -68,14 +68,6 @@ param_args() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
### MAIN ###
|
### MAIN ###
|
||||||
# Get container registry from 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
|
|
||||||
|
|
||||||
# Get the devcontainer name from the first argument. If not
|
# Get the devcontainer name from the first argument. If not
|
||||||
# provided, use the last used name when possible.
|
# provided, use the last used name when possible.
|
||||||
if [[ $# -gt 0 ]] && [[ ${1:-} != -* ]]; then
|
if [[ $# -gt 0 ]] && [[ ${1:-} != -* ]]; then
|
||||||
@@ -91,12 +83,27 @@ else
|
|||||||
fi
|
fi
|
||||||
name="${image%:*}"
|
name="${image%:*}"
|
||||||
|
|
||||||
# Create a new container when the container is not running or
|
# Get container registry from the DEVC_REGISTRY env
|
||||||
# when any arguments are provided.
|
# variable.
|
||||||
|
if [ -n "${DEVC_REGISTRY:-}" ]; then
|
||||||
|
registry="$DEVC_REGISTRY"
|
||||||
|
else
|
||||||
|
log "registry unknown; set the DEVC_REGISTRY environment variable" 'x' 31
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# 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
|
if [ "$(podman container inspect "$name" -f {{.State.Running}} 2>&1)" != 'true' ] || [[ $# -gt 0 ]]; then
|
||||||
log "starting devcontainer..."
|
log "starting devcontainer..."
|
||||||
podman container rm -f -t 0 "$name" 1>/dev/null
|
podman container rm -f -t 0 "$name" 1>/dev/null
|
||||||
podman run -td $(default_args) $(param_args $@) "$registry/$image"
|
podman run -td $(default_args) $(param_args $@) "$registry/$image"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
podman exec -it "$name" bash -l
|
podman exec -it "$name" ${DEVC_COMMAND:-}
|
||||||
|
|||||||
Reference in New Issue
Block a user