summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/offset_ids28
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/offset_ids b/bin/offset_ids
new file mode 100755
index 0000000..e5e1a47
--- /dev/null
+++ b/bin/offset_ids
@@ -0,0 +1,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)