9
change_type = os.environ.get("ENSEMBLE_CHANGE")
11
upload_path = "/var/www/wp-uploads"
12
config_file_path_template = "/etc/mediawiki/config-%s.php"
13
hostname_url = "http://169.254.169.254/latest/meta-data/public-hostname"
17
p = subprocess.Popen(args, close_fds=True)
20
mediawiki_template = """\
21
$path = array( $IP, "$IP/includes", "$IP/languages" );
22
set_include_path( implode( PATH_SEPARATOR, $path ) . PATH_SEPARATOR . get_include_path() );
24
require_once( "$IP/includes/DefaultSettings.php" );
26
# If PHP's memory limit is very low, some operations may fail.
27
# ini_set( 'memory_limit', '20M' );
29
if ( $wgCommandLineMode ) {
30
if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
31
die( "This script must be run from the command line\n" );
34
## Uncomment this to disable output compression
35
# $wgDisableOutputCompression = true;
37
$wgSitename = "Ensemblized Wiki";
39
## The URL base path to the directory containing the wiki;
40
## defaults for all runtime URL paths are based off of this.
41
## For more information on customizing the URLs please see:
42
## http://www.mediawiki.org/wiki/Manual:Short_URL
43
$wgScriptPath = "/mediawiki";
44
$wgScriptExtension = ".php";
46
## UPO means: this is also a user preference option
48
$wgEnableEmail = true;
49
$wgEnableUserEmail = true; # UPO
51
$wgEmergencyContact = "webmaster@localhost";
52
$wgPasswordSender = "webmaster@localhost";
54
$wgEnotifUserTalk = true; # UPO
55
$wgEnotifWatchlist = true; # UPO
56
$wgEmailAuthentication = true;
60
$wgDBserver = "%s(database_host)";
61
$wgDBname = "%s(database)";
62
$wgDBuser = "%s(database_user)";
63
$wgDBpassword = "%s(database_password)";
65
# MySQL specific settings
68
# MySQL table options to use during installation or update
69
$wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";
71
# Experimental charset support for MySQL 4.1/5.0.
74
## Shared memory settings
75
$wgMainCacheType = CACHE_NONE;
76
$wgMemCachedServers = array();
78
## To enable image uploads, make sure the 'images' directory
79
## is writable, then set this to true:
80
$wgEnableUploads = false;
81
$wgUseImageMagick = true;
82
$wgImageMagickConvertCommand = "/usr/bin/convert";
84
## If you use ImageMagick (or any other shell command) on a
85
## Linux server, this will need to be set to the name of an
86
## available UTF-8 locale
87
$wgShellLocale = "en_US.utf8";
89
## If you want to use image uploads under safe mode,
90
## create the directories images/archive, images/thumb and
91
## images/temp, and make them all writable. Then uncomment
92
## this, if it's not already uncommented:
93
# $wgHashedUploadDirectory = false;
95
## If you have the appropriate support software installed
96
## you can enable inline LaTeX equations:
99
$wgLocalInterwiki = strtolower( $wgSitename );
101
$wgLanguageCode = "en";
103
$wgSecretKey = "%s(secret_key)";
105
## Default skin: you can change the default skin. Use the internal symbolic
106
## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
107
$wgDefaultSkin = 'monobook';
109
## For attaching licensing metadata to pages, and displaying an
110
## appropriate copyright notice / icon. GNU Free Documentation
111
## License and Creative Commons licenses are supported so far.
112
# $wgEnableCreativeCommonsRdf = true;
113
$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
117
# $wgRightsCode = ""; # Not yet used
119
$wgDiff3 = "/usr/bin/diff3";
121
# debian specific include:
122
if (is_file("/etc/mediawiki-extensions/extensions.php")) {
123
include( "/etc/mediawiki-extensions/extensions.php" );
126
# When you make changes to this configuration file, this will make
127
# sure that cached pages are cleared.
128
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
131
adminsettings_template = """
133
$wgDBadminuser = '%s(database_admin_user)';
134
$wgDBadminpassword = '%s(database_admin_password)';
135
$wgEnableProfileInfo = false;
138
def setup_mediawiki():
140
hostname = urllib.urlopen(hostname_url).read().strip()
141
remote_unit = os.environ.get("ENSEMBLE_REMOTE_UNIT")
143
print "remote unit", remote_unit
145
# Check we haven't already been setup.
146
if os.path.exists(config_file_path_template % hostname):
147
print "Already Configured, Exiting"
150
p = subprocess.Popen(["relation-get", "--format", "json", remote_unit],
151
stdout=subprocess.PIPE, close_fds=True)
152
settings = json.loads(p.stdout.read().strip())
156
pprint.pprint(settings)
158
# Get the database settings
159
database = settings.get("database")
160
password = settings.get("password")
161
user = settings.get("user")
162
host = settings.get("host")
164
# Ensure the remote unit has self configured.
166
"database_host": host,
167
"database": database,
168
"database_password": password,
169
"database_user": user,
170
"hostname": hostname,
173
# Verify we have all of our database settings.
175
for k, v in config.items():
177
print "Do not have for %r: %r" % (k, v)
181
print "Could not fetch database settings, exiting."
184
# Write the adminsettings
185
fh = open('/etc/mediawiki/AdminSettings.php', "w")
186
do("chmod", "0644", '/etc/mediawiki/AdminSettings.php')
187
fh.write(adminsettings_template % config)
190
# Write the mediawiki config
191
fh = open('/etc/mediawiki/LocalSettings.php', "w")
192
do("chmod", "0644", '/etc/mediawiki/LocalSettings.php')
193
fh.write(mediawiki_template % config)
196
# Enable the Alias in the apache config
197
do("sed", "-ie","'s,^#Alias /mediawiki,Alias /mediawiki,' /etc/mediawiki/apache.conf")
200
do("/etc/init.d/apache2", "reload")
205
if change_type == "modified":