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