@@ -51,56 +51,33 @@ OEMID=$({ grep -m 1 -o "^ID=.*" "${OEM_MNT}"/oem-release || true ; } | cut -d =
51
51
sysext_download () {
52
52
local name=" $1 " # Payload name
53
53
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=()
60
58
local ret
61
59
SUCCESS=false
62
60
set +e
61
+ # Needs to run before subshell, thus explicit error handling
62
+ target_tmpdir=" $( dirname " ${target} " ) /ue-rs/" || return 1
63
63
(
64
64
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} "
66
67
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} " )
68
69
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} " )
70
71
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} " )
97
73
fi
98
74
# 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} "
100
77
)
101
78
ret=$?
102
79
set -e
103
- rm -f " ${target} .tmp "
80
+ rm -rf " ${target_tmpdir} "
104
81
if [ " ${ret} " -eq 0 ]; then
105
82
SUCCESS=true
106
83
fi
0 commit comments