Skip to content

Commit c4a4c8b

Browse files
committed
flatcar-postinst: Make use of ue-rs download_sysext binary
The ue-rs download_sysext binary can now do what was done in bash with curl plus decode_payload before. Switch to make use of the binary.
1 parent 8fb11a4 commit c4a4c8b

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

flatcar-postinst

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,33 @@ OEMID=$({ grep -m 1 -o "^ID=.*" "${OEM_MNT}"/oem-release || true ; } | cut -d =
5151
sysext_download() {
5252
local name="$1" # Payload name
5353
local target="$2" # Path to write the payload to, writing does not need to be atomic because the caller later does an atomic move
54-
local from="${3-}" # Either path to XML dump or the constant "release-server"
55-
local base=""
56-
local entries=""
57-
local hash=""
58-
local size=""
59-
local url=""
54+
local from="$3" # Either path to XML dump or the constant "release-server"
55+
local target_tmpdir=""
56+
local extracted_filename="${name/.gz/.raw}"
57+
local ARG=()
6058
local ret
6159
SUCCESS=false
6260
set +e
61+
# Needs to run before subshell, thus explicit error handling
62+
target_tmpdir="$(dirname "${target}")/ue-rs/" || return 1
6363
(
6464
set -e
65-
# TODO: Replace the below with invoking an ue-rs helper binary for downloading the payload "name", either from the XML data or the release server ("from"), and write unpacked, verified file to "target"
65+
rm -rf "${target_tmpdir}"
66+
mkdir -p "${target_tmpdir}"
6667
if [ "${from}" = "release-server" ]; then
67-
url="https://update.release.flatcar-linux.net/${FLATCAR_BOARD}/${NEXT_VERSION}/${name}"
68+
ARG=("-u" "https://update.release.flatcar-linux.net/${FLATCAR_BOARD}/${NEXT_VERSION}/${name}")
6869
elif [ "${from}" = "bincache-server" ]; then
69-
url="https://bincache.flatcar-linux.net/images/${FLATCAR_BOARD/-usr}/${NEXT_VERSION}/${name}"
70+
ARG=("-u" "https://bincache.flatcar-linux.net/images/${FLATCAR_BOARD/-usr}/${NEXT_VERSION}/${name}")
7071
else
71-
base=$(grep -m 1 -o 'codebase="[^"]*"' "${from}" | cut -d '"' -f 2)
72-
entries=$(grep -m 1 -o "<package name=\"${name}\"[^>]*" "${from}")
73-
url="${base}/${name}"
74-
size=$(echo "${entries}" | grep -o 'size="[0-9]*' | cut -d '"' -f 2)
75-
hash=$(echo "${entries}" | { grep -o -P 'hash="[^"]*' || true ; } | cut -d '"' -f 2) # openssl dgst -binary -sha1 < "$PAYLOAD" | base64
76-
hash_sha256=$(echo "${entries}" | { grep -o -P 'hash_sha256="[^"]*' || true ; } | cut -d '"' -f 2) # sha256sum -b "$PAYLOAD" | cut -d " " -f 1
77-
fi
78-
rm -f "${target}.tmp"
79-
curl -fsSL --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 -o "${target}.tmp" "${url}"
80-
if [ "${base}" != "" ]; then
81-
if [ "$(stat --printf='%s' "${target}.tmp")" != "${size}" ]; then
82-
echo "Size mismatch for ${name}" >&2
83-
return 1 # jump to ret=
84-
fi
85-
if [ "${hash}" = "" ] && [ "${hash_sha256}" = "" ]; then
86-
echo "At least one hash is expected, found none in Omaha package for ${name}" >&2
87-
return 1 # jump to ret=
88-
fi
89-
if [ "${hash}" != "" ] && [ "$(openssl dgst -binary -sha1 < "${target}.tmp" | base64)" != "${hash}" ]; then
90-
echo "Hash mismatch for ${name}" >&2
91-
return 1 # jump to ret=
92-
fi
93-
if [ "${hash_sha256}" != "" ] && [ "$(sha256sum -b "${target}.tmp" | cut -d " " -f 1)" != "${hash_sha256}" ]; then
94-
echo "Hash SHA256 mismatch for ${name}" >&2
95-
return 1 # jump to ret=
96-
fi
72+
ARG=("-i" "${from}" -m "${name}")
9773
fi
9874
# Using "${INSTALL_MNT}" here is ok because it was verified first by update-engine
99-
PROTOPATH="${INSTALL_MNT}"/share/update_engine/ "${INSTALL_MNT}"/share/update_engine/decode_payload /usr/share/update_engine/update-payload-key.pub.pem "${target}.tmp" "${target}"
75+
LD_LIBRARY_PATH="${INSTALL_MNT}"/lib64 "${INSTALL_MNT}"/bin/download_sysext -p /usr/share/update_engine/update-payload-key.pub.pem -o "${target_tmpdir}" "${ARG[@]}"
76+
mv "${target_tmpdir}/${extracted_filename}" "${target}"
10077
)
10178
ret=$?
10279
set -e
103-
rm -f "${target}.tmp"
80+
rm -rf "${target_tmpdir}"
10481
if [ "${ret}" -eq 0 ]; then
10582
SUCCESS=true
10683
fi

0 commit comments

Comments
 (0)