From 4cd22cb86e94c6bb4731d0fb876d7c5637037d22 Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Mon, 8 Nov 2010 19:40:49 +0100 Subject: [PATCH] don't rely on update-alternatives --- grml-x | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/grml-x b/grml-x index 64d910e..6874c92 100755 --- a/grml-x +++ b/grml-x @@ -9,7 +9,7 @@ # License: This file is licensed under the GPL v2. ############################################################################### -import os, subprocess, sys, tempfile, time, traceback +import fileinput, os, subprocess, sys, tempfile, time, traceback from optparse import OptionParser class Section(object): @@ -160,20 +160,36 @@ def main(): for depth in [8, 15, 16, 24, 32]: screen.subsect += "SubSection \"Display\"\n\tDepth %d\n\tModes \"%s\"\t\nEndSubSection\n" % (depth, options.mode) - if len(args) == 1: - window_manager = args[0] - wm_path = which(window_manager) - if not wm_path: - print "E: Cannot find window manager %r, aborting." % window_manager - return 2 - run_program(["sudo", "update-alternatives", "--set", "x-window-manager", wm_path]) - - config_empty = True - if monitor or device or len(screen.data) > 0 or screen.subsect != '': - config_empty = False + xinitrc = '~/.xinitrc' + if 'XINITRC' in os.environ: xinitrc = os.environ['XINITRC'] + xinitrc = os.path.expanduser(xinitrc) + + window_manager = 'x-window-manager' + if len(args) == 1: window_manager = args[0] + window_manager_path = which(window_manager) + if not window_manager_path: + print "E: Cannot find window manager %r, aborting." % window_manager + return 2 + + wm_exec = "exec %s\n" % window_manager_path + if not os.path.exists(xinitrc): + f = open(xinitrc, 'w') + f.write("#!/bin/sh\n") + f.write(wm_exec) + f.close() + else: + f = open(xinitrc, 'r') + lines = f.readlines() + f.close() + f = open(xinitrc, 'w') + for line in lines: + if line.startswith('exec '): line = wm_exec + f.write(line) + os.fchmod(f.fileno(), 0750) + f.close() # write new config - if not config_empty: + if monitor or device or len(screen.data) > 0 or screen.subsect != '': try: f = tempfile.NamedTemporaryFile(delete=False) f.write('# Automatically generated by grml-x.\n') @@ -187,15 +203,7 @@ def main(): f.close() if options.start_server: - xinitrc = '~/.xinitrc' - if 'XINITRC' in os.environ: xinitrc = os.environ['XINITRC'] - xinitrc = os.path.expanduser(xinitrc) - startx = ['startx'] - if os.path.exists(xinitrc): - startx.append(xinitrc) - else: - startx.append(which('x-window-manager')) - startx.append('--') + startx = ['startx', xinitrc, '--'] if options.display: startx.append(':' + options.display) print "Starting X: %r" % startx run_program(startx) -- 2.1.4