-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathupdatepackages.sh
29 lines (26 loc) · 1.17 KB
/
updatepackages.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
#!/bin/bash
set -u
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
containerIds=$(docker ps -q)
commonPackages="gnupg fakeroot fontconfig"
fedoraPackages="procps-ng hostname shared-mime-info"
debianPackages=""
alpinePackages=""
for container in $containerIds
do
OS=$(docker exec -it $container sh -c "cat /etc/os-release" | head -n 1)
if [[ "$OS" == *"CentOS"* ]] || [[ "$OS" == *"Fedora"* ]] || [[ "$OS" == *"Red Hat Enterprise Linux"* ]]; then
installCommand="yum -y update && yum -y install $commonPackages $fedoraPackages"
elif [[ "$OS" == *"Ubuntu"* ]] || [[ "$OS" == *"Debian"* ]]; then
installCommand="apt-get update && apt-get -y upgrade && apt-get -y install $commonPackages $debianPackages"
elif [[ "$OS" == *"Alpine"* ]]; then
installCommand="apk update && apk upgrade && apk --update add $commonPackages $alpinePackages"
else
echo "Unrecognised OS, skipping package update"
continue
fi
echo "Updating packages for container $container"
echo "Running $installCommand"
docker exec -it $container sh -c "$installCommand"
echo "=============================================="
done