1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | import os |
---|
4 | import sys |
---|
5 | |
---|
6 | default_location = "/usr/local/sh" |
---|
7 | downloads = { |
---|
8 | "locsat": "ftp://ftp.szgrf.bgr.de/pub/software/locsat-linux.tar.gz", |
---|
9 | "fk": "ftp://ftp.szgrf.bgr.de/pub/software/fk-linux.tar.gz" |
---|
10 | } |
---|
11 | |
---|
12 | def fetchinfo(**kwargs): |
---|
13 | """ |
---|
14 | Fetch information about user etc. |
---|
15 | """ |
---|
16 | dbg = kwargs["debug"] |
---|
17 | |
---|
18 | home = os.getenv("HOME") |
---|
19 | pwd = os.path.realpath(os.path.split(sys.argv[0])[0]) |
---|
20 | tmp = os.getenv("TEMP") |
---|
21 | if not tmp: |
---|
22 | tmp = pwd |
---|
23 | |
---|
24 | uid = os.getuid() |
---|
25 | root = uid == 0 |
---|
26 | if root: |
---|
27 | shcroot = default_location |
---|
28 | else: |
---|
29 | shcroot = os.path.join(home, "sh") |
---|
30 | |
---|
31 | del kwargs |
---|
32 | return locals() |
---|
33 | |
---|
34 | def banner(): |
---|
35 | print "="*78 |
---|
36 | print " Setup program for Seismic Handler v0.1" |
---|
37 | print "="*78 |
---|
38 | print "\n This piece of software will try to setup the included source code.\n" |
---|
39 | |
---|
40 | def download(pkg): |
---|
41 | os.system("wget") |
---|
42 | |
---|
43 | def setup(**kwargs): |
---|
44 | """ |
---|
45 | Setup Seismic Handler from source. |
---|
46 | """ |
---|
47 | banner() |
---|
48 | dbg = kwargs["debug"] |
---|
49 | |
---|
50 | data = fetchinfo(debug=dbg) |
---|
51 | if dbg: |
---|
52 | print data |
---|
53 | |
---|
54 | if not data["root"]: |
---|
55 | res = query("You have no administrative rights. " |
---|
56 | "Perform user installation [Yn]? ") |
---|
57 | if res.lower() == "n": |
---|
58 | abort() |
---|
59 | |
---|
60 | while 1: |
---|
61 | target = query("Installation directory [%s, q = exit]: " % data["shcroot"]) |
---|
62 | if target.lower() == "q": |
---|
63 | abort() |
---|
64 | |
---|
65 | if not target: |
---|
66 | target = data["shcroot"] |
---|
67 | |
---|
68 | if not os.path.exists(target): |
---|
69 | try: |
---|
70 | os.mkdir(target) |
---|
71 | except Exception, e: |
---|
72 | if dbg: |
---|
73 | print e |
---|
74 | |
---|
75 | print "Cannot create target directory: %s" % target |
---|
76 | continue |
---|
77 | |
---|
78 | break |
---|
79 | |
---|
80 | copy(os.path.join(data["pwd"], ".."), target, dbg) |
---|
81 | |
---|
82 | def copy(src, trt, dbg=False): |
---|
83 | if dbg: |
---|
84 | os.system("echo cp -rvd %s %s" % (src, trt)) |
---|
85 | else: |
---|
86 | os.system("cp -rd %s %s" % (src, trt)) |
---|
87 | |
---|
88 | def abort(text=None): |
---|
89 | if not text: |
---|
90 | text = "Installation aborted by user." |
---|
91 | |
---|
92 | quit(text) |
---|
93 | |
---|
94 | def query(text): |
---|
95 | """ |
---|
96 | Query user. |
---|
97 | """ |
---|
98 | return raw_input(text) |
---|
99 | |
---|
100 | |
---|
101 | if __name__ == "__main__": |
---|
102 | from optparse import OptionParser |
---|
103 | parser = OptionParser() |
---|
104 | parser.add_option("--debug", dest="debug", action="store_true", |
---|
105 | help="Turn on debug option.", default=False) |
---|
106 | |
---|
107 | (options, args) = parser.parse_args() |
---|
108 | |
---|
109 | setup(**vars(options)) |
---|