Mediawiki installation/create or upgrade shared-wiki-extensions.sh

From Biowikifarm Metawiki
< Mediawiki installation
Revision as of 14:42, 26 January 2016 by Andreas Plank (Talk | contribs) (Created page with "Run this as a script <code>{{SUBPAGENAMEE}}</code> not via copy and paste!!! The script does: * extensions listed the script extract them from /usr/share/mw-wmf-clone/extensio...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Run this as a script create_or_upgrade_shared-wiki-extensions.sh not via copy and paste!!! The script does:

  • extensions listed the script extract them from /usr/share/mw-wmf-clone/extensions to a /usr/share/mediawikiXXX
  • if the requested git_branch is not available whatsoever the script extracts origin/master then

It needs an existing /usr/share/mediawikiXXX ready to use shared wiki resource (see create_or_upgrade_shared_wiki-core-resource-structure.sh)

See also write_wmf-shared_git-branches-tags2home_ext-tags-and-branches.sh to list all available tags and branches of git-maintained extensions.

Extension:VisualEditor

Unchecked: it needs possibly a separate git clone in its extension folder (read web documentation (Extension:VisualEditor)).

Bash script

Bash script: create_or_upgrade_shared-wiki-extensions.sh. You can make the script executable by

# u o g means: user who owns it (u), other users in the file's group (g), other users (o)
chmod ug+x create_or_upgrade_shared-wiki-extensions.sh # add executable mode for the owned user
#!/bin/bash
# Warning: run this only as script not as copy and paste in console!!
# @description: create or upgrade extensions in a shared mediawiki resource
# @requires: depending on the desired git_branch you need an 
#   up to date git clone of /usr/share/mw-wmf-clone/extensions
######################################################

##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
#  # Update the git clone on biowikifarm:
#  cd /usr/share/mw-wmf-clone/core; sudo git fetch; 
#  cd /usr/share/mw-wmf-clone/extensions && sudo git pull; sudo git submodule update --init --recursive; sudo /usr/share/mw-wmf-clone/extensions/quick-update
#  cd /usr/share/mw-wmf-clone/skins; sudo git pull; sudo git submodule update --init --recursive;
#  
#  # OPTIONAL: list information on tags etc:
#  cd /usr/share/mw-wmf-clone/core; 
#    git branch --remotes | sort --version-sort # list branches
#    git tag --list | sort --version-sort # list tags
#  cd /usr/share/mw-wmf-clone/extensions; 
#    git branch --remotes | sort --version-sort # list branches
#    git tag --list | sort --version-sort # list tags
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
usr_share_wiki_path="/usr/share/mediawiki27wmf"
git_branch="origin/wmf/1.27.0-wmf.9" ## OR "origin/wmf/1.27.0-wmf.7" for wmf version, OR REL1_25
# extension folder
# usr_share_extension_path="${usr_share_wiki_path}/extensions-simple-features"
usr_share_extension_path="${usr_share_wiki_path}/extensions-rich-features"

# Note extensions managed by composer get overwritten:
#   GraphViz
#   ImageMap
#   Maps
#   SemanticForms
#   SemanticMediaWiki
#   SemanticMaps
#   SemanticResultFormats
#   Translate mediawiki/translate
#   Translate suggest: mediawiki/babel
#   UniversalLanguageSelector - mediawiki/universal-language-selector
#   Translate suggest: mediawiki/translation-notifications
#   Validator: mediawiki/validator
EXTENSIONS="
Arrays, origin/master
BetaFeatures
Campaigns
CategoryTree
CentralAuth
CharInsert, origin/master
CheckUser
CirrusSearch
Cite
CleanChanges
CodeReview
Collection
CollapsibleVector
CommonsMetadata
ConfirmAccount, origin/master
ConfirmEdit
ContactPage
DataTransfer, origin/master
DismissableSiteNotice
DynamicSidebar, origin/master
Echo
EducationProgram
Elastica, origin/master
ExternalData, 1.8.2
FlaggedRevs
Flow
Gadgets
GeoData
GlobalUsage
HeaderTabs, 1.0.2
InputBox
Interwiki
LiquidThreads
LocalisationUpdate, origin/master
Lockdown, origin/master
Loops, origin/master
MassEditRegex, origin/master
Math
MediaFunctions, origin/master
MwEmbedSupport, origin/master
MultimediaViewer
Nuke
OAuth
OpenID, origin/master
PageTools, origin/master
PagedTiffHandler, origin/master
ParserFunctions
PdfExport, origin/master
PdfHandler
Poem
ProofreadPage
Quiz
Renameuser
ReplaceText, origin/master
SemanticCompoundQueries, 0.4
SemanticDrilldown, 2.0.1
SemanticFormsInputs, origin/master
SemanticInternalObjects, 0.8.1
SpamBlacklist
SyntaxHighlight_GeSHi
Thanks
TimedMediaHandler, origin/master
TitleBlacklist
TranslationNotifications
TitleKey, origin/master
UploadWizard
UserMerge, origin/master
Variables, origin/master
VisualEditor
Widgets, origin/master
WikiEditor
Wikibase, origin/master
WikimediaMessages
VisualEditor, origin/master
"
# EXTENSIONS="
# Poem
# "
# End of settings
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

# Fix
EXTENSIONS=`echo "$EXTENSIONS" | sed '/^$/d'` # remove blank lines

# Create MediaWiki core for specific version
if [[ ! -d ${usr_share_wiki_path} ]]; then 
  echo "### Does not exist '${usr_share_wiki_path}' (stop)"
  echo "### Run skript create_or_upgrade_shared_wiki-core-resource-structure.sh (see biowikifarm.net)"
  exit 1;
fi

# prompt User
echo    "###############################################################"
echo -e "# Upgrade or create shard Wiki extensions to branch \e[31m${git_branch}\e[0m"
echo    "#   /usr/share/mw-wmf-clone/extensions → $usr_share_extension_path"
echo    "# Up-to-date?"
echo    "#   Did you run sudo git pull and script quick-update in /usr/share/mw-wmf-clone/extensions?"
echo    "# Information Note:"
echo    "#   Run perhaps script write_wmf-shared_git-branches-tags2home_ext-tags-and-branches.sh"
echo    "#   to get all available branches and tags available in /usr/share/mw-wmf-clone/extensions"
echo    "# Extensions:"
echo -e "#   If an extension is not available as ${git_branch} the script uses \e[1morigin/master\e[0m then."
echo -e "#   The following extensions are going to be updated (${git_branch}):"
echo "$EXTENSIONS"  | sed 's@^ *\(.\+\)[ ]*$@\1@; s@\(.\+\)[,][ ]*\(.\+\)@\1 (\2)@g; $!{ s@$@;@;}' | fmt - | sed 's@^\(.\+\)@#    \1@;'

echo -ne "# Do you want to upgrade (\e[32m$usr_share_extension_path\e[0m)?\n[yes or no (default: no)]: "
read yno
case $yno in
  [yY]|[yY][Ee][Ss])
    echo "Continue to upgrade"
  ;;
  [nN]|[nN][oO])
    echo "Stop upgrade";
    exit 1
  ;;
  *) echo "Invalid or no input (stop)"
    exit 1
  ;;
esac

#######################################
# 2. Create MediaWiki extensions in usr/share
# IMPORTANT: extensions managed by PHP script composer.phar and
# their dependencies must not be included here, presently these are:
# "mediawiki/graph-viz"
# "mediawiki/image-map"
# "mediawiki/semantic-media-wiki"
# "mediawiki/semantic-breadcrumb-links"
# "mediawiki/semantic-result-formats"
# "mediawiki/semantic-forms"
# "mediawiki/semantic-maps"

##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
echo "# Set ${usr_share_extension_path} to be owned by www-data (subversion post-commit demands these rights)"
if [ -d "${usr_share_extension_path}" ];then
  sudo chown www-data:www-data "${usr_share_extension_path}" -R
else
  echo "# Create ${usr_share_extension_path} ..."
  sudo -u root -g mwadmin mkdir --parents "${usr_share_extension_path}"
  sudo chown www-data:www-data "${usr_share_extension_path}" -R
fi
echo "# Update extensions in ${usr_share_extension_path} ..."

# --
# split line on ", ". If only one value, export HEAD, else first value is branch/tag. Example:
#   SemanticMediaWiki, 1.8
#      ↓                   ↓
#   $extension, $this_clone_version
#   will export tag 1.8
# NOTE: check the line (similar to ternary operator: if condition ? dothis : dootherthings)
# $( ... ) substitutes/returns the command's output
# → if ext-check-with-comma == ext then (&&) "HEAD" else (||) version-string-from-above-list-of-EXTENSIONS
# ${ext%,*}    from back  of $ext → delete shortest (%) or longest (%%) match
# ${ext#*,* }  from front of $ext → delete shortest (#) or longest (##) match
# --------------------------------------

this_ext_update_status=""
IFS=$'\n'; 
i_ext=1; n_ext=` echo "$EXTENSIONS" | wc --lines`
do_substitute_with_originMaster="" # empty or any value

for ext in $EXTENSIONS; do
  if [ "${ext}" ];then
    this_extension=$([ "${ext%,*}" == "$ext" ] && echo "$ext" || echo "${ext%%,*}");
    this_clone_version=$([ "${ext%,*}" == "$ext" ] && echo "$git_branch" || echo "${ext#*, *}");
    if ! [ -d "/usr/share/mw-wmf-clone/extensions/${this_extension}" ]; then
      echo "#   Shared extension resource: /usr/share/mw-wmf-clone/extensions/${this_extension} DOES NOT EXIST AS GIT SOURCE,"
      echo "#     check the extension's name or path!! (extension was skipped)";
    else
      if [ ! -d "${usr_share_extension_path}/${this_extension}" ]; then
        this_ext_update_status="+";
        sudo mkdir --parents "${usr_share_extension_path}/${this_extension}";
      # extension folder must be owned by www-data because of the subversion post-commit update
        sudo chown www-data:www-data "${usr_share_extension_path}/${this_extension}";
      else
        this_ext_update_status="u";
      fi;
      echo "# "
      printf "#   Shared extension resource: %03s of %03s: %1s %-30s (tag or branch: %s)\n" $i_ext $n_ext $this_ext_update_status $this_extension $this_clone_version;
      if [ -d "/usr/share/mw-wmf-clone/extensions/${this_extension}" ]; then
        cd "/usr/share/mw-wmf-clone/extensions/${this_extension}";
        AVAILABLE_remoteBRANCH_VERSIONS=`git branch --remote | sort --version-sort`;
        AVAILABLE_TAGS_VERSIONS=`git tag --list | sort --version-sort`;
        ##### FOLLOWING LINES CAUSE ERROR -> CHECKING code temporarily DISABLED
        if [ "`echo "$AVAILABLE_remoteBRANCH_VERSIONS" | grep --count "$this_clone_version"`" == "0" ]; then
          if  [ "`echo "$AVAILABLE_TAGS_VERSIONS" | grep --count "$this_clone_version"`" == "0" ]; then
            echo "#   Clone version of tag or branch $this_clone_version is not available!!";
            echo "#   Check available branches: git branch --remotes  | sort --version-sort";
            echo "$AVAILABLE_remoteBRANCH_VERSIONS";
            echo "#   Check available tags: git tag --list  | sort --version-sort";
            echo "$AVAILABLE_TAGS_VERSIONS";
            do_substitute_with_originMaster="1"
          else
            do_substitute_with_originMaster=""
            echo "#   OK $this_clone_version is available";
          fi
        else
          do_substitute_with_originMaster=""
          echo "#   OK $this_clone_version is available";
        fi;
        # test zero string length
        if [[ -z ${do_substitute_with_originMaster// /} ]];then
          # EXAMPLE: sudo git archive --prefix=AdminLinks/ HEAD | sudo -u www-data tar --extract --overwrite --directory=/usr/share/mediawiki25/extensions
          # TODO not sure if VisualEditor can be used from /usr/share/mw-wmf-clone/extensions/VisualEditor 
          # or whether it does need an addition al git fetch in /usr/share/mediawiki27wmf/extensions
          # VE-check: if [ "VisualEditor" == "${this_extension}" ];then
          # VE-check:   echo "#   Shared extension resource: WARNING YOU HAVE TO DO a git clone into ./extensions/VisualEditor MANUALLY !! (see web docu)"
          # VE-check: else
            echo "#     clean ${usr_share_extension_path}/${this_extension}" 
            sudo rm --recursive -- "${usr_share_extension_path}/${this_extension}"/*;
            echo "#     sudo git archive --prefix=\"${this_extension}/\" \"$this_clone_version\"" 
            sudo git archive --prefix="${this_extension}/" "$this_clone_version" | sudo -u www-data tar --extract --overwrite --directory="${usr_share_extension_path}";
          # VE-check fi
        else
          echo -e "#     $this_clone_version of ${this_extension} not available, \e[31mSUBSTITUTE with origin/master\e[0m"
          sudo git archive --prefix="${this_extension}/" "origin/master" | sudo -u www-data tar --extract --overwrite --directory="${usr_share_extension_path}";
        fi
      else
        echo  "#     Warning \"/usr/share/mw-wmf-clone/extensions/${this_extension}\" not found!! Check extension name or git pull";
      fi;
    fi;
  fi;
  i_ext=$((i_ext + 1))
done;
cd ..
IFS=$' \t\n';
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑


#######################################
# subversion step 2: biowikifarm extensions 
cd "${usr_share_extension_path}"
echo "#   Update: subversion extensions of biowikifarm to ${usr_share_extension_path}"
sudo -u www-data -g www-data svn checkout file:///var/lib/svn/LocalSVNextensions "${usr_share_extension_path}"
#######################################

echo "#   NOTICE: Take care of subversion’s checkout as well in /var/lib/svn/hooks/post-commit"
echo "#   to get ${usr_share_extension_path} updated upon suberversion commit"
echo "# "
echo "#   Extensions managed by sudo php /usr/local/bin/composer.phar update --no-dev"
echo "#   get overwritten. Use the composer.local.json to add those extensions not composer.json!!"