2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
5 # identify if this is a debian based distro
6 isdeb
() { command -v apt
&>/dev
/null
; }
7 # tee unique. append each stdin line if it does not exist in the file
11 for line
in "${MAPFILE[@]}"; do
12 grep -xFq "$line" "$1" &>/dev
/null ||
tee -a "$1" <<<"$line"
16 # get and reset an extension/skin repository, and enable it
19 local original_pwd
="$PWD"
21 local re
='[^/]*/[^/]*$'
23 target
=$mw/${BASH_REMATCH[0]}
24 if [[ ! -e $target/.git
]]; then
25 git clone
$url $target
28 echo "mw-ext error: failed cd $target";
32 git checkout
-qf origin
/$mw_branch || git checkout
-qf origin
/master
40 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/extensions
/$ext
41 if [[ -e $mw/ext
/$ext/extension.json
]]; then
42 # new style extension. remove old style declaration
43 sed -i '#^require_once( "\\\$IP/extensions/\$ext/\$ext\.php" );#d' $mwc
45 wfLoadExtension( '$ext' );
49 require_once( "\$IP/extensions/$ext/$ext.php" );
53 # --quick is quicker than default flags,
54 # but still add a sleep to make sure everything works right
55 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
59 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/skins
/$skin
60 sed -i '/^wfLoadSkin/d' $mwc
61 sed -i '/^\$wgDefaultSkin/d' $mwc
63 \$wgDefaultSkin = "${skin,,*}";
64 wfLoadSkin( '$skin' );
66 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
69 if command -v apt
&>/dev
/null
; then
76 # <source lang="bash">
77 # From here on out, exit if a command fails.
78 # This will prevent us from not noticing an important failure.
79 # We recommend setting this for the entire installation session.
80 # If you are running commands interactively, it might be best to
81 # put it in your ~/.bashrc temporarily.
83 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
88 # https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Ubuntu
90 apt-get
install -y imagemagick php-mbstring
91 if apt-get
install -s mediawiki
&>/dev
/null
; then
92 # in debian wheezy time-frame distros, mediawiki was packaged.
93 apt-get
-y install php-apc mediawiki
95 # https://www.mediawiki.org/wiki/Manual:Installation_requirements
96 if apt-get
install -s php7.0
&>/dev
/null
; then
97 # note, 7.0 is untested by the editor here, since it's not
98 # available in debian 8. it's listed as supported
99 # in the mediawiki page.
100 # noninteractive to avoid mysql password prompt
101 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 mysql-server \
102 php7.0 php7.0
-mysql libapache2-mod-php7.0 php7.0
-xml \
105 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 mysql-server \
106 php5 php5-mysql libapache2-mod-php5 php5-apcu
109 service apache2 restart
112 # fedora deps are missing a database, so some is translated from debian packages
113 yum
-y install mediawiki ImageMagick php-mysqlnd php-pecl-apcu mariadb-server
115 systemctl restart mariadb.service
116 systemctl
enable mariadb.service
117 systemctl
enable httpd.service
118 systemctl restart httpd.service
122 # slightly different depending on if we already set the root pass
123 if echo exit|mysql
-u root
-p"$dbpass"; then
124 # answer interactive prompts:
125 # mysql root pass, change pass? no, remove anon users? (default, yes)
126 # disallow remote root (default, yes), reload? (default, yes)
127 echo -e "$dbpass\nn\n\n\n\n" | mysql_secure_installation
129 # I had 1 less newline at the start when doing ubuntu 14.04,
130 # compared to debian 8, so can't say this is especially portable.
131 # It won't hurt if it fails.
132 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
135 # <source lang="bash">
138 # this will just fail if it already exists which is fine
139 if [[ ! -e .git
]]; then
140 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/core.git .
142 # to see available branches: https://www.mediawiki.org/wiki/Version_lifecycle
145 git checkout
-f origin
/$mw_branch
147 # Get the php libraries wmf uses. Based on:
148 # https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries
149 if [[ ! -e vendor
/.git
]]; then
150 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/vendor.git
153 git checkout
-f origin
/$mw_branch
156 # Drop any previous database which may have been installed while testing.
157 # If upgrading, we should have a db backup which will get restored.
158 # https://www.mediawiki.org/wiki/Manual:Upgrading
159 mysql
-u root
-p$dbpass <<'EOF' ||:
160 drop database my_wiki;
163 php
$mw/maintenance
/install.php
--pass $wikipass --scriptpath /w \
164 --dbuser root
--dbpass $dbpass "$mwdescription" "$wikiuser"
166 # lock down the wiki to only the initial owner until anti-spam measures are put in place
167 # limit edits to registered users
168 $wgGroupPermissions['*']['edit'] = false;
169 # don't allow any account creation
170 $wgGroupPermissions['*']['createaccount'] = false;
173 # <source lang="bash">
176 git_site
=https
://iankelling.org
/git
177 git clone
$git_site/acme-tiny-wrapper
181 acme-tiny-wrapper
/acme-tiny-wrapper
$mwdomain
183 git clone
$git_site/basic-https-conf
185 ServerAdmin $mw_email
187 # make the site's root url go to our main page
188 RewriteRule ^/?wiki(/.*)?\$ %{DOCUMENT_ROOT}/w/index.php [L]
189 # use short urls https://www.mediawiki.org/wiki/Manual:Short_URL
190 RewriteRule ^/*\$ %{DOCUMENT_ROOT}/w/index.php [L]
192 find -L $
(readlink
-f $mw) -name .htaccess \
193 |
while read line
; do
194 echo -e "<Directory ${line%/.htaccess}>\n $(< $line)\n</Directory>";
196 } | basic-https-conf
/apache-site
-r ${mw%/*} - $mwdomain
200 # <source lang="bash">
201 dd of
=$mw/..
/robots.txt
<<'EOF'
204 User-agent: ia_archiver
209 # <source lang="bash">
211 \$wgServer = "https://$mwdomain";
212 \$wgDBserver = "localhost";
213 \$wgRightsUrl = "$mw_RightsUrl";
214 \$wgRightsText = "$mw_RightsText";
215 \$wgRightsIcon = "$mw_RightsIcon";
218 # <source lang="bash">
220 \$wgPasswordSender = "$mw_email";
221 \$wgEmergencyContact = "$mw_email";
222 \$wgEnotifUserTalk = true; # UPO
223 \$wgEnotifWatchlist = true; # UPO
224 \$wgMainCacheType = CACHE_ACCEL;
225 \$wgEnableUploads = true;
226 \$wgUseInstantCommons = true;
229 # <source lang="bash">
231 # from https://www.mediawiki.org/wiki/Manual:Short_URL
232 $wgArticlePath = "/wiki/$1";
234 # https://www.mediawiki.org/wiki/Manual:Combating_spam
235 # check that url if our precautions don't work
236 # not using nofollow is good practice, as long as we avoid spam.
237 $wgNoFollowLinks = false;
238 # Allow user customization.
239 $wgAllowUserJs = true;
240 $wgAllowUserCss = true;
242 # use imagemagick over GD
243 $wgUseImageMagick = true;
247 # https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
248 # Increase from default of 2M to 100M.
249 # This will at least allow high res pics etc.
250 php_ini
=$
(php
-r 'echo(php_ini_loaded_file());')
251 sed -i 's/^\(upload_max_filesize\|post_max_size\)\b.*/\1 = 100M/' $php_ini
253 service apache2 restart
255 systemctl restart httpd.service
258 # if you were to install as a normal user, you would need this for images
259 # sudo usermod -aG $apache_user $USER
261 # this doesn't propogate right away
262 chgrp
-R $apache_user $mw/images
263 chmod -R g
+w
$mw/images
265 # <source lang="bash">
268 #$wgFooterIcons = null;
270 # Make the toolbox go into the drop down.
272 if ! git remote show ian-kelling
&>/dev
/null
; then
273 git remote add ian-kelling https
://iankelling.org
/git
/Vector
275 git fetch ian-kelling
276 git checkout ian-kelling
/REL1_27-toolbox-in-dropdown
278 # <source lang="bash">
279 mw-ext Cite CiteThisPage CSS Echo Gadgets ImageMap Interwiki News \
280 Nuke ParserFunctions Poem SyntaxHighlight_GeSHi Variables
282 # <source lang="bash">
284 # recommended setup script to account for existing users
285 sudo
-u $apache_user php
$mw/extensions
/AntiSpoof
/maintenance
/batchAntiSpoof.php
287 # <source lang="bash">
289 sudo
-u $apache_user php
$mw/extensions
/CheckUser
/install.php
; sleep 1
291 # <source lang="bash">
293 apt-get
-y install php-wikidiff2
295 $wgExternalDiffEngine = 'wikidiff2';
297 dir
=$
(dirname $
(php
-r 'echo(php_ini_loaded_file());'))/..
/apache
2/conf.d
298 ln -sf ..
/..
/mods-available
/wikidiff2.ini
$dir
299 service apache2 restart
302 # <source lang="bash">
304 # php5-curl according to Math readme
307 if ! apt-get
-s install $curl_pkg &>/dev
/null
; then
310 apt-get
-y install latex-cjk-all texlive-latex-extra texlive-latex-base \
311 ghostscript imagemagick ocaml
$curl_pkg make
313 # todo, php5-curl equivalent on fedora
314 yum
-y install texlive-cjk ghostscript ImageMagick texlive ocaml
316 service apache2 restart
318 cd $mw/extensions
/Math
/math
; make # makes texvc
319 cd $mw/extensions
/Math
/texvccheck
; make
322 # Enable MathJax as rendering option
323 $wgUseMathJax = true;
324 # Enable LaTeXML as rendering option
325 $wgMathValidModes[] = 'latexml';
326 # Set LaTeXML as default rendering option, because it is nicest
327 $wgDefaultUserOptions['math'] = 'latexml';
330 # <source lang="bash">
332 if ! grep -F '$wgSpamBlacklistFiles = array(' $mwc &>/dev
/null
; then
334 $wgEnableDnsBlacklist = true;
335 $wgDnsBlacklistUrls = array( 'xbl.spamhaus.org', 'dnsbl.tornevall.org' );
337 ini_set( 'pcre.backtrack_limit', '10M' );
338 $wgSpamBlacklistFiles = array(
339 "[[m:Spam blacklist]]",
340 "http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist"
345 # <source lang="bash">
346 mw-ext TitleBlacklist
347 if ! grep -F '$wgTitleBlacklistSources = array(' $mwc &>/dev
/null
; then
349 $wgTitleBlacklistSources = array(
352 'src' => 'MediaWiki:Titleblacklist',
356 'src' => 'http://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw',
362 # <source lang="bash">
365 # Enable Wikieditor by default
366 $wgDefaultUserOptions['usebetatoolbar'] = 1;
367 $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
369 # Display the Preview and Changes tabs
370 $wgDefaultUserOptions['wikieditor-preview'] = 1;
373 # <source lang="bash">
376 # Mediawiki setting dependency for CategoryTree
380 # <source lang="bash">
383 $wgGroupPermissions['sysop']['abusefilter-modify'] = true;
384 $wgGroupPermissions['*']['abusefilter-log-detail'] = true;
385 $wgGroupPermissions['*']['abusefilter-view'] = true;
386 $wgGroupPermissions['*']['abusefilter-log'] = true;
387 $wgGroupPermissions['sysop']['abusefilter-private'] = true;
388 $wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
389 $wgGroupPermissions['sysop']['abusefilter-revert'] = true;
392 # <source lang="bash">
396 wfLoadExtension( 'ConfirmEdit/QuestyCaptcha' );
397 $wgCaptchaClass = 'QuestyCaptcha';
398 # only captcha on registration
399 $wgGroupPermissions['user' ]['skipcaptcha'] = true;
400 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
402 if ! grep -Fx 'foreach ( $localSettingsQuestyQuestions as $key => $value ) {' $mwc; then
404 foreach ( $localSettingsQuestyQuestions as $key => $value ) {
405 $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
410 # <source lang="bash">
411 sed -i "/\\\$wgGroupPermissions\\['\\*'\\]\\['createaccount'\\] = false;/d" $mwc
413 # <source lang="bash">
415 if [[ ! -e ~
/pywikibot
/.git
]]; then
416 git clone
--recursive \
417 https
://gerrit.wikimedia.org
/r
/pywikibot
/core.git ~
/pywikibot
424 # <source lang="bash">
426 dd of
=user-config.py
<<EOF
428 usernames["$mwfamily"]['en'] = u'$wikiuser'
430 console_encoding = 'utf-8'
431 password_file = "secretsfile"
434 dd of
=secretsfile
<<EOF
435 ("$wikiuser", "$wikipass")
438 # it won't overrwrite an existing file. Remove if if one exists
439 rm -f pywikibot
/families
/${mwfamily}_family.py
441 apt-get
install -y python-requests
443 yum
-y install python-requests
446 python generate_family_file.py https
://$mwdomain/wiki
/Main_Page
"$mwfamily"
448 # Note, this needed only for ssl site
449 tee -a pywikibot
/families
/${mwfamily}_family.py
<<'EOF'
450 def protocol(self, code):
454 # <source lang="bash">
457 dd of
=scripts
/${mwfamily}_setup.py
<<EOF
461 site = pywikibot.Site()
463 page = pywikibot.Page(site, p)
465 #force is for some anti-bot thing, not necessary in my testing, but might as well include it
466 page.save(force=True)
468 # Small/medium noncommercial wiki should be fine with no privacy policy
469 # based on https://www.mediawiki.org/wiki/Manual:Footer
470 x("MediaWiki:Privacy")
472 # licenses for uploads. Modified from the mediawiki's wiki
473 x("MediaWiki:Licenses", u"""* Same as this wiki's text (preferred)
474 ** CC BY-SA or GFDL| Creative Commons Attribution ShareAlike or GNU Free Documentation License
476 ** Unknown_copyright|I don't know exactly
477 ** PD|PD: public domain
478 ** CC BY|Creative Commons Attribution
479 ** CC BY-SA|Creative Commons Attribution ShareAlike
480 ** GFDL|GFDL: GNU Free Documentation License
481 ** GPL|GPL: GNU General Public License
482 ** LGPL|LGPL: GNU Lesser General Public License""")
483 x("MediaWiki:Copyright", '$mw_license')
484 x("MediaWiki:Mainpage-description", "$mwdescription")
488 # The rest of the settings are for the site style
490 # Remove various clutter
491 x("MediaWiki:Lastmodifiedat")
492 x("MediaWiki:Disclaimers")
493 x("MediaWiki:Viewcount")
494 x("MediaWiki:Aboutsite")
495 # remove these lines from sidebar
496 # ** recentchanges-url|recentchanges
497 # ** randompage-url|randompage
499 x("MediaWiki:Sidebar", """* navigation
500 ** mainpage|mainpage-description
506 # helpfull doc: https://www.mediawiki.org/wiki/Manual:Interface/Sidebar
507 x("mediawiki:Common.css", """/* adjust sidebar to just be home link and up top */
508 /* panel width increased to fit full wiki name. */
509 div#mw-panel { top: 10px; padding-top: 0em; width: 20em }
510 div#footer, #mw-head-base, div#content { margin-left: 1em; }
511 #left-navigation { margin-left: 1em; }
514 /* logo, and toolbar hidden */
515 #p-logo, #p-tb.portal {
519 /* make the font size smaller for the misc stuff */
527 div#mw-content-text {
533 python pwb.py
${mwfamily}_setup
535 # <source lang="bash">
536 s
=/etc
/cron.daily
/mediawiki_update
542 git checkout origin/$mw_branch
543 git rebase ian/REL1_23-toolbox-in-dropdown
549 git checkout origin/$mw_branch || git checkout -qf origin/master
553 php $mw/maintenance/update.php -q