-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_podman_containers.sh
executable file
·65 lines (50 loc) · 1.58 KB
/
update_podman_containers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Save current pwd
currentpath=$(pwd)
# Determine toolpath if not set already
relativepath="./" # Define relative path to go from this script to the root level of the tool
if [[ ! -v toolpath ]]; then scriptpath=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ); toolpath=$(realpath --canonicalize-missing ${scriptpath}/${relativepath}); fi
# Load functions
source ${toolpath}/functions.sh
# Define user
user=${1}
if [[ -v user ]]
then
user=$(whoami)
fi
# Get user homedir
userhomedir=$(get_homedir "${user}")
# Get Systemdconfigdir
systemdconfigdir=$(get_systemdconfigdir "${user}")
# Prune old images
podman image prune -f
# List all images
mapfile -t images < <( podman images --all --format="{{.Names}}" )
# Iterate over images
for image in "${images[@]}"
do
# Remove Square brackets []
source=$(echo ${image} | sed 's/[][]//g')
# Debug
debug_message "Processing Container Image <${image}> from <${source}>"
# If source is non-null then try to pull image
if [[ -n "${source}" ]]
then
# Pull (new ?) image
podman pull ${source}
fi
done
# Restart Systemd Container Services
cd ${systemdconfigdir} || exit
for servicepath in container-*.service
do
# Get Service Name (without Path or "./")
servicename=$(basename "${servicepath}")
# Restart Service
systemd_restart "${user}" "${servicename}"
done
# Change back to currentpath
cd ${currentpath} || exit
# Restart the podman-auto-update.service Systemd Service
# This forces old images to be purges and news ones to be fetched
#systemctl --user restart podman-auto-update.service