3 # This script exports environment variables from the file specified in
4 # the ENVFILE argument and then executes the specified command.
6 # If any environment variables from ENVFILE are already set in the
7 # current environment, those are *not* overwritten, so environment
8 # variables set by the caller take precedence over the ones from ENVFILE.
10 # ENVFILE must be null-terminated.
14 from pathlib import Path
16 usage = f"{sys.argv[0]} ENVFILE [--] COMMAND [ARG...]"
19 def read_envfile(envfile: str) -> dict:
20 env = dict(os.environ)
21 for line in Path(envfile).read_text().split('\0'):
24 key, value = line.split("=", 1)
31 if os.geteuid() != 1000:
32 print(f"{sys.argv[0]: This script must be run as amnesia}", file=sys.stderr)
36 print(usage, file=sys.stderr)
39 if sys.argv[2] == "--":
42 env = read_envfile(sys.argv[1])
45 os.execvpe(file, args, env=env)
48 if __name__ == "__main__":