-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathchunkah-tag.sh
More file actions
71 lines (62 loc) · 2.22 KB
/
chunkah-tag.sh
File metadata and controls
71 lines (62 loc) · 2.22 KB
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
66
67
68
69
70
71
#!/bin/sh
# Tag files with package component names for chunkah content-based layering
# Supports: apk (Alpine), rpm (Fedora/RHEL), dpkg (Debian/Ubuntu), pacman (Arch)
set -euo pipefail
tag_files() {
pkgname="$1"
shift
for filepath in "$@"; do
if [ -f "$filepath" ]; then
setfattr -n user.component -v "$pkgname" "$filepath" 2>/dev/null || true
fi
done
}
if command -v apk >/dev/null 2>&1; then
echo "==> Detected Alpine (apk) - tagging files for chunkah"
apk add --no-cache attr
apk info -q | while read pkgname; do
tag_files "$pkgname" $(apk info -L "$pkgname" 2>/dev/null | sed 's|^|/|')
done
apk del attr
echo "✓ Alpine file tagging complete"
elif command -v rpm >/dev/null 2>&1; then
echo "==> Detected RPM-based (dnf/yum) - tagging files for chunkah"
if command -v dnf5 >/dev/null 2>&1; then
dnf5 install -y attr
elif command -v dnf >/dev/null 2>&1; then
dnf install -y attr
else
yum install -y attr
fi
rpm -qa --qf '%{NAME}\n' | while read pkgname; do
tag_files "$pkgname" $(rpm -ql "$pkgname" 2>/dev/null)
done
if command -v dnf5 >/dev/null 2>&1; then
dnf5 remove -y attr
elif command -v dnf >/dev/null 2>&1; then
dnf remove -y attr
else
yum remove -y attr
fi
echo "✓ RPM file tagging complete"
elif command -v dpkg >/dev/null 2>&1; then
echo "==> Detected Debian-based (dpkg/apt) - tagging files for chunkah"
apt-get update && apt-get install -y attr
dpkg-query -W -f='${Package}\n' | while read pkgname; do
tag_files "$pkgname" $(dpkg -L "$pkgname" 2>/dev/null)
done
apt-get remove -y attr
echo "✓ Debian file tagging complete"
elif command -v pacman >/dev/null 2>&1; then
echo "==> Detected Arch (pacman) - tagging files for chunkah"
pacman -Sy --noconfirm attr
pacman -Qq | while read pkgname; do
tag_files "$pkgname" $(pacman -Ql "$pkgname" 2>/dev/null | awk '{print $2}')
done
pacman -R --noconfirm attr
echo "✓ Arch file tagging complete"
else
echo "WARNING: Unknown package manager detected"
echo "Chunkah will still work but layer splitting may be less optimal"
exit 0
fi