Skip to content

Commit

Permalink
upgrade: add a flag to upgrade only running instances (#823)
Browse files Browse the repository at this point in the history
* Add a flag to upgrade only running instances

i created multiple instances for different projects, and updating all instances means starting all instances that some do heavy operations at startup, so i want to keep them up-to-date but only for the ones i'm currently using so i thought that --up variable could be useful to add for other/similar usages

* upgrade: rename up flag to running, add example in man page

Signed-off-by: Luca Di Maio <[email protected]>

---------

Signed-off-by: Luca Di Maio <[email protected]>
Co-authored-by: Luca Di Maio <[email protected]>
  • Loading branch information
Julio Gutierrez and 89luca89 authored Aug 3, 2023
1 parent 3501c56 commit 5b5c28f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion distrobox-upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if [ -n "${SUDO_USER}" ] || [ -n "${DOAS_USER}" ]; then
fi

all=0
running=0
container_manager="autodetect"
distrobox_flags=""
distrobox_path="$(dirname "$(realpath "${0}")")"
Expand Down Expand Up @@ -88,6 +89,7 @@ Options:
--help/-h: show this message
--all/-a: perform for all distroboxes
--running: perform only for running distroboxes
--root/-r: launch podman/docker with root privileges. Note that if you need root this is the preferred
way over "sudo distrobox" (note: if using a program other than 'sudo' for root privileges is necessary,
specify it through the DBX_SUDO_PROGRAM env variable, or 'distrobox_sudo_program' config variable)
Expand Down Expand Up @@ -121,6 +123,10 @@ while :; do
all=1
shift
;;
--running)
running=1
shift
;;
-r | --root)
shift
rootful=1
Expand Down Expand Up @@ -154,7 +160,7 @@ if [ "${verbose}" -ne 0 ]; then
set -o xtrace
fi

if [ -z "${container_name}" ] && [ "${all}" -eq 0 ]; then
if [ -z "${container_name}" ] && [ "${all}" -eq 0 ] && [ "${running}" -eq 0 ]; then
printf >&2 "Please specify the name of the container.\n"
exit 1
fi
Expand Down Expand Up @@ -211,6 +217,13 @@ if [ "${all}" -ne 0 ]; then
# shellcheck disable=SC2086,2248
container_name="$("${distrobox_path}"/distrobox-list ${distrobox_flags} --no-color |
tail -n +2 | cut -d'|' -f2 | tr -d ' ')"

# If running, set container_name to the list of names of running instances
if [ "${running}" -ne 0 ]; then
# shellcheck disable=SC2086,2248
container_name="$("${distrobox_path}"/distrobox-list ${distrobox_flags} --no-color |
tail -n +2 | grep -iE '\| running|up' | cut -d'|' -f2 | tr -d ' ')"
fi
fi

# Launch the entrypoint in upgrade mode
Expand Down
5 changes: 5 additions & 0 deletions docs/usage/distrobox-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ an upgrade using the container's package manager.

--help/-h: show this message
--all/-a: perform for all distroboxes
--running: perform only on running distroboxes
--root/-r: launch podman/docker with root privileges. Note that if you need root this is the preferred
way over "sudo distrobox" (note: if using a program other than 'sudo' for root privileges is necessary,
specify it through the DBX_SUDO_PROGRAM env variable, or 'distrobox_sudo_program' config variable)
Expand All @@ -26,6 +27,10 @@ Upgrade all distroboxes

distrobox-upgrade --all

Upgrade all running distroboxes

distrobox-upgrade --all --running

Upgrade a specific distrobox

distrobox-upgrade alpine-linux
Expand Down

0 comments on commit 5b5c28f

Please sign in to comment.