summaryrefslogtreecommitdiff
path: root/machine_profiles
blob: 79daf4bbb1006c484b459430b3d62ffd9b57aa42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python3

# print a comma-separate list of tags for system

import socket
import sys

tags = {
    "desktop" : [
        "daenerys",
        "games.daenerys",
        "shion",
        "diziet",
        "cirno",
    ],
}

hostname = socket.getfqdn()
if hostname.startswith('localhost'):
    # try gethostname, it might sometimes return a real name
    # when FQDN is misconfigured
    hostname = socket.gethostname()

if hostname.startswith('localhost'):
    sys.stderr.write('System hostname "%s" starts with localhost, '
                     'that is probably wrong\n', hostname)

for t, systems in tags.items():
    for s in systems:
        if (hostname.startswith(s) and
            (len(s) == len(hostname) or hostname[len(s)] == '.')):
            print(t)
            break