Commit 5525d367 authored by Simon McVittie's avatar Simon McVittie
Browse files

set-build-id: Populate /etc/debian_chroot



This file is read by the default /etc/bash.bashrc in Debian and
included as a prefix to the prompt, in this style:

    (contents of /etc/debian_chroot) user@host:~$

It is automatically populated with the chroot name by schroot, but not
by other container tools like Docker and Flatpak. We might as well
give it a useful value for all Flatdeb-generated containers.
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent a55fa077
......@@ -172,5 +172,6 @@ actions:
etc/apt/apt.conf.d/*
etc/apt/sources.list
etc/apt/sources.list.d/*
etc/debian_chroot
usr/lib/os-release
|| true
......@@ -333,6 +333,7 @@ actions:
files/etc/apt/apt.conf.d/*
files/etc/apt/sources.list
files/etc/apt/sources.list.d/*
files/etc/debian_chroot
files/lib/os-release
src/files/MISSING.txt
metadata
......
......@@ -109,6 +109,10 @@ def main():
return
os_id = ''
version_codename = ''
version_id = ''
with open(
os.path.join(args.sysroot, 'usr', 'lib', 'os-release'),
'r',
......@@ -119,6 +123,24 @@ def main():
else:
logger.info('%s', line.strip())
lines.append(line)
value = line.split('=', 1)[1].strip()
if value[0] == '"':
assert value.endswith('"'), value
value = value[1:-1]
# Unescape \\, \", \$, \`. The string can't contain \n
# so we can use \n as a placeholder for a literal backslash.
value = value.replace('\\\\', '\n')
value = value.replace('\\', '')
value = value.replace('\n', '\\')
if line.startswith('ID='):
os_id = value
elif line.startswith('VERSION_CODENAME='):
version_codename = value
elif line.startswith('VERSION_ID='):
version_id = value
if args.build_id:
logger.info('Adding BUILD_ID=%s', quote(args.build_id))
......@@ -143,6 +165,50 @@ def main():
os.path.join(args.sysroot, 'usr', 'lib', 'os-release'),
)
if version_codename:
# e.g. buster, leading to (buster) user@host:~$
chroot_name = version_codename
elif version_id:
# e.g. 10, leading to (10) user@host:~$
chroot_name = version_id
else:
chroot_name = ''
# We use the OS ID instead of the human-readable NAME because we want
# something short.
if os_id:
if chroot_name:
# e.g. leading to (debian buster) user@host:~$
# or (debian 10) user@host:~$
chroot_name = '{} {}'.format(os_id, chroot_name)
else:
# e.g. (debian) user@host:~$
chroot_name = os_id
if args.build_id:
if chroot_name:
# e.g. (debian buster 20190603) user@host:~$
chroot_name = '{} {}'.format(chroot_name, args.build_id)
else:
# e.g. (20190603) user@host:~$
chroot_name = args.build_id
if chroot_name:
logger.info('Setting debian_chroot to %r', chroot_name)
with open(
os.path.join(args.sysroot, 'etc', 'debian_chroot.new'),
'w',
) as writer:
writer.write(chroot_name + '\n')
else:
logger.info('Not setting debian_chroot')
os.rename(
os.path.join(args.sysroot, 'etc', 'debian_chroot.new'),
os.path.join(args.sysroot, 'etc', 'debian_chroot'),
)
if __name__ == '__main__':
if sys.stderr.isatty():
......
Markdown is supported
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