-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bash | ||
|
||
container=dotfiles | ||
image=dotfiles | ||
service=dotfiles-cli.service | ||
|
||
function get_metadata() { | ||
# Output: | ||
# $0 image id | ||
# $1 git revision | ||
# $2 created datetime | ||
# $3 image name | ||
echo $(echo "$@" | jq --raw-output '.[0] | | ||
# `podman ps` returns .ImageID, `podman image inspect` returns .Id | ||
([.ImageID, .Id] | map(select(. != null)))[0], | ||
.Labels["org.opencontainers.image.revision"], | ||
.Labels["org.opencontainers.image.created"], .Image | ||
') | ||
} | ||
|
||
function output() { | ||
local arr | ||
read -a arr <<< "$@" | ||
image=$(echo ${arr[0]} | cut -c1-7) | ||
revision=$(echo ${arr[1]} | cut -c1-7) | ||
datetime=${arr[2]} | ||
echo "$image $datetime $revision" | ||
} | ||
|
||
active=$(systemctl --user is-active $service) | ||
latest=$(get_metadata `podman image inspect $image`) | ||
running=$(get_metadata `podman ps -f name=dotfiles --format="json"`) | ||
# can get this from $running or $latest | ||
image_name=$(podman inspect $container|jq '.[0].ImageName' | cut -d '"' -f 2) | ||
|
||
echo "Image: $image_name" | ||
echo "Status: $active" | ||
echo "Last checked for updates:" | ||
|
||
printf "\n" | ||
headings=$(printf "%-7s %-24s %-7s" "Image" "Created" "Revision") | ||
if [[ "$(output $latest)" == "$(output $running)" ]]; then | ||
printf " Running the latest image\n\n" | ||
echo "$headings" | ||
echo "$(output $latest)" | ||
gum confirm "Check for updates?" && podman pull $image && $0 || exit 0 | ||
else | ||
printf " Update available\n\n" | ||
echo " $headings" | ||
echo " $(output $latest)" | ||
echo "● $(output $running)" | ||
gum confirm "Restart container?" && \ | ||
gum spin --spinner line --title "Restarting $service" -- systemctl --user restart $service && \ | ||
systemctl --user status $service \ | ||
|| exit 0 | ||
fi |