2 # Copyright (C) 2016 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
6 # identify if this is a debian based distro
7 isdeb
() { command -v apt
&>/dev
/null
; }
8 # tee unique. append each stdin line if it does not exist in the file
12 for line
in "${MAPFILE[@]}"; do
13 grep -xFq "$line" "$1" &>/dev
/null ||
tee -a "$1" <<<"$line"
17 # get and reset an extension/skin repository, and enable it
20 local original_pwd
="$PWD"
22 local re
='[^/]*/[^/]*$'
24 target
=$mw/${BASH_REMATCH[0]}
25 if [[ ! -e $target/.git
]]; then
26 git clone
$url $target
29 echo "mw-ext error: failed cd $target";
33 git checkout
-qf origin
/$mw_branch || git checkout
-qf origin
/master
41 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/extensions
/$ext
42 if [[ -e $mw/ext
/$ext/extension.json
]]; then
43 # new style extension. remove old style declaration
44 sed -i --follow-symlinks '#^require_once( "\\\$IP/extensions/\$ext/\$ext\.php" );#d' $mwc
46 wfLoadExtension( '$ext' );
50 require_once( "\$IP/extensions/$ext/$ext.php" );
54 # --quick is quicker than default flags,
55 # but still add a sleep to make sure everything works right
56 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
60 mw-clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/skins
/$skin
61 sed -i --follow-symlinks '/^wfLoadSkin/d' $mwc
62 sed -i --follow-symlinks '/^\$wgDefaultSkin/d' $mwc
64 \$wgDefaultSkin = "${skin,,*}";
65 wfLoadSkin( '$skin' );
67 sudo
-u $apache_user php
$mw/maintenance
/update.php
-q --quick; sleep 1
70 if command -v apt
&>/dev
/null
; then
77 # <source lang="bash">
78 # From here on out, exit if a command fails.
79 # This will prevent us from not noticing an important failure.
80 # We recommend setting this for the entire installation session.
81 # If you are running commands interactively, it might be best to
82 # put it in your ~/.bashrc temporarily.
84 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
89 # https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Ubuntu
91 DEBIAN_FRONTEND
=noninteractive apt-get
install -y imagemagick
92 if apt-get
install -s mediawiki
&>/dev
/null
; then
93 # mediawiki is packaged in jessie backports.
94 DEBIAN_FRONTEND
=noninteractive apt-get
-y install php5-apcu mediawiki
96 # https://www.mediawiki.org/wiki/Manual:Installation_requirements
97 if apt-get
install -s php7.0
&>/dev
/null
; then
98 # note, 7.0 is untested by the editor here, since it's not
99 # available in debian 8. it's listed as supported
100 # in the mediawiki page.
101 # noninteractive to avoid mysql password prompt.
102 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 \
103 default-mysql-server \
104 php7.0 php7.0
-mysql libapache2-mod-php7.0 php7.0
-xml \
105 php7.0
-apcu php7.0
-mbstring
107 # note: mbstring is recommended, but it's not available for php5 in
109 DEBIAN_FRONTEND
=noninteractive apt-get
install -y apache2 \
110 default-mysql-server \
111 php5 php5-mysql libapache2-mod-php5 php5-apcu
114 service apache2 restart
117 # fedora deps are missing a database, so some is translated from debian packages
118 yum
-y install mediawiki ImageMagick php-mysqlnd php-pecl-apcu mariadb-server
120 systemctl restart mariadb.service
121 systemctl
enable mariadb.service
122 systemctl
enable httpd.service
123 systemctl restart httpd.service
127 # slightly different depending on if we already set the root pass
128 if echo exit|mysql
-u root
-p"$dbpass"; then
129 # answer interactive prompts:
130 # mysql root pass, change pass? no, remove anon users? (default, yes)
131 # disallow remote root (default, yes), reload? (default, yes)
132 echo -e "$dbpass\nn\n\n\n\n" | mysql_secure_installation
134 # I had 1 less newline at the start when doing ubuntu 14.04,
135 # compared to debian 8, so can't say this is especially portable.
136 # It won't hurt if it fails.
137 echo -e "\n\n$dbpass\n$dbpass\n\n\n\n\n" | mysql_secure_installation
140 # <source lang="bash">
143 # this will just fail if it already exists which is fine
144 if [[ ! -e .git
]]; then
145 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/core.git .
147 # to see available branches: https://www.mediawiki.org/wiki/Version_lifecycle
150 git checkout
-f origin
/$mw_branch
152 # Get the php libraries wmf uses. Based on:
153 # https://www.mediawiki.org/wiki/Download_from_Git#Fetch_external_libraries
154 if [[ ! -e vendor
/.git
]]; then
155 git clone https
://gerrit.wikimedia.org
/r
/p
/mediawiki
/vendor.git
158 git checkout
-f origin
/$mw_branch
161 # Drop any previous database which may have been installed while testing.
162 # If upgrading, we should have a db backup which will get restored.
163 # https://www.mediawiki.org/wiki/Manual:Upgrading
164 mysql
-u root
-p$dbpass <<'EOF' ||:
165 drop database my_wiki;
168 php
$mw/maintenance
/install.php
--pass $wikipass --scriptpath /w \
169 --dbuser root
--dbpass $dbpass "$mwdescription" "$wikiuser"
171 # lock down the wiki to only the initial owner until anti-spam measures are put in place
172 # limit edits to registered users
173 $wgGroupPermissions['*']['edit'] = false;
174 # don't allow any account creation
175 $wgGroupPermissions['*']['createaccount'] = false;
178 # <source lang="bash">
181 git_site
=https
://iankelling.org
/git
182 git clone
$git_site/acme-tiny-wrapper
186 acme-tiny-wrapper
/acme-tiny-wrapper
-t $mwdomain
188 git clone
$git_site/basic-https-conf
190 ServerAdmin $mw_email
192 # make the site's root url go to our main page
193 RewriteRule ^/?wiki(/.*)?\$ %{DOCUMENT_ROOT}/w/index.php [L]
194 # use short urls https://www.mediawiki.org/wiki/Manual:Short_URL
195 RewriteRule ^/*\$ %{DOCUMENT_ROOT}/w/index.php [L]
197 find -L $
(readlink
-f $mw) -name .htaccess \
198 |
while read line
; do
199 echo -e "<Directory ${line%/.htaccess}>\n $(< $line)\n</Directory>";
201 } | basic-https-conf
/apache-site
-r ${mw%/*} - $mwdomain
205 # <source lang="bash">
206 dd of
=$mw/..
/robots.txt
<<'EOF'
209 User-agent: ia_archiver
214 # <source lang="bash">
216 \$wgServer = "https://$mwdomain";
217 \$wgDBserver = "localhost";
218 \$wgRightsUrl = "$mw_RightsUrl";
219 \$wgRightsText = "$mw_RightsText";
220 \$wgRightsIcon = "$mw_RightsIcon";
223 # <source lang="bash">
225 \$wgPasswordSender = "$mw_email";
226 \$wgEmergencyContact = "$mw_email";
227 \$wgEnotifUserTalk = true; # UPO
228 \$wgEnotifWatchlist = true; # UPO
229 \$wgMainCacheType = CACHE_ACCEL;
230 \$wgEnableUploads = true;
231 \$wgUseInstantCommons = true;
234 # <source lang="bash">
236 # from https://www.mediawiki.org/wiki/Manual:Short_URL
237 $wgArticlePath = "/wiki/$1";
239 # https://www.mediawiki.org/wiki/Manual:Combating_spam
240 # check that url if our precautions don't work
241 # not using nofollow is good practice, as long as we avoid spam.
242 $wgNoFollowLinks = false;
243 # Allow user customization.
244 $wgAllowUserCss = true;
246 # use imagemagick over GD
247 $wgUseImageMagick = true;
251 # https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
252 # Increase from default of 2M to 100M.
253 # This will at least allow high res pics etc.
254 php_ini
=$
(php
-r 'echo(php_ini_loaded_file());')
255 sed -i --follow-symlinks 's/^\(upload_max_filesize\|post_max_size\)\b.*/\1 = 100M/' $php_ini
257 service apache2 restart
259 systemctl restart httpd.service
262 # if you were to install as a normal user, you would need this for images
263 # sudo usermod -aG $apache_user $USER
265 # this doesn't propogate right away
266 chgrp
-R $apache_user $mw/images
267 chmod -R g
+w
$mw/images
269 # <source lang="bash">
272 #$wgFooterIcons = null;
274 # Make the toolbox go into the drop down.
276 if ! git remote show ian-kelling
&>/dev
/null
; then
277 git remote add ian-kelling https
://iankelling.org
/git
/forks
/Vector
279 git fetch ian-kelling
280 git checkout ian-kelling
/${mw_branch}-toolbox-in-dropdown
282 # <source lang="bash">
283 mw-ext Cite CiteThisPage CSS Echo Gadgets ImageMap Interwiki News \
284 Nuke ParserFunctions Poem SyntaxHighlight_GeSHi Variables
286 # <source lang="bash">
288 # recommended setup script to account for existing users
289 sudo
-u $apache_user php
$mw/extensions
/AntiSpoof
/maintenance
/batchAntiSpoof.php
291 # <source lang="bash">
293 if [[ -e $mw/extensions
/CheckUser
/install.php
]]; then
294 sudo
-u $apache_user php
$mw/extensions
/CheckUser
/install.php
; sleep 1
297 # <source lang="bash">
299 apt-get
-y install php-wikidiff2
301 $wgExternalDiffEngine = 'wikidiff2';
303 dir
=$
(dirname $
(php
-r 'echo(php_ini_loaded_file());'))/..
/apache
2/conf.d
304 ln -sf ..
/..
/mods-available
/wikidiff2.ini
$dir
305 service apache2 restart
308 # <source lang="bash">
310 # php5-curl according to Math readme
313 if ! apt-get
-s install $curl_pkg &>/dev
/null
; then
316 apt-get
-y install latex-cjk-all texlive-latex-extra texlive-latex-base \
317 ghostscript imagemagick ocaml
$curl_pkg make
319 # todo, php5-curl equivalent on fedora
320 yum
-y install texlive-cjk ghostscript ImageMagick texlive ocaml
322 service apache2 restart
324 cd $mw/extensions
/Math
/math
; make # makes texvc
325 cd $mw/extensions
/Math
/texvccheck
; make
328 # Enable MathJax as rendering option
329 $wgUseMathJax = true;
330 # Enable LaTeXML as rendering option
331 $wgMathValidModes[] = 'latexml';
332 # Set LaTeXML as default rendering option, because it is nicest
333 $wgDefaultUserOptions['math'] = 'latexml';
336 # <source lang="bash">
338 if ! grep -F '$wgSpamBlacklistFiles = array(' $mwc &>/dev
/null
; then
340 $wgEnableDnsBlacklist = true;
341 $wgDnsBlacklistUrls = array( 'xbl.spamhaus.org', 'dnsbl.tornevall.org' );
343 ini_set( 'pcre.backtrack_limit', '10M' );
344 $wgSpamBlacklistFiles = array(
345 "[[m:Spam blacklist]]",
346 "http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist"
351 # <source lang="bash">
352 mw-ext TitleBlacklist
353 if ! grep -F '$wgTitleBlacklistSources = array(' $mwc &>/dev
/null
; then
355 $wgTitleBlacklistSources = array(
358 'src' => 'MediaWiki:Titleblacklist',
362 'src' => 'http://meta.wikimedia.org/w/index.php?title=Title_blacklist&action=raw',
368 # <source lang="bash">
371 # Enable Wikieditor by default
372 $wgDefaultUserOptions['usebetatoolbar'] = 1;
373 $wgDefaultUserOptions['usebetatoolbar-cgd'] = 1;
375 # Display the Preview and Changes tabs
376 $wgDefaultUserOptions['wikieditor-preview'] = 1;
379 # <source lang="bash">
382 # Mediawiki setting dependency for CategoryTree
386 # <source lang="bash">
389 $wgGroupPermissions['sysop']['abusefilter-modify'] = true;
390 $wgGroupPermissions['*']['abusefilter-log-detail'] = true;
391 $wgGroupPermissions['*']['abusefilter-view'] = true;
392 $wgGroupPermissions['*']['abusefilter-log'] = true;
393 $wgGroupPermissions['sysop']['abusefilter-private'] = true;
394 $wgGroupPermissions['sysop']['abusefilter-modify-restricted'] = true;
395 $wgGroupPermissions['sysop']['abusefilter-revert'] = true;
398 # <source lang="bash">
402 wfLoadExtension( 'ConfirmEdit/QuestyCaptcha' );
403 $wgCaptchaClass = 'QuestyCaptcha';
404 # only captcha on registration
405 $wgGroupPermissions['user' ]['skipcaptcha'] = true;
406 $wgGroupPermissions['autoconfirmed']['skipcaptcha'] = true;
408 if ! grep -Fx 'foreach ( $localSettingsQuestyQuestions as $key => $value ) {' $mwc; then
410 foreach ( $localSettingsQuestyQuestions as $key => $value ) {
411 $wgCaptchaQuestions[] = array( 'question' => $key, 'answer' => $value );
416 # <source lang="bash">
417 sed -i --follow-symlinks "/\\\$wgGroupPermissions\\['\\*'\\]\\['createaccount'\\] = false;/d" $mwc
419 # <source lang="bash">
421 if [[ ! -e ~
/pywikibot
/.git
]]; then
422 git clone
--recursive \
423 https
://gerrit.wikimedia.org
/r
/pywikibot
/core.git ~
/pywikibot
430 # <source lang="bash">
432 dd of
=user-config.py
<<EOF
434 usernames["$mwfamily"]['en'] = u'$wikiuser'
436 console_encoding = 'utf-8'
437 password_file = "secretsfile"
440 dd of
=secretsfile
<<EOF
441 ("$wikiuser", "$wikipass")
444 # it won't overrwrite an existing file. Remove if if one exists
445 rm -f pywikibot
/families
/${mwfamily}_family.py
447 apt-get
install -y python-requests
449 yum
-y install python-requests
452 python generate_family_file.py https
://$mwdomain/wiki
/Main_Page
"$mwfamily"
454 # Note, this needed only for ssl site
455 tee -a pywikibot
/families
/${mwfamily}_family.py
<<'EOF'
456 def protocol(self, code):
460 # <source lang="bash">
463 dd of
=scripts
/${mwfamily}_setup.py
<<EOF
467 site = pywikibot.Site()
469 page = pywikibot.Page(site, p)
471 #force is for some anti-bot thing, not necessary in my testing, but might as well include it
472 page.save(force=True)
474 # Small/medium noncommercial wiki should be fine with no privacy policy
475 # based on https://www.mediawiki.org/wiki/Manual:Footer
476 x("MediaWiki:Privacy")
478 # licenses for uploads. Modified from the mediawiki's wiki
479 x("MediaWiki:Licenses", u"""* Same as this wiki's text (preferred)
480 ** CC BY-SA or GFDL| Creative Commons Attribution ShareAlike or GNU Free Documentation License
482 ** Unknown_copyright|I don't know exactly
483 ** PD|PD: public domain
484 ** CC BY|Creative Commons Attribution
485 ** CC BY-SA|Creative Commons Attribution ShareAlike
486 ** GFDL|GFDL: GNU Free Documentation License
487 ** GPL|GPL: GNU General Public License
488 ** LGPL|LGPL: GNU Lesser General Public License""")
489 x("MediaWiki:Copyright", '$mw_license')
490 x("MediaWiki:Mainpage-description", "$mwdescription")
494 # The rest of the settings are for the site style
496 # Remove various clutter
497 x("MediaWiki:Lastmodifiedat")
498 x("MediaWiki:Disclaimers")
499 x("MediaWiki:Viewcount")
500 x("MediaWiki:Aboutsite")
501 # remove these lines from sidebar
502 # ** recentchanges-url|recentchanges
503 # ** randompage-url|randompage
505 x("MediaWiki:Sidebar", """* navigation
506 ** mainpage|mainpage-description
512 # helpfull doc: https://www.mediawiki.org/wiki/Manual:Interface/Sidebar
513 x("mediawiki:Common.css", """/* adjust sidebar to just be home link and up top */
514 /* panel width increased to fit full wiki name. */
515 div#mw-panel { top: 10px; padding-top: 0em; width: 20em }
516 div#footer, #mw-head-base, div#content { margin-left: 1em; }
517 #left-navigation { margin-left: 1em; }
520 /* logo, and toolbar hidden */
521 #p-logo, #p-tb.portal {
525 /* make the font size smaller for the misc stuff */
533 div#mw-content-text {
539 # this can spam a warning, so uniq it
540 python pwb.py
${mwfamily}_setup |
& uniq
542 # <source lang="bash">
543 s
=/etc
/cron.daily
/mediawiki_update
548 for dir in extensions/* skins/* $mw; do
549 [[ -d $dir ]] || continue
551 branch=$(git describe --all)
552 branch=${branch#remotes/}
554 new_head=$(git rev-parse $branch)
555 log=$(git log HEAD..$new_head)
560 git checkout -q $new_head
563 php $mw/maintenance/update.php -q --quick