-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·48 lines (39 loc) · 1.35 KB
/
update.sh
File metadata and controls
executable file
·48 lines (39 loc) · 1.35 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
#!/bin/sh
TARGET="Containerfile"
SOURCE="https://codeberg.org/stagex/stagex/raw/branch/main/digests"
STAGES="core user bootstrap"
TMPFILE="$(mktemp)"
DIGESTS_TMP="$(mktemp)"
for stage in $STAGES; do
curl -fsSL "$SOURCE/$stage.txt" | while read -r digest name; do
echo "$name $digest" >> "$DIGESTS_TMP"
done
done
while IFS= read -r line; do
case "$line" in
FROM\ stagex/*)
full_image=$(echo "$line" | awk '{print $2}')
name=$(echo "$full_image" | cut -d/ -f2 | cut -d: -f1)
tag=$(echo "$full_image" | cut -d: -f2 | cut -d@ -f1)
digest=""
digest=$(awk -v name="$name" '$1 == name { print $2 }' "$DIGESTS_TMP")
if [ -z "$digest" ]; then
for stage in $STAGES; do
staged_name="$stage-$name"
digest=$(awk -v name="$staged_name" '$1 == name { print $2 }' "$DIGESTS_TMP")
[ -n "$digest" ] && name="$staged_name" && break
done
fi
if [ -n "$digest" ]; then
echo "FROM stagex/$name:$tag@sha256:$digest AS $name" >> "$TMPFILE"
else
echo "$line" >> "$TMPFILE"
fi
;;
*)
echo "$line" >> "$TMPFILE"
;;
esac
done < "$TARGET"
mv "$TMPFILE" "$TARGET"
rm -f "$DIGESTS_TMP"