Difference between revisions of "Anarchopedia:en:administration/generatevhostscript"
From Anarchopedia
(Replacing page with 'nn') |
m (Reverted edits by 64.247.69.74 (Talk) to last version by Millosh) |
||
| Line 1: | Line 1: | ||
| − | + | (I am writting code here, so it is not done yet.) | |
| + | |||
| + | There are two scripts: (1) Before MediaWiki initialization and (2) After MediaWiki initialization. (There is no need for automatization because we are not IANA :) ) | ||
| + | |||
| + | ==Before MediaWiki initialization:== | ||
| + | |||
| + | Program shoud be started as "./program.pl | sh". | ||
| + | |||
| + | #!/usr/bin/perl -w | ||
| + | |||
| + | # Some parameters: | ||
| + | $conf_available_dir = ""; | ||
| + | $conf_enabled_dir = ""; | ||
| + | $vhostroot = ""; | ||
| + | $serveradmin = ""; | ||
| + | $serveruser = ""; | ||
| + | $servergroup = ""; | ||
| + | $mediawikisource = ""; | ||
| + | $mediawikipatch = ""; | ||
| + | $reloadapachecmd = ""; | ||
| + | $default_config = $conf_available_dir . '/template-org.anarchopedia.lang.template'; | ||
| + | die "No default config, no new Anarchopedia!" if (!(-f $default_config)); | ||
| + | die "No vhostroot dir, no new Anarchopedia!" if (!(-d $vhostroot)); | ||
| + | die "No MediaWiki, no new Anarchopedia!" if (!(-d $mediawikisource)); | ||
| + | system "mkdir " . $vhostroot . "/langs" if (!(-d "$vhostroot/langs")); | ||
| + | |||
| + | # We are getting three letter language code and two letter language code from ARGV. | ||
| + | die "No language codes, no new Anarchopedia!" if (!($ARGV[0]) || !($ARGV[1])); | ||
| + | $lng = $ARGV[0]; | ||
| + | $lg = $ARGV[1]; | ||
| + | $lang_config = $conf_available_dir . '/org.anarchopedia.' . $lng . '.conf'; | ||
| + | |||
| + | # Translating LANGUAGE and LANG to real codes | ||
| + | $httpdconf = `cat $default_config`; | ||
| + | $httpdconf =~ s#LANGUAGE#$lng#g; | ||
| + | $httpdconf =~ s#LANG2#$lg#g; | ||
| + | |||
| + | # Translating VHOSTROOT into real virtual host root | ||
| + | $httpdconf = s#VHOSTROOT#$vhostroot#g; | ||
| + | |||
| + | # Who is server admin? | ||
| + | $httpdconf = s#SERVERADMIN#$serveradmin#g; | ||
| + | |||
| + | # Commenting RewriteRule and RewriteCond for initialization. | ||
| + | $httpdconf =~ s/RewriteRule/# RewriteRule/g; | ||
| + | $httpdconf =~ s/RewriteCond/# RewriteCond/g; | ||
| + | |||
| + | # Copying MediaWiki source | ||
| + | $htdocsdir = $vhostroot . "langs/" . $lng . "\""; | ||
| + | $cgibindir = $vhostroot . "cgi-bin/" . $lng . "\""; | ||
| + | print "cp -a " . $mediawikisource . ' "' . $htdocsdir . '"'; | ||
| + | |||
| + | # Copying MediaWiki patch | ||
| + | print "cp -a " . $mediawikipatch . '/* "' . $htdocsdir . '"'; | ||
| + | |||
| + | # Creating some directories and chowning them | ||
| + | print "mkdir -p \"" . $cgibindir . "\""; | ||
| + | print "chown -R" . $serveruser . '.' . $servergroup . '"' . $htdocsdir . '" "' . $cgibindir . '"'; | ||
| + | |||
| + | # Putting httpdconf and reloading Apache | ||
| + | open ("CONFIG", "> $lang_config"); | ||
| + | print CONFIG $httpdconf; | ||
| + | close (CONFIG); | ||
| + | print "ln -s \"" . $lang_config . "\" \"" . $conf_enabled_dir . "\""; | ||
| + | print $reloadapachecmd; | ||
| + | |||
| + | ==MediaWiki initialization== | ||
| + | |||
| + | ==After MediaWiki initialization== | ||
| + | |||
| + | #!/usr/bin/perl -w | ||
| + | |||
| + | # Some parameters: | ||
| + | $conf_available_dir = ""; | ||
| + | $vhostroot = ""; | ||
| + | $serveruser = ""; | ||
| + | $servergroup = ""; | ||
| + | $reloadapachecmd = ""; | ||
| + | $langfile = ""; | ||
| + | $sqlfile = ""; | ||
| + | $database = ""; | ||
| + | $dbuser = ""; | ||
| + | $dbpass = ""; | ||
| + | die "No vhostroot dir, no new Anarchopedia!" if (!(-d $vhostroot)); | ||
| + | die "No MediaWiki, no new Anarchopedia!" if (!(-d $mediawikisource)); | ||
| + | |||
| + | # We are getting three letter language code and two letter language code from ARGV. | ||
| + | die "No language codes, no new Anarchopedia!" if (!($ARGV[0]) || !($ARGV[1])); | ||
| + | $lng = $ARGV[0]; | ||
| + | $lg = $ARGV[1]; | ||
| + | $lang_config = $conf_available_dir . '/org.anarchopedia.' . $lng . '.conf'; | ||
| + | die "No config, no new Anarchopedia!" if (!(-f $lang_config)); | ||
| + | |||
| + | # We need configuration: | ||
| + | $httpdconf = `cat $lang_config`; | ||
| + | |||
| + | # Removing commets before RewriteRule and RewriteCond. | ||
| + | $httpdconf =~ s/# RewriteRule/RewriteRule/g; | ||
| + | $httpdconf =~ s/# RewriteCond/RewriteCond/g; | ||
| + | |||
| + | # Putting httpdconf and reloading Apache | ||
| + | open ("CONFIG", "> $lang_config"); | ||
| + | print CONFIG $httpdconf; | ||
| + | close (CONFIG); | ||
| + | print "ln -s \"" . $lang_config . "\" \"" . $conf_enabled_dir . "\""; | ||
| + | print $reloadapachecmd; | ||
| + | |||
| + | ### LocalSetting.php | ||
| + | $old_localsettings = $vhostroot . '/langs/' . $lng . '/config/LocalSettings.php'; | ||
| + | $localsettings = $vhostroot . '/langs/' . $lng . '/LocalSettings.php'; | ||
| + | $datals = `cat $old_localsettings`; | ||
| + | # Changing $wgScript from $wgScriptPath/index.php to $wgScriptPath; | ||
| + | $datals =~ s/\n\$wgScript/\n\$wgScript = \$wgScriptPath;\n#\$wgScript/; | ||
| + | # ... | ||
| + | # ... | ||
| + | # ... | ||
| + | # Removig the old file | ||
| + | system "rm " . $old_localsettings; | ||
| + | # Writting new file | ||
| + | open (IN, "> $localsettings"); | ||
| + | print IN $datals; | ||
| + | close (IN); | ||
| + | |||
| + | # Including new language into interwiki tables of other languages. | ||
| + | ## The form of language code is: | ||
| + | ### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LNG_CODE###','###LNGSITE###/$1',1);" | \ | ||
| + | ### mysql -u <username> -p <password> <database_existing_language1> | ||
| + | ### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LG_CODE###','###LNGSITE###/$1',1);" | \ | ||
| + | ### mysql -u <username> -p <password> <database_existing_language1> | ||
| + | ### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LNG_CODE###','###LNGSITE###/$1',1);" | \ | ||
| + | ### mysql -u <username> -p <password> <database_existing_language2> | ||
| + | ### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LG_CODE###','###LNGSITE###/$1',1);" | \ | ||
| + | ### mysql -u <username> -p <password> <database_existing_language2> | ||
| + | ### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LNG_CODE###','###LNGSITE###/$1',1);" | \ | ||
| + | ### mysql -u <username> -p <password> <database_existing_languageN> | ||
| + | ### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LG_CODE###','###LANGSITE###/$1',1);" | \ | ||
| + | ### mysql -u <username> -p <password> <database_existing_languageN> | ||
| + | if (-e $langfile) { | ||
| + | $langdata = `cat $langfile`; | ||
| + | $lngsite = 'http://' . $lng . '.anarchopedia.org'; | ||
| + | $langdata =~ s/###LNG_CODE###/$lng/g; | ||
| + | $langdata =~ s/###LNGSITE###/$lngsite/g; | ||
| + | $langdata =~ s/###LN_CODE###/$lg/g; | ||
| + | print $langdata; | ||
| + | } | ||
| + | |||
| + | # Adding language into SQL script for Internal interwiki for old languages. | ||
| + | $langsentence = "echo \"INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LN_CODE###','###LANGSITE###/\$1',1);" | \ | ||
| + | mysql -u" . $dbuser . " -p " . $dbpass . " " . $database . "\n"; | ||
| + | open (ADD, ">> $langfile"); | ||
| + | print ADD $langsentence; | ||
| + | close (ADD); | ||
| + | |||
| + | # Adding SQL code (from [[Anarchopedia:en:administration/Internal interwiki|Internal interwiki]]) | ||
| + | print "mysql -u " . $dbuser . " -p " . $dbpass . " " . $database . " < " . $sqlfile . "\n"; | ||
| + | |||
| + | # Adding language into SQL script for Internal interwiki for new languages. | ||
| + | $sqlsentence = "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('" . $lng . "','" . $langsite . "/\$1',1);"; | ||
| + | $sqlsentence .= "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('" . $lg . "','" . $langsite . "/\$1',1);"; | ||
| + | open (ADD, ">> $sqlfile"); | ||
| + | print ADD $sqlsentence; | ||
| + | close (ADD); | ||
| + | |||
| + | # the end | ||
Latest revision as of 10:33, 20 November 2008
(I am writting code here, so it is not done yet.)
There are two scripts: (1) Before MediaWiki initialization and (2) After MediaWiki initialization. (There is no need for automatization because we are not IANA :) )
Before MediaWiki initialization:[edit]
Program shoud be started as "./program.pl | sh".
#!/usr/bin/perl -w
# Some parameters:
$conf_available_dir = "";
$conf_enabled_dir = "";
$vhostroot = "";
$serveradmin = "";
$serveruser = "";
$servergroup = "";
$mediawikisource = "";
$mediawikipatch = "";
$reloadapachecmd = "";
$default_config = $conf_available_dir . '/template-org.anarchopedia.lang.template';
die "No default config, no new Anarchopedia!" if (!(-f $default_config));
die "No vhostroot dir, no new Anarchopedia!" if (!(-d $vhostroot));
die "No MediaWiki, no new Anarchopedia!" if (!(-d $mediawikisource));
system "mkdir " . $vhostroot . "/langs" if (!(-d "$vhostroot/langs"));
# We are getting three letter language code and two letter language code from ARGV.
die "No language codes, no new Anarchopedia!" if (!($ARGV[0]) || !($ARGV[1]));
$lng = $ARGV[0];
$lg = $ARGV[1];
$lang_config = $conf_available_dir . '/org.anarchopedia.' . $lng . '.conf';
# Translating LANGUAGE and LANG to real codes
$httpdconf = `cat $default_config`;
$httpdconf =~ s#LANGUAGE#$lng#g;
$httpdconf =~ s#LANG2#$lg#g;
# Translating VHOSTROOT into real virtual host root
$httpdconf = s#VHOSTROOT#$vhostroot#g;
# Who is server admin?
$httpdconf = s#SERVERADMIN#$serveradmin#g;
# Commenting RewriteRule and RewriteCond for initialization.
$httpdconf =~ s/RewriteRule/# RewriteRule/g;
$httpdconf =~ s/RewriteCond/# RewriteCond/g;
# Copying MediaWiki source
$htdocsdir = $vhostroot . "langs/" . $lng . "\"";
$cgibindir = $vhostroot . "cgi-bin/" . $lng . "\"";
print "cp -a " . $mediawikisource . ' "' . $htdocsdir . '"';
# Copying MediaWiki patch
print "cp -a " . $mediawikipatch . '/* "' . $htdocsdir . '"';
# Creating some directories and chowning them
print "mkdir -p \"" . $cgibindir . "\"";
print "chown -R" . $serveruser . '.' . $servergroup . '"' . $htdocsdir . '" "' . $cgibindir . '"';
# Putting httpdconf and reloading Apache
open ("CONFIG", "> $lang_config");
print CONFIG $httpdconf;
close (CONFIG);
print "ln -s \"" . $lang_config . "\" \"" . $conf_enabled_dir . "\"";
print $reloadapachecmd;
MediaWiki initialization[edit]
After MediaWiki initialization[edit]
#!/usr/bin/perl -w
# Some parameters:
$conf_available_dir = "";
$vhostroot = "";
$serveruser = "";
$servergroup = "";
$reloadapachecmd = "";
$langfile = "";
$sqlfile = "";
$database = "";
$dbuser = "";
$dbpass = "";
die "No vhostroot dir, no new Anarchopedia!" if (!(-d $vhostroot));
die "No MediaWiki, no new Anarchopedia!" if (!(-d $mediawikisource));
# We are getting three letter language code and two letter language code from ARGV.
die "No language codes, no new Anarchopedia!" if (!($ARGV[0]) || !($ARGV[1]));
$lng = $ARGV[0];
$lg = $ARGV[1];
$lang_config = $conf_available_dir . '/org.anarchopedia.' . $lng . '.conf';
die "No config, no new Anarchopedia!" if (!(-f $lang_config));
# We need configuration:
$httpdconf = `cat $lang_config`;
# Removing commets before RewriteRule and RewriteCond.
$httpdconf =~ s/# RewriteRule/RewriteRule/g;
$httpdconf =~ s/# RewriteCond/RewriteCond/g;
# Putting httpdconf and reloading Apache
open ("CONFIG", "> $lang_config");
print CONFIG $httpdconf;
close (CONFIG);
print "ln -s \"" . $lang_config . "\" \"" . $conf_enabled_dir . "\"";
print $reloadapachecmd;
### LocalSetting.php
$old_localsettings = $vhostroot . '/langs/' . $lng . '/config/LocalSettings.php';
$localsettings = $vhostroot . '/langs/' . $lng . '/LocalSettings.php';
$datals = `cat $old_localsettings`;
# Changing $wgScript from $wgScriptPath/index.php to $wgScriptPath;
$datals =~ s/\n\$wgScript/\n\$wgScript = \$wgScriptPath;\n#\$wgScript/;
# ...
# ...
# ...
# Removig the old file
system "rm " . $old_localsettings;
# Writting new file
open (IN, "> $localsettings");
print IN $datals;
close (IN);
# Including new language into interwiki tables of other languages.
## The form of language code is:
### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LNG_CODE###','###LNGSITE###/$1',1);" | \
### mysql -u <username> -p <password> <database_existing_language1>
### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LG_CODE###','###LNGSITE###/$1',1);" | \
### mysql -u <username> -p <password> <database_existing_language1>
### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LNG_CODE###','###LNGSITE###/$1',1);" | \
### mysql -u <username> -p <password> <database_existing_language2>
### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LG_CODE###','###LNGSITE###/$1',1);" | \
### mysql -u <username> -p <password> <database_existing_language2>
### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LNG_CODE###','###LNGSITE###/$1',1);" | \
### mysql -u <username> -p <password> <database_existing_languageN>
### echo "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LG_CODE###','###LANGSITE###/$1',1);" | \
### mysql -u <username> -p <password> <database_existing_languageN>
if (-e $langfile) {
$langdata = `cat $langfile`;
$lngsite = 'http://' . $lng . '.anarchopedia.org';
$langdata =~ s/###LNG_CODE###/$lng/g;
$langdata =~ s/###LNGSITE###/$lngsite/g;
$langdata =~ s/###LN_CODE###/$lg/g;
print $langdata;
}
# Adding language into SQL script for Internal interwiki for old languages.
$langsentence = "echo \"INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('###LN_CODE###','###LANGSITE###/\$1',1);" | \
mysql -u" . $dbuser . " -p " . $dbpass . " " . $database . "\n";
open (ADD, ">> $langfile");
print ADD $langsentence;
close (ADD);
# Adding SQL code (from Internal interwiki)
print "mysql -u " . $dbuser . " -p " . $dbpass . " " . $database . " < " . $sqlfile . "\n";
# Adding language into SQL script for Internal interwiki for new languages.
$sqlsentence = "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('" . $lng . "','" . $langsite . "/\$1',1);";
$sqlsentence .= "INSERT INTO interwiki (iw_prefix,iw_url,iw_local) VALUES ('" . $lg . "','" . $langsite . "/\$1',1);";
open (ADD, ">> $sqlfile");
print ADD $sqlsentence;
close (ADD);
# the end