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

From Biowikifarm Metawiki
Jump to: navigation, search

Run this as a script in normal mode not with sudo and not via copy and paste!

./create_or_upgrade_shared-wiki-skins.sh 

The script does:

  • extract listed skins in the script from /usr/share/mw-wmf-clone/skins to a shared resource /usr/share/mediawikiXXX

Requirements:

Bash script

You can make the script executable by

# u o g means: user who owns it , group users in the file's group, other users
# add executable mode for the owned user and groups
chmod ug+x create_or_upgrade_shared-wiki-skins.sh


Bash script:
./create_or_upgrade_shared-wiki-skins.sh

#!/bin/bash
# Warning: run this in normal mode not as sudo and not as copy and paste in console!!
# @description: create or upgrade skins in a shared MediaWiki resource
# @requires: running sudo without prompt
# @requires: a ready to use shared-wiki-resource e.g. in /usr/share/mediawiki26
# @requires: depending on the desired git_branch you need an 
#   up to date git clone of /usr/share/mw-wmf-clone/skins
######################################################
 
##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
#  # Update the git clone on biowikifarm:
#  cd /usr/share/mw-wmf-clone/core; sudo git fetch; 
#  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/skins/Vector; 
#    git branch --remotes | sort --version-sort # list branches
#    git tag --list | sort --version-sort # list tags
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
 
##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# Settings: edit the following settings at your convenience
usr_share_wiki_path="/usr/share/mediawiki26"
git_tag_or_branch="origin/REL1_26" ## OR "origin/wmf/1.27.0-wmf.7" for wmf version, OR REL1_25
# skin folder
usr_share_skins_path="${usr_share_wiki_path}/skins"
 
# List of SKINS can manage as follows
# SkinName1 (and no specific tag_or_branch -> global git_tag_or_branch is used)
# SkinName2, comma and tag_or_branch (this specific given tag_or_branch is used instead of global)
SKINS="
Vector
CologneBlue
MonoBook
Modern
"
# just some skins:"
# SKINS="
# Vector
# "
# End of settings
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
 
 
# Fix
SKINS=`echo "$SKINS" | sed '/^$/d'` # remove blank lines
 
# Check shared MediaWiki core 
if [[ ! -d ${usr_share_wiki_path} ]]; then 
  echo "### Shared resource does not exist: '${usr_share_wiki_path}' (stop)"
  echo "### Run script create_or_upgrade_shared_wiki-core-resource-structure.sh (see biowikifarm.net)"
  exit 1;
fi
 
# prompt User
echo    "###############################################################"
 
[[ -e $usr_share_skins_path ]] && \
echo -e "# Upgrade shared Wiki skins to branch \e[31m${git_tag_or_branch}\e[0m" || \
echo -e "# Create shared Wiki skins to branch \e[31m${git_tag_or_branch}\e[0m"
 
echo    "#   /usr/share/mw-wmf-clone/skins → $usr_share_skins_path"
echo    "# Check before: up-to-date?"
echo    "#   Did you run sudo git pull and script quick-update in /usr/share/mw-wmf-clone/skins?"
echo    "# Check before: information on branches, tags"
echo    "#   Run perhaps script write_wmf-shared_git-branches-tags2home_skin-tags-and-branches.sh"
echo    "#   to get all available branches and tags available in /usr/share/mw-wmf-clone/skins"
echo    "# Skins:"
echo -e "#   If a skin is not available as ${git_tag_or_branch} the script uses \e[1morigin/master\e[0m then."
echo -e "#   The following skins are going to be updated (${git_tag_or_branch}):"
echo "$SKINS"  | sed 's@^ *\(.\+\)[ ]*$@\1@; s@\(.\+\)[,][ ]*\(.\+\)@\1 (\2)@g; $!{ s@$@;@;}' | fmt - | sed 's@^\(.\+\)@#     \1@;'
echo     "# "
if [[ -e $usr_share_wiki_path ]]; then 
echo     "# Information: the following wikis using the same setup. So take really care of what you do ;-) ..."
echo     "# (May be you need a maintenace update hereinafter as well)"
echo     "#   $usr_share_wiki_path"
  # avoid error messages 2>/dev/null
  find -L /var/www/ -maxdepth 3 -samefile $usr_share_wiki_path/index.php -exec dirname '{}' ';' 2>/dev/null | sort | awk '{print "#   " NR " -> " $0}'
fi
 
CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l)
if [[ ! $CAN_I_RUN_SUDO -gt 0 ]]; then
echo     "# "
echo -e  "# The script was stopped because it \e[1mrequires sudo\e[0m running without promt. It will fail to work now. Please run any sudo"
echo     "# action before to have sudo action available without password prompt, e.g. list directory as sudo"
echo -e  "#   \e[1msudo ls\e[0m"
echo     "# "
exit 1
fi
 
[[ -e $usr_share_skins_path ]] && \
echo -ne "# Do you want to upgrade (\e[32m$usr_share_skins_path\e[0m)?\n[yes or no (default: no)]: " || \
echo -ne "# Do you want to create (\e[32m$usr_share_skins_path\e[0m)?\n[yes or no (default: no)]: "
read yno
case $yno in
  [yY]|[yY][Ee][Ss])
    echo "Continue ..."
  ;;
  [nN]|[nN][oO])
    echo "Stop";
    exit 1
  ;;
  *) echo "Invalid or no input (stop)"
    exit 1
  ;;
esac
 
 
##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
if [ ! -d "${usr_share_skins_path}" ];then
  echo "# Create ${usr_share_skins_path} ..."
  sudo -u root -g mwadmin mkdir --parents "${usr_share_skins_path}"
else
  echo "# Update skins in ${usr_share_skins_path} ..."
fi
 
# --
# split line at ", ". If only one value, export global git_tag_or_branch, else first value is branch/tag. Example:
#   Vector, 1.8
#      ↓                   ↓
#   $this_skin, $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
# ${skin%,*}    check from end       of $skin → delete shortest (%) or longest (%%) match
# ${skin#*,* }  check from beginning of $skin → delete shortest (#) or longest (##) match
# --------------------------------------
 
this_skin_update_status=""
IFS=$'\n'; # IFS=script (I)nternal (F)ield (S)eparator -> set to newline
i_skin=1; n_skin=` echo "$SKINS" | wc --lines`
do_substitute_with_originMaster="" # empty or any value
 
for skin in $SKINS; do
  # test zero string length
  if [[ ! -z ${skin// /} ]];then
    this_skin=$([ "${skin%,*}" == "$skin" ] && echo "$skin" || echo "${skin%%,*}");
    this_clone_version=$([ "${skin%,*}" == "$skin" ] && echo "$git_tag_or_branch" || echo "${skin#*, *}");
    if ! [[ -d /usr/share/mw-wmf-clone/skins/${this_skin} ]]; then
      echo -e "#   Shared skin resource: \e[31m/usr/share/mw-wmf-clone/skins/${this_skin}\e[0m \e[1mDOES NOT EXIST AS GIT SOURCE\e[0m"
      echo    "#     Read documentation https://www.mediawiki.org/wiki/Skin:$this_skin";
      echo    "#     check the skin's name or path or it may be an external skin (skipped)";
    else
      if [[ ! -d ${usr_share_skins_path}/${this_skin} ]]; then
        this_skin_update_status="+";
        sudo mkdir --parents "${usr_share_skins_path}/${this_skin}";
      else
        this_skin_update_status="u";
      fi;
      echo "# "
      printf "#   Shared skin resource: %03s of %03s: %1s %-30s (tag or branch: %s)\n" $i_skin $n_skin $this_skin_update_status $this_skin $this_clone_version;
      if [[ -d /usr/share/mw-wmf-clone/skins/${this_skin} ]]; then
        cd "/usr/share/mw-wmf-clone/skins/${this_skin}";
        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"` -eq 0 ]]; then
          if  [[ `echo "$AVAILABLE_TAGS_VERSIONS" | grep --count "$this_clone_version"` -eq 0 ]]; then
            echo -e "#   \e[31mClone version of tag or branch $this_clone_version of $this_skin is not available!!\e[0m";
            echo    "#   Check available branches:";
            echo    "#     cd /usr/share/mw-wmf-clone/skins/${this_skin} && git branch --remotes  | sort --version-sort";
            echo    "$AVAILABLE_remoteBRANCH_VERSIONS" | column -c 100;
            echo    "#   Check available tags:";
            echo    "#     cd /usr/share/mw-wmf-clone/skins/${this_skin} &&  git tag --list  | sort --version-sort";
            echo    "$AVAILABLE_TAGS_VERSIONS" | column -c 100;
            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 HEAD | sudo -u root -g mwadmin tar --extract --recursive-unlink --overwrite --directory=/usr/share/mediawiki25/skins          
          echo "#     sudo git archive \"$this_clone_version\"" 
          sudo git archive "$this_clone_version" | sudo -u root -g mwadmin tar --extract \
          --recursive-unlink \
          --overwrite --directory="${usr_share_skins_path}/${this_skin}";
          # VE-check fi
        else
          echo -e "#     $this_clone_version of ${this_skin} not available, \e[31mSUBSTITUTE with origin/master\e[0m"
          sudo git archive "origin/master" | sudo -u root -g mwadmin tar --extract \
          --recursive-unlink \
          --overwrite --directory="${usr_share_skins_path}/${this_skin}";
        fi
      else
        echo -e "#     Warning '\e[31m/usr/share/mw-wmf-clone/skins/${this_skin}\e[0m' not found!! Check skin name or git pull (skipped this step)";
      fi;
    fi;
  fi;
  i_skin=$((i_skin + 1))
done;
cd ..
IFS=$' \t\n'; # reset IFS=script (I)nternal (F)ield (S)eparator
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
 
echo    "# (done)"