__init__.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """
  2. Copyright 2017 Oliver Smith
  3. This file is part of pmbootstrap.
  4. pmbootstrap is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. pmbootstrap is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
  14. """
  15. import sys
  16. import logging
  17. import os
  18. import traceback
  19. from . import config
  20. from . import parse
  21. from .config import init as config_init
  22. from .helpers import frontend
  23. from .helpers import logging as pmb_logging
  24. from .helpers import other
  25. def main():
  26. # Parse arguments, set up logging
  27. args = parse.arguments()
  28. pmb_logging.init(args)
  29. os.umask(0o22)
  30. # Wrap everything to display nice error messages
  31. try:
  32. # Sanity check
  33. other.check_grsec(args)
  34. # Initialize or require config
  35. if args.action == "init":
  36. return config_init.frontend(args)
  37. elif not os.path.exists(args.config):
  38. raise RuntimeError("Please specify a config file, or run"
  39. " 'pmbootstrap init' to generate one.")
  40. elif not os.path.exists(args.work):
  41. raise RuntimeError("Work path not found, please run 'pmbootstrap"
  42. " init' to create it.")
  43. # Migrate work folder if necessary
  44. if args.action not in ["shutdown", "zap", "log"]:
  45. other.migrate_work_folder(args)
  46. # Run the function with the action's name (in pmb/helpers/frontend.py)
  47. if args.action:
  48. getattr(frontend, args.action)(args)
  49. else:
  50. logging.info("Run pmbootstrap -h for usage information.")
  51. # Print finish timestamp
  52. logging.info("Done")
  53. except Exception as e:
  54. logging.info("ERROR: " + str(e))
  55. logging.info("Run 'pmbootstrap log' for details.")
  56. logging.info("See also: <https://postmarketos.org/troubleshooting>")
  57. logging.debug(traceback.format_exc())
  58. return 1
  59. if __name__ == "__main__":
  60. sys.exit(main())