Better variant (and this time working)
def _unpack_generic_initrd(self): initrd_path = os.path.join( 'usr', 'lib', 'ubuntu-core-generic-initrd', 'initrd.img-core') initrd_unpacked_path = os.path.join(self.builddir, 'initrd-staging') if os.path.exists(initrd_unpacked_path): shutil.rmtree(initrd_unpacked_path) os.makedirs(initrd_unpacked_path)
with tempfile.TemporaryDirectory() as temp_dir: subprocess.check_call([ 'unsquashfs', self.os_snap, os.path.dirname(initrd_path)], cwd=temp_dir)
tmp_initrd_path = os.path.join(temp_dir, 'squashfs-root', initrd_path) cmd = shlex.split('file -L --mime-type {}'.format(tmp_initrd_path)) result = subprocess.check_output(cmd) mime_type = str(result.split()[-1]) logger.info('initrd mime_type: {} {}'.format(tmp_initrd_path, mime_type)) decompressor = 'gzip' if "gzip" in mime_type: decompressor = 'gzip' elif "x-xz" in mime_type: decompressor = 'xz' elif "x-lzma" in mime_type: decompressor = 'xz'
subprocess.check_call( 'cat {0} | {1} -dc | cpio -i'.format(tmp_initrd_path, decompressor), shell=True, cwd=initrd_unpacked_path)
return initrd_unpacked_path
Better variant (and this time working)
def _unpack_ generic_ initrd( self): core-generic- initrd' , 'initrd.img-core')
initrd_ unpacked_ path = os.path. join(self. builddir, 'initrd-staging') exists( initrd_ unpacked_ path):
shutil. rmtree( initrd_ unpacked_ path)
os.makedirs( initrd_ unpacked_ path)
initrd_path = os.path.join(
'usr', 'lib', 'ubuntu-
if os.path.
with tempfile. TemporaryDirect ory() as temp_dir:
subprocess .check_ call([
'unsquashfs' , self.os_snap, os.path. dirname( initrd_ path)],
cwd=temp_ dir)
cmd = shlex.split('file -L --mime-type {}'.format(
result = subprocess.
if "gzip" in mime_type:
elif "x-xz" in mime_type:
elif "x-lzma" in mime_type:
return initrd_ unpacked_ path