Commit 5c43c8b7 authored by David Boddie's avatar David Boddie 💬
Browse files

Refactored a function.

Changed the fdisk output handling to search for the image file name
rather than a hard-coded string.
parent 4de929c5
Pipeline #59479 passed with stage
in 59 seconds
......@@ -12,16 +12,47 @@ import subprocess
import sys
def add_sources_and_update(mount_point):
# 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)
if __name__ == '__main__':
if len(sys.argv) != 3:
sys.stderr.write('Usage: %s <librem5.img disk image> '
sys.stderr.write('Usage: %s <Librem 5 disk image> '
'<mount point>\n' % sys.argv[0])
sys.exit(1)
image = sys.argv[1]
mount_point = sys.argv[2]
name = image.encode(locale.getpreferredencoding())
s = subprocess.Popen(['fdisk', '--units=sectors', '-l', shlex.quote(image)],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if s.wait() != 0:
......@@ -31,7 +62,7 @@ if __name__ == '__main__':
for line in s.stdout.readlines():
line = line.strip()
if line.startswith(b'librem5.img2'):
if line.startswith(name + b'2'):
start = int(line.split()[1])
offset = start * 512
......@@ -45,31 +76,10 @@ if __name__ == '__main__':
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)
# Add source lines to the /etc/apt/sources.list file in the chroot and
# update it. We may be able to fetch Sources.xz files for each of the
# suites from the server and inspect those instead.
add_sources_and_update(mount_point)
print('Now run:')
print('dpkg-status-summary.py [-d] <release name> %s '
......
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