blob: f8ae84b8b3f733ff3b0c64fa473a02217af7429f [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001#!/usr/bin/env python3
2#
3# Wrapper around 'chgrp' that redirects to root in all cases
4
5import os
6import shutil
7import sys
8
9# calculate path to the real 'chgrp'
10path = os.environ['PATH']
11path = path.replace(os.path.dirname(sys.argv[0]), '')
12real_chgrp = shutil.which('chgrp', path=path)
13
14args = list()
15
16found = False
Andrew Geissler5082cc72023-09-11 08:41:39 -040017
18args.append(real_chgrp)
19
20for i in sys.argv[1:]:
Andrew Geissler595f6302022-01-24 19:11:47 +000021 if i.startswith("-"):
22 args.append(i)
23 continue
24 if not found:
25 args.append("root")
26 found = True
27 else:
28 args.append(i)
29
30os.execv(real_chgrp, args)