-
Notifications
You must be signed in to change notification settings - Fork 5
/
cherokee-wizard
executable file
·144 lines (113 loc) · 3.31 KB
/
cherokee-wizard
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
#!/usr/bin/env python
# -*- coding: utf-8; mode: python -*-
#
# Cherokee-admin
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
import os
import sys
import CTK
import Wizard2
import Install_Log
import server
USAGE = \
"Usage:\n" \
" cherokee-wizard install WIZARD config=PATH [option=<something>]\n" \
"\n" \
"Report bugs to http://bugs.cherokee-project.com\n"
# ANSI Colors
#
ESC = chr(27) + '['
RESET = '%s0m' %(ESC)
def green (s): return ESC + '0;32m' + s + RESET
def red (s): return ESC + '0;31m' + s + RESET
def yellow (s): return ESC + '1;33m' + s + RESET
def blue (s): return ESC + '0;34m' + s + RESET
# Util
#
def print_error (msg, severity="ERROR"):
sys.stdout.write ("%s: %s\n" %(red(severity), msg))
sys.stdout.flush ()
# Installer
#
def install (wizard_path, params):
# Log
Install_Log.only_print = True
# Load the module
mod = Wizard2.Load_Module (wizard_path)
if not mod:
print_error ("Could not load '%s'" %(wizard_path))
return 1
# Launch the wizard
installer = mod.Install (params.copy())
# Go through all the installation phases
for phase in (installer.Check_Parameters,
installer.Check_Prerequisites,
installer.Download,
installer.Unpack,
installer.Check_PostUnpack,
installer.Configure_Cherokee,
installer.Configure_Cherokee_PostApply):
errors = phase()
if errors:
for err in set(errors):
print_error (err)
return 1
print yellow("ok")
# Save the config
CTK.cfg.save()
def help():
print USAGE
return 1
def main():
# Check paramaters
if len(sys.argv) < 3:
return help()
if sys.argv[1] != 'install':
return help()
# Process parameters
wizard = sys.argv[2]
params = {}
for p in sys.argv:
if '=' in p:
tmp = p.split('=')
val = tmp[1]
if val[0] in ['"', "'"] and val[-1] in ['"', "'"]:
val = val[1:-1]
params[tmp[0]] = val
# Read config file
if not 'config' in params:
return help()
config_file = params['config']
if not os.path.exists(config_file):
open (config_file, "w+").write (server.DEFAULT_EMPTY_CONFIG)
CTK.init()
CTK.cfg.file = params['config']
CTK.cfg.load()
# Install
return install (wizard, params)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print
print "Exiting now.."
os._exit(1)