~jmarsden/ubiquity/lp775124

« back to all changes in this revision

Viewing changes to bin/ubiquity-wrapper

  • Committer: Colin Watson
  • Date: 2006-12-19 11:02:24 UTC
  • Revision ID: colin.watson@canonical.com-20061219110224-azyc5l1sg6yxxmnh
* Move the ubiquity executable proper into /usr/lib/ubiquity/bin, and add
  a /usr/bin/ubiquity wrapper that calls gksudo, kdesu, etc. as
  appropriate. This makes argument handling more straightforward and
  reduces the need for strange environment variables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
# Wrapper script to run Ubiquity as root using the appropriate privilege
 
4
# escalation method for the frontend.
 
5
 
 
6
import sys
 
7
import os
 
8
 
 
9
def main():
 
10
    newargv = []
 
11
    desktop = None
 
12
    frontend = None
 
13
    toexec = []
 
14
 
 
15
    i = 1
 
16
    while i < len(sys.argv):
 
17
        if sys.argv[i] == '--desktop':
 
18
            desktop = sys.argv[i + 1]
 
19
            i += 2
 
20
            # strip option and argument from newargv
 
21
            continue
 
22
        elif not sys.argv[i].startswith('-'):
 
23
            frontend = sys.argv[i]
 
24
        newargv.append(sys.argv[i])
 
25
        i += 1
 
26
 
 
27
    if os.getuid() == 0:
 
28
        # no privilege escalation required
 
29
        pass
 
30
    else:
 
31
        if frontend is None:
 
32
            # Try to detect which frontend will be used by looking for a
 
33
            # frontend module.
 
34
            import imp
 
35
            import ubiquity.frontend
 
36
            frontend_names = ['gtkui', 'kde-ui']
 
37
            for f in frontend_names:
 
38
                try:
 
39
                    imp.find_module(f, ubiquity.frontend.__path__)
 
40
                    frontend = f
 
41
                    break
 
42
                except ImportError:
 
43
                    pass
 
44
 
 
45
        if frontend == 'gtkui':
 
46
            toexec = ['gksudo']
 
47
            if desktop:
 
48
                toexec.extend(['--desktop', desktop])
 
49
            toexec.append('--')
 
50
        elif frontend == 'kde-ui':
 
51
            toexec = ['kdesu', '--nonewdcop', '--']
 
52
        else:
 
53
            toexec = ['sudo']
 
54
 
 
55
    toexec.append('/usr/lib/ubiquity/bin/ubiquity')
 
56
    toexec.extend(newargv)
 
57
 
 
58
    if 'UBIQUITY_WRAPPER_DEBUG' in os.environ:
 
59
        print >>sys.stderr, toexec
 
60
    os.execvp(toexec[0], toexec)
 
61
    sys.exit(127)
 
62
 
 
63
if __name__ == '__main__':
 
64
    main()