def main(): parser = argparse.ArgumentParser(description="Display Manager setup service for the Optimus Manager tool.\n" "https://github.com/Askannz/optimus-manager") parser.add_argument('--setup-boot', action='store_true') parser.add_argument('--setup-prime', action='store_true') parser.add_argument('--setup-gpu', action='store_true') args = parser.parse_args() _print_timestamp_separator() print("Optimus Manager (Setup script) version %s" % envs.VERSION) if args.setup_boot: print("Setting up boot") if is_xorg_running(): print("Error : attempting to run the initial boot setup while a X server is already running !" " Skipping initial GPU setup.") sys.exit(0) # We always clean autogenerated files before doing anything else, just in case the script crashes later on. print("Cleaning up leftover Xorg conf") cleanup_xorg_conf() print("Loading config") config = _get_config() print("Reading startup mode") startup_mode = _get_startup_mode() print("Startup mode is : %s" % startup_mode) print("Writing startup mode to requested GPU mode") _write_gpu_mode(config, startup_mode) print("Initial GPU setup") _setup_gpu(config, startup_mode) elif args.setup_prime: print("Setting up PRIME") print("Loading config") config = _get_config() _setup_PRIME() _set_DPI(config) elif args.setup_gpu: print("Setting up the GPU") print("Cleaning up leftover Xorg conf") cleanup_xorg_conf() print("Loading config") config = _get_config() requested_mode = _get_requested_mode() print("Requested mode :", requested_mode) _setup_gpu(config, requested_mode)
def _cleanup_xorg_and_exit(): if os.geteuid() != 0: print("You need to execute the command as root for this action.") sys.exit(1) cleanup_xorg_conf() sys.exit(0)
def handler(self, signum, frame): print("\nProcess stop requested") print("Closing and removing the socket...") self.server_socket.close() os.remove(envs.SOCKET_PATH) print("Cleaning up Xorg conf...") cleanup_xorg_conf() print("Goodbye !") sys.exit(0)
def _setup_gpu(config, requested_mode): _kill_gdm_server() try: setup_kernel_state(config, requested_mode) configure_xorg(config, requested_mode) except KernelSetupError as e: print("Cannot setup GPU : kernel setup error : %s" % str(e)) sys.exit(1) except XorgSetupError as e: print("Cannot setup GPU : Xorg setup error : %s" % str(e)) print("Cleaning up Xorg config and exiting.") cleanup_xorg_conf() sys.exit(1)