1 SQUASHFS_IMG_NAMES ?= ""
2 SQUASHFS_IMG_REPLACES ?= ""
3 SQUASHFS_IMG_BLOCKSIZES ?= ""
4 SQUASHFS_IMG_FILESREGEX ?= ""
5 SQUASHFS_IMG_COMPRESSOR ?= ""
6 SQUASHFS_IMG_SUPPORT_ENABLED ?= "${@base_less_or_equal('DREAMBOX_IMAGE_SIZE', 64, 1, 0, d)}"
8 DEPENDS += '${@base_contains('SQUASHFS_IMG_SUPPORT_ENABLED', '1', 'squashfs-tools-native dreambox-squashfs-support', '', d)}'
10 PACKAGE_ARCH := "${@base_contains('SQUASHFS_IMG_SUPPORT_ENABLED', '1', '${MACHINE_ARCH}', '${PACKAGE_ARCH}', d)}"
12 python emit_pkgdata_prepend() {
13 import os, subprocess, glob, re, shutil
14 enabled = d.getVar('SQUASHFS_IMG_SUPPORT_ENABLED', True)
17 bb.note('squashfs-image-support is disabled..')
25 def rename(src, dest):
31 def symlink(source, link_name):
33 os.symlink(source, link_name)
43 packages = d.getVar('PACKAGES', True).split(' ')
44 packagesdir = d.getVar('PKGDEST', True)
46 package_names = d.getVar('SQUASHFS_IMG_PACKAGES', True).split(':')
47 package_replaces = d.getVar('SQUASHFS_IMG_REPLACES', True).split(':')
48 package_blocksizes = d.getVar('SQUASHFS_IMG_BLOCKSIZES', True).split(':')
49 package_filesregex = d.getVar('SQUASHFS_IMG_FILESREGEX', True).split(':')
50 package_compressor = d.getVar('SQUASHFS_IMG_COMPRESSOR', True)
52 if not package_compressor:
53 package_compressor = 'xz'
55 num_replaces = len(package_replaces)
56 num_blocksizes = len(package_blocksizes)
57 num_filesregex = len(package_filesregex)
60 for package in package_names:
61 bb.note('building squashfs img %s' %package)
65 packagedir = packagesdir+'/'+package
67 if num_replaces <= idx:
68 bb.fatal('no replaces for %s' %package)
70 replaces = package_replaces[idx].split(' ')
71 replaces = [ repl.strip('\t ') for repl in replaces if repl.strip('\t ') ]
74 if num_blocksizes > idx:
75 blocksize = package_blocksizes[idx]
77 blocksize = str(128*1024)
79 if num_filesregex > idx:
80 filesregex = package_filesregex[idx]
83 filesre = re.compile(filesregex)
87 bb.note('replaces %s, blocksize %s, file_regex %s' %(replaces, blocksize, filesregex))
90 bb.note('process replacement %s' %repl)
92 files_pathes = d.getVar('FILES_%s'%repl, True).split(' ')
93 files_pathes = [ p.strip('\t ') for p in files_pathes ]
95 bb.fatal('couldnt retrieve FILES_%s!' %repl)
96 repldir = packagesdir+'/'+repl
97 bb.note('FILES_%s %s' %(repl, files_pathes))
100 for path in files_pathes:
101 if path.startswith('/etc'):
104 for realpath in glob.glob(realp):
105 if os.path.isdir(realpath):
107 for root, dirs, names in os.walk(realpath):
108 files += [ root+'/'+name for name in names ]
110 if os.path.islink(realpath):
112 files = glob.glob(realpath)
113 files = [ (f, l) for f in files if not os.path.islink(f) and (not filesre or filesre.search(f) is not None) ]
114 squashfs_files += files
116 if not squashfs_files:
117 bb.fatal("no squashfs files ... maybe regex wrong?!?")
119 bb.note('squashfs_files %s' %[ f for f, l in squashfs_files ])
121 makedirs(packagedir+'/media/squashfs-images/'+package)
122 makedirs(packagedir+'/squashfs-images')
124 for f, l in squashfs_files:
125 makedirs(packagedir+'/tmp'+os.path.dirname(f)[l:])
126 rename(f, packagedir+'/tmp'+f[l:])
127 symlink('/media/squashfs-images/'+package+f[l:], f)
129 squashfs_cmd = ['mksquashfs']
130 squashfs_cmd.append(packagedir+'/tmp/')
131 squashfs_cmd.append(packagedir+'/squashfs-images/'+package)
132 squashfs_cmd.append('-b')
133 squashfs_cmd.append('%s' %blocksize)
134 squashfs_cmd.append('-comp')
135 squashfs_cmd.append('%s' %package_compressor)
137 bb.note('squashfs_cmd %s' %squashfs_cmd)
139 if subprocess.call(squashfs_cmd):
140 bb.fatal('mksquashfs failed!')
142 rmtree(packagedir+'/tmp')
144 for repl in replaces:
145 rdepends = d.getVar('RDEPENDS_'+repl, True).split(' ')
146 rdepends.append(package)
147 d.setVar('RDEPENDS_'+repl, ' '.join(rdepends))
148 d.setVar('INSANE_SKIP_'+repl, 'dev-so')
149 d.setVar('ALLOW_EMPTY_'+repl, '1')
151 d.setVar('RDEPENDS_'+package, 'dreambox-squashfs-support')
152 d.setVar('FILES_'+package, '/')
153 d.setVar('pkg_preinst_'+package, 'if [ -z "$D" ]; then if mountpoint -q /media/squashfs-images/'+package+'; then umount /media/squashfs-images/'+package+' && losetup -d `losetup | grep '+package+' | cut -d: -f1` || touch /var/tmp/.umount_'+package+'_needed; else touch /var/tmp/.umount_'+package+'_needed; fi; fi')
154 d.setVar('pkg_postinst_'+package, 'if [ -z "$D" ]; then if ! mountpoint -q /media/squashfs-images/'+package+'; then mount -t squashfs -o ro,loop /squashfs-images/'+package+' /media/squashfs-images/'+package+' || touch /var/tmp/.mount_'+package+'_needed; else touch /var/tmp/.mount_'+package+'_needed; fi; fi')
155 d.setVar('pkg_postrm_'+package, 'if [ -z "$D" ]; then if mountpoint -q /media/squashfs-images/'+package+'; then umount /media/squashfs-images/'+package+' && losetup -d `losetup | grep '+package+' | cut -d: -f1` || touch /var/tmp/.umount_'+package+'_needed; else touch /var/tmp/.umount_'+package+'_needed; fi; fi')
156 packages.append(package)
160 d.setVar('PACKAGES', ' '.join(packages))