summaryrefslogtreecommitdiff
path: root/meson_post_install.py
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-07-15 12:36:05 +0000
committerJan Rybar <jrybar@redhat.com>2021-07-15 12:36:05 +0000
commit6c8022392713955c5ae0061e22b50a16a1c2252a (patch)
tree60e4dde232580799fe84c3d6bcdb3ec35ff18e1e /meson_post_install.py
parent025f9a6ba374c77c67f104ed5a4c04a057cc8084 (diff)
downloadpolkit-6c8022392713955c5ae0061e22b50a16a1c2252a.tar.gz
Improve meson_post_install script
Diffstat (limited to 'meson_post_install.py')
-rw-r--r--meson_post_install.py58
1 files changed, 48 insertions, 10 deletions
diff --git a/meson_post_install.py b/meson_post_install.py
index 0a0fccf..0ab7469 100644
--- a/meson_post_install.py
+++ b/meson_post_install.py
@@ -1,20 +1,44 @@
#!/usr/bin/env python3
-import getpass
import os
import pwd
import sys
+destdir = os.environ.get('DESTDIR')
prefix = os.environ['MESON_INSTALL_DESTDIR_PREFIX']
-bindir = os.path.join(prefix, sys.argv[1])
-pkgdatadir = os.path.join(prefix, sys.argv[2])
-pkglibdir = os.path.join(prefix, sys.argv[3])
-pkgsysconfdir = os.path.join(prefix, sys.argv[4])
+def destdir_path(p):
+ if os.path.isabs(p):
+ if destdir is None:
+ return p
+ else:
+ return os.path.join(destdir, os.path.relpath(p, '/'))
+ else:
+ return os.path.join(prefix, p)
-polkitd_uid = pwd.getpwnam(sys.argv[5]).pw_uid
+bindir = destdir_path(sys.argv[1])
+pkgdatadir = destdir_path(sys.argv[2])
+pkglibdir = destdir_path(sys.argv[3])
+pkgsysconfdir = destdir_path(sys.argv[4])
+polkitd_user = sys.argv[5]
-os.chmod(os.path.join(bindir, 'pkexec'), 0o4775)
+try:
+ polkitd_uid = pwd.getpwnam(polkitd_user).pw_uid
+except KeyError:
+ polkitd_uid = None
+
+dst = os.path.join(bindir, 'pkexec')
+
+if os.geteuid() == 0:
+ os.chmod(dst, 0o4755)
+ os.chown(dst, 0, -1)
+else:
+ print(
+ 'Owner and mode of {} need to be setuid root (04755) after '
+ 'installation'.format(
+ dst,
+ )
+ )
dst_dirs = [
os.path.join(pkgsysconfdir, 'rules.d'),
@@ -24,13 +48,27 @@ dst_dirs = [
for dst in dst_dirs:
if not os.path.exists(dst):
os.makedirs(dst, mode=0o700)
- if getpass.getuser() == "root":
+ if os.geteuid() == 0 and polkitd_uid is not None:
os.chown(dst, polkitd_uid, -1)
+ else:
+ print(
+ 'Owner of {} needs to be set to {} after installation'.format(
+ dst, polkitd_user,
+ )
+ )
# polkit-agent-helper-1 need to be setuid root because it's used to
# authenticate not only the invoking user, but possibly also root
# and/or other users.
dst = os.path.join(pkglibdir, 'polkit-agent-helper-1')
-os.chmod(dst, 0o4755)
-if getpass.getuser() == "root":
+
+if os.geteuid() == 0:
+ os.chmod(dst, 0o4755)
os.chown(dst, 0, -1)
+else:
+ print(
+ 'Owner and mode of {} need to be setuid root (04755) after '
+ 'installation'.format(
+ dst,
+ )
+ )