wic_fakeroot 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. #
  3. # wic needs a FAKEROOT cmd to run, the default is pseudo. In Isar we do/can not
  4. # use pseudo. And we call wic as root to begin with, so this script could be a
  5. # dummy doing nothing. It is almost a dummy ...
  6. #
  7. # If the fsck hack ever becomes obsolete, FAKEROOTCMD ?= "true;" can be used
  8. #
  9. # This software is a part of Isar.
  10. # Copyright (C) 2018 Siemens AG
  11. #
  12. import os
  13. import sys
  14. import subprocess
  15. args = sys.argv
  16. args.pop(0)
  17. cmd = args[0]
  18. # expect to be running as root
  19. # we could loosen that and execv(sudo, args) but even some early
  20. # "du"s fail, which do not use the fakeroot-wrapper
  21. # i.e. in wics partition.py the "du -ks" fails on
  22. # var/cache/apt/archives/partial
  23. # rootfs/root ...
  24. assert os.geteuid() == 0, "wic_fakeroot must be run as root!"
  25. # Check if we are calling the pseudo command itself. Return 0
  26. # for standalone pseudo operations.
  27. if cmd.startswith('-'):
  28. sys.exit(0)
  29. # e2fsck <= 1.43.5 returns 1 on non-errors (stretch and before affected)
  30. # treat 1 as safe ... the filesystem was successfully repaired and is OK
  31. if cmd.startswith('fsck.'):
  32. ret = subprocess.call(args)
  33. sys.exit(0 if ret == 1 else ret)
  34. os.execvp(cmd, args)