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