summaryrefslogtreecommitdiff
path: root/bin/offset_ids
blob: e5e1a477b98c298e9e68946bb58cd96ff8278f6e (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
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python36

import pwd
import grp
import os
import sys

if len(sys.argv) != 3:
  print(f"USAGE: {sys.argv[0]} TARGET OFFSET")
  sys.exit(1)

target = sys.argv[1]
offset = int(sys.argv[2])

def adjust(path):
  stat = os.stat(path, follow_symlinks=False)
  uid = stat.st_uid
  gid = stat.st_gid
  
  print(f"{path} {uid}:{gid} => {uid + offset}:{gid + offset}")
  os.chown(path, uid + offset, gid + offset, follow_symlinks=False)

for root, dirs, files in os.walk(target):
  for d in dirs:
    adjust(root + os.sep + d)
  for f in files:
    adjust(root + os.sep + f)