forked from jensl/critic
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.py
156 lines (131 loc) · 5.42 KB
/
install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# -*- mode: python; encoding: utf-8 -*-
#
# Copyright 2012 Jens Lindström, Opera Software ASA
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
import os
import sys
import traceback
if os.getuid() != 0:
print """
ERROR: This script must be run as root.
"""
sys.exit(1)
# Python version check is done before imports below so
# that python 2.6/2.5 users can see the error message.
if sys.version_info[0] != 2 or sys.version_info[1] < 7:
print """\
Unsupported Python version! Critic requires Python 2.7.x or later,
but not Python 3.x. This script must be run in the Python interpreter
that will be used to run Critic."""
sys.exit(2)
import json
import argparse
import installation
parser = argparse.ArgumentParser(description="Critic installation script")
parser.add_argument("--etc-dir", help="directory where the Critic system configuration is stored", action="store")
parser.add_argument("--install-dir", help="directory where the Critic source code is installed", action="store")
parser.add_argument("--data-dir", help="directory where Critic's persistent data files are stored", action="store")
parser.add_argument("--cache-dir", help="directory where Critic's temporary data files are stored", action="store")
parser.add_argument("--git-dir", help="directory where the main Git repositories are stored", action="store")
parser.add_argument("--log-dir", help="directory where Critic's log files are stored", action="store")
parser.add_argument("--run-dir", help="directory where Critic's runtime files are stored", action="store")
parser.add_argument("--system-hostname", help="FQDN of the system", action="store")
parser.add_argument("--system-username", help="name of system user to run as", action="store")
parser.add_argument("--system-email", help="address used as sender of emails", action="store")
parser.add_argument("--system-groupname", help="name of system group to run as", action="store")
parser.add_argument("--auth-mode", help="user authentication mode", choices=["host", "critic"], action="store")
parser.add_argument("--session-type", help="session type", choices=["httpauth", "cookie"], action="store")
parser.add_argument("--admin-username", help="name of Critic administrator user", action="store")
parser.add_argument("--admin-email", help="email address to Critic administrator user", action="store")
parser.add_argument("--admin-fullname", help="Critic administrator user's full name", action="store")
for module in installation.modules:
if hasattr(module, "add_arguments"):
module.add_arguments("install", parser)
arguments = parser.parse_args()
def abort():
print
print "ERROR: Installation aborted."
print
for module in reversed(installation.modules):
try:
if hasattr(module, "undo"):
module.undo()
except:
print >>sys.stderr, "FAILED: %s.undo()" % module.__name__
traceback.print_exc()
sys.exit(1)
try:
try:
if not installation.prereqs.check(arguments):
abort()
except KeyboardInterrupt:
abort()
except SystemExit:
raise
except:
print >>sys.stderr, "FAILED: installation.prereqs.check()"
traceback.print_exc()
abort()
git = installation.prereqs.git
if installation.process.check_output([git, "status", "--porcelain"]).strip():
print """
ERROR: This Git repository has local modifications.
Installing from a Git repository with local changes is not supported.
Please commit or stash the changes and then try again.
"""
sys.exit(1)
sha1 = installation.process.check_output([git, "rev-parse", "HEAD"]).strip()
data = { "sha1": sha1 }
for module in installation.modules:
try:
if hasattr(module, "prepare") and not module.prepare("install", arguments, data):
abort()
except KeyboardInterrupt:
abort()
except SystemExit:
raise
except:
print >>sys.stderr, "FAILED: %s.prepare()" % module.__name__
traceback.print_exc()
abort()
print
with open(os.path.join(installation.root_dir, ".install.data"), "w") as install_data:
json.dump(data, install_data)
for module in installation.modules:
try:
if hasattr(module, "install") and not module.install(data):
abort()
except KeyboardInterrupt:
abort()
except SystemExit:
raise
except:
print >>sys.stderr, "FAILED: %s.execute()" % module.__name__
traceback.print_exc()
abort()
for module in installation.modules:
try:
if hasattr(module, "finish"):
module.finish()
except:
print >>sys.stderr, "WARNING: %s.finish() failed" % module.__name__
traceback.print_exc()
print
print "SUCCESS: Installation complete!"
print
except SystemExit:
raise
except:
traceback.print_exc()
abort()