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