annotate users/users.py @ 326:5b88b38f2471

huge reorg, reog toplevel functions in preparation of a ui with nice task lists
author drewp@bigasterisk.com
date Mon, 20 Jan 2025 21:55:08 -0800
parents users.py@b3acb9fff274
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
1 from pyinfra.context import host
0
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
2 from pyinfra.operations import server
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
3
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
4
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
5 def setupUsers():
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
6 # raspbian took 1000 for 'pi' group, but drewp is rarely used on pi
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
7 # setups so hopefully it won't matter much that drew group has a
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
8 # different id.
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
9 drewp_uid, drewp_gid = host.data.drewp_uid, host.data.drewp_gid
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
10 drewp_groups = [
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
11 'lp', 'adm', 'dialout', 'cdrom', 'sudo', 'audio', 'video', 'plugdev', 'games', 'users', 'netdev', 'i2c', 'input', 'spi',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
12 'gpio', 'fuse', 'render', 'mongodb', 'lpadmin'
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
13 ]
0
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
14
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
15 svcIds = 1050
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
16 for svc in [
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
17 # only append to this list:
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
18 "photoprism",
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
19 "mongodb",
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
20 ]:
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
21 server.group(group=svc, gid=svcIds)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
22 server.user(user=svc, uid=svcIds, group=svc)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
23 svcIds += 1
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
24
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
25 # the following gets scrambled on new rpi. Run "useradd -u 1501 drewp" as workaround.
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
26 server.group(group='drewp', gid=drewp_gid)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
27 # this won't change existing drewp uid; I've been doing that myself.
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
28 server.user(user='drewp', uid=drewp_uid, group='drewp', groups=drewp_groups)
0
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
29
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
30 if 'pi' not in host.groups:
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
31
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
32 server.user(user='drewp', uid=drewp_uid, group='drewp', groups=drewp_groups)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
33
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
34 for name, uid, gid in [
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
35 ('ari', 3019, 3019),
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
36 ('talia', 1003, 1003),
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
37 ]:
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
38 server.group(group=name, gid=gid)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
39 server.user(user=name, uid=uid, group=name, groups=['audio', 'dialout', 'docker', 'lp', 'lpadmin', 'sudo', 'video'])
171
5565e4c907aa add drewp groups; fix logic err
drewp@bigasterisk.com
parents: 168
diff changeset
40
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
41 server.user(user='dmcc', uid=1013)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
42
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
43 server.group(group='elastic', gid=3018)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
44 server.user(user='elastic', uid=3018, group='elastic')
0
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
45
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
46 server.group(group='kelsi', gid=1008)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
47 server.user(user='kelsi', uid=1008, group='elastic')
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
48
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
49 server.group(group='drewnote', gid=1009)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
50 server.user(user='drewnote', uid=1009)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
51
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
52 server.group(group='prometheus', gid=1010)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
53 server.user(user='prometheus', uid=1010)
0
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
54
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
55
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
56 def systemGroups():
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
57 for group in [
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
58 'fuse',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
59 'spi',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
60 'gpio',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
61 'i2c',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
62 'input',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
63 'netdev',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
64 'render',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
65 'lpadmin',
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
66 ]:
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
67 server.group(group=group, system=True)
0
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
68
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
69 if 'pi' not in host.groups:
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
70 server.group(group='adm', gid=4)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
71 server.group(group='cdrom', gid=24)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
72 server.group(group='dialout', gid=20)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
73 server.group(group='dip', gid=30)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
74 server.group(group='lp', gid=7)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
75 # prime has something on 109
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
76 server.group(group='lpadmin', gid=200)
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
77 server.group(group='plugdev', gid=46)
0
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
78
1550a6db59b3 first ported section from ansible. shorter, faster, clearer.
drewp@bigasterisk.com
parents:
diff changeset
79
326
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
80 operations = [
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
81 systemGroups,
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
82 setupUsers,
5b88b38f2471 huge reorg, reog toplevel functions in preparation of a ui with nice task lists
drewp@bigasterisk.com
parents: 313
diff changeset
83 ]