dreambox-image: use timestamp from start of build, allow to override type and version
[opendreambox.git] / meta-opendreambox / recipes-dreambox / images / dreambox-console-image.inc
1 SUMMARY ?= "A Dreambox firmware image for headless systems"
2
3 # packages to build for the feed
4 DEPENDS = " \
5         gdb \
6         lsof \
7         ltrace \
8         strace \
9 "
10
11 python __anonymous() {
12     pkgtype = d.getVar('IMAGE_PKGTYPE', True)
13     if not oe.utils.inherits(d, 'package_%s' % pkgtype):
14         pn = d.getVar('PN', True)
15         raise bb.parse.SkipPackage("Unable to build %s without %s packages" % (pn, pkgtype))
16 }
17
18 BAD_RECOMMENDATIONS += " \
19     busybox-syslog \
20     libconnman-qt5-qmlplugins \
21     libnss-mdns \
22     qtbase-plugins \
23     qtdeclarative-plugins \
24     qtdeclarative-qmlplugins \
25     qtwebkit-qmlplugins \
26     udev-hwdb \
27     wpa-supplicant-passphrase \
28     xinetd \
29 "
30
31 # packages to drag into the image
32 IMAGE_INSTALL = " \
33     packagegroup-boot-systemd \
34     packagegroup-net-connman \
35     packagegroup-pkg-deb \
36     packagegroup-opendreambox-base \
37     packagegroup-opendreambox-dvbapi3 \
38 "
39
40 # enable online package management
41 IMAGE_FEATURES = "empty-root-password package-management"
42
43 # we don't want any locales, at least not in the common way.
44 IMAGE_LINGUAS = ""
45
46 # 512MB rootfs
47 IMAGE_ROOTFS_SIZE_ext4 = "524288"
48
49 inherit image
50
51 DREAMBOX_IMAGE_DATE = "${@d.getVar('DATETIME', True)[:-2]}"
52 DREAMBOX_IMAGE_DATE[vardepsexclude] = "DATETIME"
53 # 0: Release, 1: Experimental
54 DREAMBOX_IMAGE_TYPE ?= "1"
55 # e.g. 400 for release 4.0.0, if IMAGE_TYPE=0
56 DREAMBOX_IMAGE_VERSION ?= "000"
57
58 opendreambox_rootfs_postprocess() {
59     echo "version=${DREAMBOX_IMAGE_TYPE}${DREAMBOX_IMAGE_VERSION}${DREAMBOX_IMAGE_DATE}" > ${IMAGE_ROOTFS}${sysconfdir}/image-version
60 }
61
62 ROOTFS_POSTPROCESS_COMMAND += "opendreambox_rootfs_postprocess; "
63
64 python dreambox_image_nfo() {
65     def parse_status_file(filename, package):
66         kv = dict()
67         found = 0
68         with open(filename, 'r') as f:
69             for line in f.read().splitlines():
70                 try:
71                     key, value = line.split(': ', 1)
72                     if found == 0 and key == 'Package' and value == package:
73                         found = 1
74                     if found == 1:
75                         kv[key] = value
76                 except:
77                     if found == 1:
78                         break
79         return kv
80
81     def hash_image(filename, algorithm):
82         import hashlib
83         h = hashlib.new(algorithm)
84         with open(filename, 'r') as f:
85             while True:
86                 buf = f.read(1024 * 1024)
87                 if len(buf) == 0:
88                     return h.hexdigest()
89                 h.update(buf)
90         return None
91
92     def file_mtime(filename):
93         from datetime import datetime
94         dt = datetime.fromtimestamp(os.path.getmtime(filename))
95         return dt.isoformat(' ')
96
97     deploy_dir_image = d.getVar('DEPLOY_DIR_IMAGE', True)
98     distro_feed_uri = d.getVar('DISTRO_FEED_URI', True)
99     distro_name = d.getVar('DISTRO_NAME', True)
100     distro_version = d.getVar('DISTRO_VERSION', True)
101     image_fstypes = (d.getVar('IMAGE_FSTYPES', True) or "").split()
102     image_name = d.getVar('IMAGE_NAME', True)
103     image_pkgtype = d.getVar('IMAGE_PKGTYPE', True)
104     image_rootfs = d.getVar('IMAGE_ROOTFS', True)
105     machine = d.getVar('MACHINE', True)
106
107     if oe.utils.inherits(d, 'image_types_nfi'):
108         ext = 'nfi'
109     elif len(image_fstypes) >= 1:
110         ext = 'rootfs.%s' % image_fstypes[0]
111     else:
112         raise bb.build.FuncFailed('Invalid IMAGE_FSTYPES')
113
114     image_path = os.path.join(deploy_dir_image, '.'.join((image_name, ext)))
115
116     attr = dict()
117
118     mtime = file_mtime(image_path)
119     if mtime:
120         attr['Date'] = mtime
121
122     opkglibdir = d.getVar('OPKGLIBDIR', True)
123     if opkglibdir:
124         status_path = image_rootfs + opkglibdir + '/opkg/status'
125     else:
126         status_path = image_rootfs + '/var/lib/dpkg/status'
127
128     control = parse_status_file(status_path, 'kernel-image')
129     if 'Version' in control:
130         if 'Provides' in control:
131             attr['Kernel'] = ' '.join((control['Provides'], control['Version']))
132         else:
133             attr['Kernel'] = control['Version']
134
135     control = parse_status_file(status_path, 'dreambox-dvb-modules')
136     if 'Version' in control:
137         attr['Drivers'] = control['Version']
138
139     control = parse_status_file(status_path, 'enigma2')
140     if 'Version' in control:
141         attr['Enigma2'] = control['Version']
142
143     if distro_name and distro_version:
144         attr['Distro'] = ' '.join((distro_name, distro_version))
145
146     if machine:
147         attr['Machine'] = ' '.join(('Dreambox', machine.upper()))
148
149     if distro_feed_uri and image_pkgtype:
150         attr['Link'] = '/'.join((distro_feed_uri, image_pkgtype))
151
152     md5 = hash_image(image_path, 'md5')
153     if md5:
154         attr['MD5'] = md5
155
156     sha256 = hash_image(image_path, 'sha256')
157     if sha256:
158         attr['SHA256'] = sha256
159
160     nfo_path = os.path.join(deploy_dir_image, '%s.nfo' % image_name)
161     with open(nfo_path, 'w') as f:
162         for key, value in sorted(attr.items()):
163             f.write('%s: %s\n' % (key, value))
164 }
165
166 IMAGE_POSTPROCESS_COMMAND += "dreambox_image_nfo;"