From a940236215b234a2aa37e26ecf5a14acd2e7f539 Mon Sep 17 00:00:00 2001 From: Till Höppner Date: Sun, 1 Oct 2017 22:34:59 +0200 Subject: Add utility script to fix uid volumes for uid namespaces --- bin/offset_ids | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 bin/offset_ids 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) -- cgit v1.2.3