1#!/usr/bin/python
2# SPDX-License-Identifier: CC0-1.0
3
4import ast
5import re
6import sys
7
8def read_os_release():
9    try:
10        filename = '/etc/os-release'
11        f = open(filename)
12    except FileNotFoundError:
13        filename = '/usr/lib/os-release'
14        f = open(filename)
15
16    for line_number, line in enumerate(f, start=1):
17        line = line.rstrip()
18        if not line or line.startswith('#'):
19            continue
20        if m := re.match(r'([A-Z][A-Z_0-9]+)=(.*)', line):
21            name, val = m.groups()
22            if val and val[0] in '"\'':
23                val = ast.literal_eval(val)
24            yield name, val
25        else:
26            print(f'{filename}:{line_number}: bad line {line!r}',
27                  file=sys.stderr)
28
29os_release = dict(read_os_release())
30
31pretty_name = os_release.get('PRETTY_NAME', 'Linux')
32print(f'Running on {pretty_name!r}')
33
34if 'debian' in [os_release.get('ID', 'linux'),
35                *os_release.get('ID_LIKE', '').split()]:
36    print('Looks like Debian!')
37