Commit 9e525f70 authored by David Boddie's avatar David Boddie 💬
Browse files

Add tools to extract license information from system images

parent 19512f55
Pipeline #52557 failed with stage
in 15 seconds
This diff is collapsed.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 Purism SPC
# SPDX-License-Identifier: GPL-3.0+
# Author: David Boddie <david.boddie@puri.sm>
import locale
import os
import shlex
import subprocess
import sys
if __name__ == '__main__':
if len(sys.argv) != 3:
sys.stderr.write('Usage: %s <librem5.img disk image> '
'<mount point>\n' % sys.argv[0])
sys.exit(1)
image = sys.argv[1]
mount_point = sys.argv[2]
s = subprocess.Popen(['fdisk', '--units=sectors', '-l', shlex.quote(image)],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if s.wait() != 0:
sys.stderr.write('Error: %s\n' % str(s.stderr.read().rstrip(),
locale.getpreferredencoding()))
sys.exit(1)
for line in s.stdout.readlines():
line = line.strip()
if line.startswith(b'librem5.img2'):
start = int(line.split()[1])
offset = start * 512
if not os.path.isdir(mount_point):
os.mkdir(mount_point)
result = os.system('mount -o offset=%i %s %s' % (
offset, shlex.quote(image), shlex.quote(mount_point)))
if result != 0:
sys.exit(1)
# Add sources to the /etc/apt/sources.list file.
file_name = os.path.join(mount_point, 'etc', 'apt', 'sources.list')
lines = []
sources = set()
for line in open(file_name).readlines():
lines.append(line)
if line.startswith('deb-src '):
sources.add(line[8:])
f = open(file_name, 'w')
for line in lines:
f.write(line)
if line.startswith('deb '):
if line[4:] not in sources:
f.write('deb-src ' + line[4:])
f.close()
# Enter the chroot and update apt.
if os.system('chroot %s apt update' % shlex.quote(mount_point)) != 0:
sys.exit(1)
print('Now run:')
print('dpkg-status-summary.py [-d] <release name> %s '
'<output directory>' % shlex.quote(mount_point))
sys.exit()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment