@@ -12,60 +12,30 @@ function usrcurl() {
12
12
}
13
13
14
14
function download_and_verify() {
15
- # Downloads release artifact to /sysroot/$name and verifies $name.sig with gpg
15
+ # Extracts release artifact to /sysroot/$final_name
16
16
# Expects the env vars: FLATCAR_BOARD, VERSION
17
- local name=" $1 "
18
- # TODO: We should use update.release.flatcar-linux.net and then decode the payload
19
- local channel=" "
20
- case $( echo " ${VERSION} " | cut -d . -f 2) in
21
- 0) channel=" alpha" ;;
22
- 1) channel=" beta" ;;
23
- 2) channel=" stable" ;;
24
- 3) channel=" lts" ;;
25
- * ) ;;
26
- esac
27
- local URLS=()
28
- if [ " ${channel} " != " " ]; then
29
- URLS+=(" https://${channel} .release.flatcar-linux.net/${FLATCAR_BOARD} /${VERSION} /${name} " )
17
+ local final_name=" $1 "
18
+ local name=" ${final_name/ .raw/ .gz} "
19
+ URL=" https://update.release.flatcar-linux.net/${FLATCAR_BOARD} /${VERSION} /${name} "
20
+ # Check for scripts:sdk_container/src/third_party/coreos-overlay/coreos-base/coreos-au-key/files/developer-v1.pub.pem
21
+ if [ " $( usrbin md5sum /sysroot/usr/share/update_engine/update-payload-key.pub.pem | cut -d " " -f 1) " = " 7192addf4a7f890c0057d21653eff2ea" ]; then
22
+ URL=" https://bincache.flatcar-linux.net/images/${FLATCAR_BOARD/ -usr} /${VERSION} /flatcar_test_update-${name} "
30
23
fi
31
- URLS+=(" https://bincache.flatcar-linux.net/images/${FLATCAR_BOARD/ -usr} /${VERSION} /${name} " )
24
+ # TODO: Replace the below with invoking an ue-rs helper binary for downloading the payload
25
+ # from the URL and write the unpacked, verified file to the final name.
32
26
local COUNT=" "
33
- local URL=" "
34
- for URL in " ${URLS[@]} " LAST; do
35
- if [ " ${URL} " = LAST ]; then
36
- echo " Failed to download required sysext image ${name} " >&2
37
- exit 1 # Fail the boot
27
+ # Workaround: Once curl starts and fails to resolve a DNS name (due to a race or temporary failure),
28
+ # it sticks to it for each retry, making the retry pointless. Therefore, we first have to
29
+ # add a curl waiter that does the DNS retry and won't be stuck (nor waste 30*60 seconds).
30
+ for COUNT in $( usrbin seq 30) ; do
31
+ if usrbin curl -fsSL --head " ${URL} " > /dev/null; then
32
+ break
38
33
fi
39
- # Workaround: Once curl starts and fails to resolve a DNS name (due to a race or temporary failure),
40
- # it sticks to it for each retry, making the retry pointless. Therefore, we first have to
41
- # add a curl waiter that does the DNS retry and won't be stuck (nor waste 30*60 seconds).
42
- for COUNT in $( usrbin seq 30) ; do
43
- if usrbin curl -fsSL --head " ${URL} " > /dev/null; then
44
- break
45
- fi
46
- sleep 1
47
- done
48
- usrcurl -o " /sysroot/${name} " " ${URL} " || { rm -f " /sysroot/${name} " ; continue ; }
49
- usrcurl -o " /sysroot/${name} .sig" " ${URL} .sig" || { rm -f " /sysroot/${name} .sig" ; continue ; }
50
- break
34
+ sleep 1
51
35
done
52
- local GPG_KEY=" "
53
- local GPG_LONG_ID=" "
54
- # Extract public key from flatcar-install
55
- GPG_KEY=$( tr ' \n' ' _' < /sysroot/usr/bin/flatcar-install | grep -Po ' GPG_KEY="\K.*?(?=")' | tr ' _' ' \n' )
56
- GPG_LONG_ID=$( grep -Po ' ^GPG_LONG_ID="\K.*?(?=")' /sysroot/usr/bin/flatcar-install)
57
- export GNUPGHOME=/run/_gpg
58
- mkdir -p " ${GNUPGHOME} "
59
- usrbin chmod 700 " ${GNUPGHOME} "
60
- usrbin gpg --batch --quiet --import <<< " ${GPG_KEY}"
61
- if ! usrbin gpg --batch --trusted-key " ${GPG_LONG_ID} " --verify " /sysroot/${name} .sig" " /sysroot/${name} " ; then
62
- rm -f " /sysroot/${name} .sig" " /sysroot/${name} "
63
- rm -rf " ${GNUPGHOME} "
64
- echo " Failed to verify required sysext image ${name} " >&2
65
- exit 1 # Fail the boot
66
- fi
67
- rm " /sysroot/${name} .sig"
68
- rm -rf " ${GNUPGHOME} "
36
+ rm -f " /sysroot/${name} "
37
+ usrcurl -o " /sysroot/${name} " " ${URL} " || { rm -f " /sysroot/${name} " ; return 1 ; }
38
+ usrbin unshare -m sh -c " mount --rbind /dev /sysroot/dev/ && mount -t proc /proc /sysroot/proc/ && PROTOPATH=/usr/share/update_engine/ chroot /sysroot /usr/share/update_engine/decode_payload /usr/share/update_engine/update-payload-key.pub.pem \" /${name} \" \" /${final_name} \" " || { rm -f " /sysroot/${final_name} " ; echo " Failing boot" >&2 ; exit 1; }
69
39
true # Don't leak previous exit code as return code
70
40
}
71
41
@@ -82,7 +52,6 @@ OEMID=$({ grep -m 1 -o "^ID=.*" /sysroot/oem/oem-release || true ; } | cut -d =
82
52
83
53
# The active-oem-OEMID file gets created by the update-engine postinst action if both old and new /usr partitions have a sysext
84
54
if [ " ${OEMID} " != " " ] && [ -e " /sysroot/oem/sysext/active-oem-${OEMID} " ]; then
85
- INITIAL_MVP=" /oem/sysext/oem-${OEMID} -initial.raw"
86
55
SYSEXT_OEM_PART=" /oem/sysext/oem-${OEMID} -${VERSION} .raw"
87
56
SYSEXT_ROOT_PART=" /etc/flatcar/oem-sysext/oem-${OEMID} -${VERSION} .raw"
88
57
SYMLINK=" /sysroot/etc/extensions/oem-${OEMID} .raw"
@@ -111,38 +80,19 @@ if [ "${OEMID}" != "" ] && [ -e "/sysroot/oem/sysext/active-oem-${OEMID}" ]; the
111
80
echo " That failed, keeping it on root partition" >&2
112
81
ACTIVE_OEM=" ${SYSEXT_ROOT_PART} "
113
82
fi
114
- elif [ -e " /sysroot/${INITIAL_MVP} " ]; then
115
- # This is the initial MVP OEM sysext that is not bound to the OS version because
116
- # at that time update support was missing.
117
- # Like any other inactive sysext, it will be deleted by update-engine's post-inst action
118
- # when it's not needed (i.e., the active and new inactive both have a versioned sysext)
119
- ACTIVE_OEM=" ${INITIAL_MVP} "
120
83
else
121
84
echo " Did not find ${SYSEXT_OEM_PART} nor ${SYSEXT_ROOT_PART} , downloading" >&2
122
85
systemctl start --quiet systemd-networkd systemd-resolved
123
86
download_and_verify " oem-${OEMID} .raw"
124
- # TODO: This can be removed once we download the update payload from update.release.flatcar-linux.net
125
- # because it won't be the "initial" MVP sysext
126
- mkdir -p /run/_oem
127
- mount " /sysroot/oem-${OEMID} .raw" /run/_oem/
128
- if grep -q SYSEXT_LEVEL=1.0 " /run/_oem/usr/lib/extension-release.d/extension-release.oem-${OEMID} " ; then
129
- # The initial MVP OEM is only supported on the OEM partition
130
- ACTIVE_OEM=" ${INITIAL_MVP} "
131
- fi
132
- umount " /sysroot/oem-${OEMID} .raw"
133
87
mkdir -p /sysroot/oem/sysext/
134
- if [ " ${ACTIVE_OEM} " != " " ]; then
135
- mv " /sysroot/oem-${OEMID} .raw" " /sysroot${ACTIVE_OEM} "
88
+ echo " Trying to place /sysroot/oem-${OEMID} .raw on OEM partition" >&2
89
+ if mv " /sysroot/oem-${OEMID} .raw" " /sysroot${SYSEXT_OEM_PART} " ; then
90
+ ACTIVE_OEM=" ${SYSEXT_OEM_PART} "
136
91
else
137
- echo " Trying to place /sysroot/oem-${OEMID} .raw on OEM partition" >&2
138
- if mv " /sysroot/oem-${OEMID} .raw" " /sysroot${SYSEXT_OEM_PART} " ; then
139
- ACTIVE_OEM=" ${SYSEXT_OEM_PART} "
140
- else
141
- echo " That failed, moving it to right location on root partition" >&2
142
- mkdir -p /sysroot/etc/flatcar/oem-sysext/
143
- mv " /sysroot/oem-${OEMID} .raw" " /sysroot${SYSEXT_ROOT_PART} "
144
- ACTIVE_OEM=" ${SYSEXT_ROOT_PART} "
145
- fi
92
+ echo " That failed, moving it to right location on root partition" >&2
93
+ mkdir -p /sysroot/etc/flatcar/oem-sysext/
94
+ mv " /sysroot/oem-${OEMID} .raw" " /sysroot${SYSEXT_ROOT_PART} "
95
+ ACTIVE_OEM=" ${SYSEXT_ROOT_PART} "
146
96
fi
147
97
fi
148
98
if [ " ${ACTIVE_OEM} " != " " ] && [ -e " /sysroot/${ACTIVE_OEM} " ]; then
@@ -180,6 +130,7 @@ for NAME in $(grep -h -o '^[^#]*' /sysroot/etc/flatcar/enabled-sysext.conf /sysr
180
130
ACTIVE_EXT=" /etc/flatcar/sysext/flatcar-${NAME} -${VERSION} .raw"
181
131
if [ ! -e " /sysroot/${ACTIVE_EXT} " ]; then
182
132
echo " Did not find ${ACTIVE_EXT} " >&2
133
+ systemctl start --quiet systemd-networkd systemd-resolved
183
134
download_and_verify " flatcar-${NAME} .raw"
184
135
mv " /sysroot/flatcar-${NAME} .raw" " /sysroot/${ACTIVE_EXT} "
185
136
fi
0 commit comments