diff options
author | Patrick Vacek <patrickvacek@gmail.com> | 2017-09-25 17:35:39 +0200 |
---|---|---|
committer | Patrick Vacek <patrickvacek@gmail.com> | 2017-09-25 17:35:39 +0200 |
commit | e8916f0d63177548c088f183309f724cda0ca795 (patch) | |
tree | 56bc2e789e01a37d4f43a1dc80626e82b491d0ef | |
parent | e789ff50f9d11f838a3e1cd985cb3ae34c1ca764 (diff) | |
download | meta-updater-e8916f0d63177548c088f183309f724cda0ca795.tar.gz |
Formatting.
According to https://www.openembedded.org/wiki/Styleguide
-rw-r--r-- | classes/image_types_ostree.bbclass | 382 |
1 files changed, 192 insertions, 190 deletions
diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index 97da1db..cb520c2 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass | |||
@@ -2,13 +2,13 @@ | |||
2 | 2 | ||
3 | inherit image | 3 | inherit image |
4 | 4 | ||
5 | IMAGE_DEPENDS_ostree = "ostree-native:do_populate_sysroot \ | 5 | IMAGE_DEPENDS_ostree = "ostree-native:do_populate_sysroot \ |
6 | openssl-native:do_populate_sysroot \ | 6 | openssl-native:do_populate_sysroot \ |
7 | zip-native:do_populate_sysroot \ | 7 | zip-native:do_populate_sysroot \ |
8 | coreutils-native:do_populate_sysroot \ | 8 | coreutils-native:do_populate_sysroot \ |
9 | virtual/kernel:do_deploy \ | 9 | virtual/kernel:do_deploy \ |
10 | ${OSTREE_INITRAMFS_IMAGE}:do_image_complete \ | 10 | ${OSTREE_INITRAMFS_IMAGE}:do_image_complete \ |
11 | unzip-native" | 11 | unzip-native" |
12 | 12 | ||
13 | export OSTREE_REPO | 13 | export OSTREE_REPO |
14 | export OSTREE_BRANCHNAME | 14 | export OSTREE_BRANCHNAME |
@@ -21,202 +21,204 @@ OSTREE_KERNEL ??= "${KERNEL_IMAGETYPE}" | |||
21 | export SYSTEMD_USED = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', '', d)}" | 21 | export SYSTEMD_USED = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', '', d)}" |
22 | 22 | ||
23 | IMAGE_CMD_ostree () { | 23 | IMAGE_CMD_ostree () { |
24 | if [ -z "$OSTREE_REPO" ]; then | 24 | if [ -z "$OSTREE_REPO" ]; then |
25 | bbfatal "OSTREE_REPO should be set in your local.conf" | 25 | bbfatal "OSTREE_REPO should be set in your local.conf" |
26 | fi | 26 | fi |
27 | 27 | ||
28 | if [ -z "$OSTREE_BRANCHNAME" ]; then | 28 | if [ -z "$OSTREE_BRANCHNAME" ]; then |
29 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | 29 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" |
30 | fi | 30 | fi |
31 | 31 | ||
32 | OSTREE_ROOTFS=`mktemp -du ${WORKDIR}/ostree-root-XXXXX` | 32 | OSTREE_ROOTFS=`mktemp -du ${WORKDIR}/ostree-root-XXXXX` |
33 | cp -a ${IMAGE_ROOTFS} ${OSTREE_ROOTFS} | 33 | cp -a ${IMAGE_ROOTFS} ${OSTREE_ROOTFS} |
34 | chmod a+rx ${OSTREE_ROOTFS} | 34 | chmod a+rx ${OSTREE_ROOTFS} |
35 | sync | 35 | sync |
36 | 36 | ||
37 | cd ${OSTREE_ROOTFS} | 37 | cd ${OSTREE_ROOTFS} |
38 | 38 | ||
39 | # Create sysroot directory to which physical sysroot will be mounted | 39 | # Create sysroot directory to which physical sysroot will be mounted |
40 | mkdir sysroot | 40 | mkdir sysroot |
41 | ln -sf sysroot/ostree ostree | 41 | ln -sf sysroot/ostree ostree |
42 | 42 | ||
43 | rm -rf tmp/* | 43 | rm -rf tmp/* |
44 | ln -sf sysroot/tmp tmp | 44 | ln -sf sysroot/tmp tmp |
45 | 45 | ||
46 | mkdir -p usr/rootdirs | 46 | mkdir -p usr/rootdirs |
47 | 47 | ||
48 | mv etc usr/ | 48 | mv etc usr/ |
49 | # Implement UsrMove | 49 | # Implement UsrMove |
50 | dirs="bin sbin lib" | 50 | dirs="bin sbin lib" |
51 | 51 | ||
52 | for dir in ${dirs} ; do | 52 | for dir in ${dirs} ; do |
53 | if [ -d ${dir} ] && [ ! -L ${dir} ] ; then | 53 | if [ -d ${dir} ] && [ ! -L ${dir} ] ; then |
54 | mv ${dir} usr/rootdirs/ | 54 | mv ${dir} usr/rootdirs/ |
55 | rm -rf ${dir} | 55 | rm -rf ${dir} |
56 | ln -sf usr/rootdirs/${dir} ${dir} | 56 | ln -sf usr/rootdirs/${dir} ${dir} |
57 | fi | 57 | fi |
58 | done | 58 | done |
59 | 59 | ||
60 | if [ -n "$SYSTEMD_USED" ]; then | 60 | if [ -n "$SYSTEMD_USED" ]; then |
61 | mkdir -p usr/etc/tmpfiles.d | 61 | mkdir -p usr/etc/tmpfiles.d |
62 | tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf | 62 | tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf |
63 | echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} | 63 | echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} |
64 | echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf} | 64 | echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf} |
65 | else | 65 | else |
66 | mkdir -p usr/etc/init.d | 66 | mkdir -p usr/etc/init.d |
67 | tmpfiles_conf=usr/etc/init.d/tmpfiles.sh | 67 | tmpfiles_conf=usr/etc/init.d/tmpfiles.sh |
68 | echo '#!/bin/sh' > ${tmpfiles_conf} | 68 | echo '#!/bin/sh' > ${tmpfiles_conf} |
69 | echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} | 69 | echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} |
70 | echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf} | 70 | echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf} |
71 | 71 | ||
72 | ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh | 72 | ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh |
73 | fi | 73 | fi |
74 | 74 | ||
75 | # Preserve OSTREE_BRANCHNAME for future information | 75 | # Preserve OSTREE_BRANCHNAME for future information |
76 | mkdir -p usr/share/sota/ | 76 | mkdir -p usr/share/sota/ |
77 | echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname | 77 | echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname |
78 | 78 | ||
79 | # Preserve data in /home to be later copied to /sysroot/home by | 79 | # Preserve data in /home to be later copied to /sysroot/home by sysroot |
80 | # sysroot generating procedure | 80 | # generating procedure |
81 | mkdir -p usr/homedirs | 81 | mkdir -p usr/homedirs |
82 | if [ -d "home" ] && [ ! -L "home" ]; then | 82 | if [ -d "home" ] && [ ! -L "home" ]; then |
83 | mv home usr/homedirs/home | 83 | mv home usr/homedirs/home |
84 | ln -sf var/rootdirs/home home | 84 | ln -sf var/rootdirs/home home |
85 | fi | 85 | fi |
86 | 86 | ||
87 | # Move persistent directories to /var | 87 | # Move persistent directories to /var |
88 | dirs="opt mnt media srv" | 88 | dirs="opt mnt media srv" |
89 | 89 | ||
90 | for dir in ${dirs}; do | 90 | for dir in ${dirs}; do |
91 | if [ -d ${dir} ] && [ ! -L ${dir} ]; then | 91 | if [ -d ${dir} ] && [ ! -L ${dir} ]; then |
92 | if [ "$(ls -A $dir)" ]; then | 92 | if [ "$(ls -A $dir)" ]; then |
93 | bbwarn "Data in /$dir directory is not preserved by OSTree. Consider moving it under /usr" | 93 | bbwarn "Data in /$dir directory is not preserved by OSTree. Consider moving it under /usr" |
94 | fi | 94 | fi |
95 | 95 | ||
96 | if [ -n "$SYSTEMD_USED" ]; then | 96 | if [ -n "$SYSTEMD_USED" ]; then |
97 | echo "d /var/rootdirs/${dir} 0755 root root -" >>${tmpfiles_conf} | 97 | echo "d /var/rootdirs/${dir} 0755 root root -" >>${tmpfiles_conf} |
98 | else | 98 | else |
99 | echo "mkdir -p /var/rootdirs/${dir}; chown 755 /var/rootdirs/${dir}" >>${tmpfiles_conf} | 99 | echo "mkdir -p /var/rootdirs/${dir}; chown 755 /var/rootdirs/${dir}" >>${tmpfiles_conf} |
100 | fi | 100 | fi |
101 | rm -rf ${dir} | 101 | rm -rf ${dir} |
102 | ln -sf var/rootdirs/${dir} ${dir} | 102 | ln -sf var/rootdirs/${dir} ${dir} |
103 | fi | 103 | fi |
104 | done | 104 | done |
105 | 105 | ||
106 | if [ -d root ] && [ ! -L root ]; then | 106 | if [ -d root ] && [ ! -L root ]; then |
107 | if [ "$(ls -A root)" ]; then | 107 | if [ "$(ls -A root)" ]; then |
108 | bberror "Data in /root directory is not preserved by OSTree." | 108 | bberror "Data in /root directory is not preserved by OSTree." |
109 | fi | 109 | fi |
110 | 110 | ||
111 | if [ -n "$SYSTEMD_USED" ]; then | 111 | if [ -n "$SYSTEMD_USED" ]; then |
112 | echo "d /var/roothome 0755 root root -" >>${tmpfiles_conf} | 112 | echo "d /var/roothome 0755 root root -" >>${tmpfiles_conf} |
113 | else | 113 | else |
114 | echo "mkdir -p /var/roothome; chown 755 /var/roothome" >>${tmpfiles_conf} | 114 | echo "mkdir -p /var/roothome; chown 755 /var/roothome" >>${tmpfiles_conf} |
115 | fi | 115 | fi |
116 | 116 | ||
117 | rm -rf root | 117 | rm -rf root |
118 | ln -sf var/roothome root | 118 | ln -sf var/roothome root |
119 | fi | 119 | fi |
120 | 120 | ||
121 | mkdir -p var/sota | 121 | mkdir -p var/sota |
122 | 122 | ||
123 | if [ -n "${SOTA_AUTOPROVISION_CREDENTIALS}" ]; then | 123 | if [ -n "${SOTA_AUTOPROVISION_CREDENTIALS}" ]; then |
124 | bbwarn "SOTA_AUTOPROVISION_CREDENTIALS are ignored. Please use SOTA_PACKED_CREDENTIALS" | 124 | bbwarn "SOTA_AUTOPROVISION_CREDENTIALS are ignored. Please use SOTA_PACKED_CREDENTIALS" |
125 | fi | 125 | fi |
126 | if [ -n "${SOTA_AUTOPROVISION_URL}" ]; then | 126 | if [ -n "${SOTA_AUTOPROVISION_URL}" ]; then |
127 | bbwarn "SOTA_AUTOPROVISION_URL is ignored. Please use SOTA_PACKED_CREDENTIALS" | 127 | bbwarn "SOTA_AUTOPROVISION_URL is ignored. Please use SOTA_PACKED_CREDENTIALS" |
128 | fi | 128 | fi |
129 | if [ -n "${SOTA_AUTOPROVISION_URL_FILE}" ]; then | 129 | if [ -n "${SOTA_AUTOPROVISION_URL_FILE}" ]; then |
130 | bbwarn "SOTA_AUTOPROVISION_URL_FILE is ignored. Please use SOTA_PACKED_CREDENTIALS" | 130 | bbwarn "SOTA_AUTOPROVISION_URL_FILE is ignored. Please use SOTA_PACKED_CREDENTIALS" |
131 | fi | 131 | fi |
132 | if [ -n "${OSTREE_PUSH_CREDENTIALS}" ]; then | 132 | if [ -n "${OSTREE_PUSH_CREDENTIALS}" ]; then |
133 | bbwarn "OSTREE_PUSH_CREDENTIALS is ignored. Please use SOTA_PACKED_CREDENTIALS" | 133 | bbwarn "OSTREE_PUSH_CREDENTIALS is ignored. Please use SOTA_PACKED_CREDENTIALS" |
134 | fi | 134 | fi |
135 | 135 | ||
136 | # deploy SOTA credentials | 136 | # deploy SOTA credentials |
137 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then | 137 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then |
138 | if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then | 138 | if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then |
139 | cp ${SOTA_PACKED_CREDENTIALS} var/sota/sota_provisioning_credentials.zip | 139 | cp ${SOTA_PACKED_CREDENTIALS} var/sota/sota_provisioning_credentials.zip |
140 | # Device should not be able to push data to treehub | 140 | # Device should not be able to push data to treehub |
141 | zip -d var/sota/sota_provisioning_credentials.zip treehub.json | 141 | zip -d var/sota/sota_provisioning_credentials.zip treehub.json |
142 | fi | 142 | fi |
143 | fi | 143 | fi |
144 | 144 | ||
145 | if [ -n "${SOTA_SECONDARY_ECUS}" ]; then | 145 | if [ -n "${SOTA_SECONDARY_ECUS}" ]; then |
146 | cp ${SOTA_SECONDARY_ECUS} var/sota/ecus | 146 | cp ${SOTA_SECONDARY_ECUS} var/sota/ecus |
147 | fi | 147 | fi |
148 | 148 | ||
149 | # Deploy client certificate and key. | 149 | # Deploy client certificate and key. |
150 | if [ -n "${SOTA_CLIENT_CERTIFICATE}" ]; then | 150 | if [ -n "${SOTA_CLIENT_CERTIFICATE}" ]; then |
151 | if [ -e ${SOTA_CLIENT_CERTIFICATE} ]; then | 151 | if [ -e ${SOTA_CLIENT_CERTIFICATE} ]; then |
152 | mkdir -p var/sota/token | 152 | mkdir -p var/sota/token |
153 | cp ${SOTA_CLIENT_CERTIFICATE} var/sota/token/ | 153 | cp ${SOTA_CLIENT_CERTIFICATE} var/sota/token/ |
154 | fi | 154 | fi |
155 | fi | 155 | fi |
156 | if [ -n "${SOTA_CLIENT_KEY}" ]; then | 156 | if [ -n "${SOTA_CLIENT_KEY}" ]; then |
157 | if [ -e ${SOTA_CLIENT_KEY} ]; then | 157 | if [ -e ${SOTA_CLIENT_KEY} ]; then |
158 | mkdir -p var/sota/token | 158 | mkdir -p var/sota/token |
159 | cp ${SOTA_CLIENT_KEY} var/sota/token/ | 159 | cp ${SOTA_CLIENT_KEY} var/sota/token/ |
160 | fi | 160 | fi |
161 | fi | 161 | fi |
162 | if [ -n "${SOTA_ROOT_CA}" ]; then | 162 | if [ -n "${SOTA_ROOT_CA}" ]; then |
163 | if [ -e ${SOTA_ROOT_CA} ]; then | 163 | if [ -e ${SOTA_ROOT_CA} ]; then |
164 | cp ${SOTA_ROOT_CA} var/sota/ | 164 | cp ${SOTA_ROOT_CA} var/sota/ |
165 | fi | 165 | fi |
166 | fi | 166 | fi |
167 | 167 | ||
168 | # Creating boot directories is required for "ostree admin deploy" | 168 | # Creating boot directories is required for "ostree admin deploy" |
169 | 169 | ||
170 | mkdir -p boot/loader.0 | 170 | mkdir -p boot/loader.0 |
171 | mkdir -p boot/loader.1 | 171 | mkdir -p boot/loader.1 |
172 | ln -sf boot/loader.0 boot/loader | 172 | ln -sf boot/loader.0 boot/loader |
173 | 173 | ||
174 | checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` | 174 | checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` |
175 | 175 | ||
176 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} | 176 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} |
177 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT} boot/initramfs-${checksum} | 177 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT} boot/initramfs-${checksum} |
178 | 178 | ||
179 | # Copy image manifest | 179 | # Copy image manifest |
180 | cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest | 180 | cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest |
181 | 181 | ||
182 | cd ${WORKDIR} | 182 | cd ${WORKDIR} |
183 | 183 | ||
184 | # Create a tarball that can be then commited to OSTree repo | 184 | # Create a tarball that can be then commited to OSTree repo |
185 | OSTREE_TAR=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 | 185 | OSTREE_TAR=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 |
186 | tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . | 186 | tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . |
187 | sync | 187 | sync |
188 | 188 | ||
189 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 | 189 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 |
190 | ln -s ${IMAGE_NAME}.rootfs.ostree.tar.bz2 ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 | 190 | ln -s ${IMAGE_NAME}.rootfs.ostree.tar.bz2 ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 |
191 | 191 | ||
192 | if [ ! -d ${OSTREE_REPO} ]; then | 192 | if [ ! -d ${OSTREE_REPO} ]; then |
193 | ostree --repo=${OSTREE_REPO} init --mode=archive-z2 | 193 | ostree --repo=${OSTREE_REPO} init --mode=archive-z2 |
194 | fi | 194 | fi |
195 | 195 | ||
196 | # Commit the result | 196 | # Commit the result |
197 | ostree --repo=${OSTREE_REPO} commit \ | 197 | ostree --repo=${OSTREE_REPO} commit \ |
198 | --tree=dir=${OSTREE_ROOTFS} \ | 198 | --tree=dir=${OSTREE_ROOTFS} \ |
199 | --skip-if-unchanged \ | 199 | --skip-if-unchanged \ |
200 | --branch=${OSTREE_BRANCHNAME} \ | 200 | --branch=${OSTREE_BRANCHNAME} \ |
201 | --subject="Commit-id: ${IMAGE_NAME}" | 201 | --subject="Commit-id: ${IMAGE_NAME}" |
202 | 202 | ||
203 | rm -rf ${OSTREE_ROOTFS} | 203 | rm -rf ${OSTREE_ROOTFS} |
204 | } | 204 | } |
205 | 205 | ||
206 | IMAGE_TYPEDEP_ostreepush = "ostree" | 206 | IMAGE_TYPEDEP_ostreepush = "ostree" |
207 | IMAGE_DEPENDS_ostreepush = "sota-tools-native:do_populate_sysroot" | 207 | IMAGE_DEPENDS_ostreepush = "sota-tools-native:do_populate_sysroot" |
208 | IMAGE_CMD_ostreepush () { | 208 | IMAGE_CMD_ostreepush () { |
209 | # Print warnings if credetials are not set or if the file has not been found. | 209 | # Print warnings if credetials are not set or if the file has not been found. |
210 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then | 210 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then |
211 | if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then | 211 | if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then |
212 | garage-push --repo=${OSTREE_REPO} \ | 212 | garage-push --repo=${OSTREE_REPO} \ |
213 | --ref=${OSTREE_BRANCHNAME} \ | 213 | --ref=${OSTREE_BRANCHNAME} \ |
214 | --credentials=${SOTA_PACKED_CREDENTIALS} \ | 214 | --credentials=${SOTA_PACKED_CREDENTIALS} \ |
215 | --cacert=${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt | 215 | --cacert=${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt |
216 | else | ||
217 | bbwarn "SOTA_PACKED_CREDENTIALS file does not exist." | ||
218 | fi | ||
219 | else | 216 | else |
220 | bbwarn "SOTA_PACKED_CREDENTIALS not set. Please add SOTA_PACKED_CREDENTIALS." | 217 | bbwarn "SOTA_PACKED_CREDENTIALS file does not exist." |
221 | fi | 218 | fi |
219 | else | ||
220 | bbwarn "SOTA_PACKED_CREDENTIALS not set. Please add SOTA_PACKED_CREDENTIALS." | ||
221 | fi | ||
222 | } | 222 | } |
223 | |||
224 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||