Mediawiki installation/create or upgrade vhost-wiki.sh

From Biowikifarm Metawiki
< Mediawiki installation
Revision as of 22:59, 25 January 2016 by Andreas Plank (Talk | contribs) (Created page with "Run this as a script <code>{{SUBPAGENAMEE}}</code> not via copy and paste!!! The skript is interactive prompts before running. The concept is to have two different setups, one...")

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

Run this as a script create_or_upgrade_vhost-wiki.sh not via copy and paste!!! The skript is interactive prompts before running. The concept is to have two different setups, one for simple feature-wikis and one for rich feature-wikis.

  • it takes care of /cache, /media if not specified in the script
  • needs an existing /usr/share/mediawikiXXX ready to use shared wiki resource (see create or upgrade vhost-wiki.sh/upgrade shared wiki-core-resource-structure.sh)

For the different needed features the script needs one of the following structures in /usr/share/mediawikiXXX:

/usr/share/mediawiki27wmf                   v-host-wiki
├── extensions-rich-features/            -> ├── extensions/        
├── vendor-rich-features/                -> ├── vendor/            
├── composer-rich-features.json          -> ├── composer.json      
├── composer-rich-features.local.json    -> ├── composer.local.json (manage composer extensions here!!)
└── composer-rich-features.lock          -> └── composer.lock      

/usr/share/mediawiki27wmf                   v-host-wiki
├── extensions-simple-features/          -> ├── extensions/        
├── vendor-simple-features/              -> ├── vendor/            
├── composer-simple-features.json        -> ├── composer.json      
├── composer-simple-features.local.json  -> ├── composer.local.json (manage composer extensions here!!)
└── composer-simple-features.lock        -> └── composer.lock      

To get a symlinked v-host-wiki functioning make sure to set up:

# LocalSettings.php
putenv('MW_INSTALL_PATH=/path/to/v-host-wiki');"

Otherwise the update.php will not work.


Bash script: create_or_upgrade_vhost-wiki.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_vhost-wiki.sh # add executable mode for the owned user
#!/bin/bash
################################### 
# Create or upgrade a vhost-wiki from shared resources
# @dependencies: upgrade_shared_wiki-core-resource-structure.sh
# @dependencies: is written for wikis with a setup of composer.json, composer.local.json (MW1.23+)
# @dependencies: a correctly setup set up in /usr/share/mediawikiXXX
#    it depends on simple-features or rich-features set up of the /usr/share/mediawikiXXX
#    /usr/share/mediawiki27wmf                   v-host-wiki
#    ├── extensions-rich-features/            -> ├── extensions/        
#    ├── vendor-rich-features/                -> ├── vendor/            
#    ├── composer-rich-features.json          -> ├── composer.json      
#    ├── composer-rich-features.local.json    -> ├── composer.local.json (manage composer extensions here!!)
#    └── composer-rich-features.lock          -> └── composer.lock      
#    
#    /usr/share/mediawiki27wmf                   v-host-wiki
#    ├── extensions-simple-features/          -> ├── extensions/        
#    ├── vendor-simple-features/              -> ├── vendor/            
#    ├── composer-simple-features.json        -> ├── composer.json      
#    ├── composer-simple-features.local.json  -> ├── composer.local.json (manage composer extensions here!!)
#    └── composer-simple-features.lock        -> └── composer.lock      
#    
# Note short conditional syntax:
# [[ test condition ]] && echo "condition true"
# [[ test condition ]] && echo "condition true" || echo "condition false"
# Note long conditional syntax:
# if [[ test condition ]]; then echo "condition true"; else echo "condition false";

################################### 
# Start: global variables settings
usr_share_wiki_path="/usr/share/mediawiki27wmf"
setup_case="rich-features" # either "rich-features" or "simple-features"
# TODO setup_case="test-features" # a testwiki could use 3rd setting: the normal /extensions /vendor composer.json etc.

# cache, media: running as upgrade the script transfers old cache and media to upgraded wiki folder automatically
vhost_wiki_cache_path="" # empty (=local folder) or fully specified, e.g: /mnt/dump/var/www/testwiki-cache
vhost_wiki_media_path="" # empty (=local folder) or fully specified, e.g: /mnt/storage/var-www-testwiki-media

# in web base dir
vhost_wiki_path="/var/www/testwiki2"

# End: global variables settings
################################### 
# get actual modification time or today's date
[[ -e "$vhost_wiki_path" ]] && \
  backupdate=`stat --format=%Y "$vhost_wiki_path" | awk '{print strftime("%Y%m%d_%H%M", $1)}'` || \
  backupdate=`date '+%Y%m%d_%H%M'`

# bakup path if any
[[ -e "$vhost_wiki_path" ]] && \
  vhost_wiki_backup_path="${vhost_wiki_path}_${backupdate}" || \
  vhost_wiki_backup_path=""

# wiki template to get substituted later by real wiki
vhost_wiki_template_path="${vhost_wiki_path}_upgrade_template" # 

# cache path
if [[ -z ${vhost_wiki_cache_path// /} ]];then # string length really zero ? no path given
  [[ -d $vhost_wiki_path/cache  ]] && \
    vhost_wiki_cache_target=`realpath "$vhost_wiki_path/cache"` || \
    vhost_wiki_cache_target="$vhost_wiki_path/cache"
else
  [[ -e $vhost_wiki_cache_path ]] && \
    vhost_wiki_cache_target=`realpath $vhost_wiki_cache_path` || \
    vhost_wiki_cache_target=$vhost_wiki_cache_path
fi
# media path
if [[ -z ${vhost_wiki_media_path// /} ]];then # string length really zero ? path not given
  [[ -d $vhost_wiki_path/media  ]] && \
    vhost_wiki_media_target=`realpath "$vhost_wiki_path/media"` || \
    vhost_wiki_media_target="$vhost_wiki_path/media"
else
  [[ -e $vhost_wiki_media_path ]] && \
    vhost_wiki_media_target=`realpath $vhost_wiki_media_path`
    vhost_wiki_media_target=$vhost_wiki_media_path
fi

# prompt before start
# │├ ─ └ 
echo     "################################################################"
echo     "# Create or upgrade a vhost-wiki from shared resources"
echo     "#---------------------------------------------------------------"
echo     "# $usr_share_wiki_path"
echo     "#  "
echo     "#  | (shared resource above is symlinked to)"
echo     "#  V"
echo     "#  "
echo     "# $vhost_wiki_path"
printf   "# ├─ %-50s %-s\n" "/${vhost_wiki_template_path##*/}"                            "(step 1: set up new template)"
[[ -e $vhost_wiki_path ]] && \
printf   "# ├─ %-50s %-s\n" "/${vhost_wiki_path##*/} -> /${vhost_wiki_backup_path##*/}"   "(step 2: backup wiki folder)" || \
printf   "# ├─ %-50s %-s\n" "/${vhost_wiki_path##*/}"                                     "(step 2: create wiki folder from template, joint with step 3)"

printf   "# └─ %-50s %-s\n" "/${vhost_wiki_template_path##*/} -> /${vhost_wiki_path##*/}" "(step 3: substitute template to wiki)"
[[ -e $vhost_wiki_path ]] && \
printf   "#    │ %-48s %-s\n" "" "(step 4: transfer old LocalSettings.php, cache, media from backup copy )" || \
printf   "#    │ %-48s %-s\n" "" "(step 4: handle LocalSettings.php, cache, media)"

echo     "#    ├─ /cache target: ${vhost_wiki_cache_target}"
echo     "#    ├─ /media target: ${vhost_wiki_media_target}"
echo     "#    └─ LocalSettings.php (must be checked or edited afterwards manually)"
echo     "# "

case "$setup_case" in
simple-features)
  echo -e  "# Is structure of $usr_share_wiki_path ready in place for setup case of «\e[31m$setup_case\e[0m»?:"
  printf   "#   %-41s %s\n" "$usr_share_wiki_path" "$vhost_wiki_path"
  [[ -e $usr_share_wiki_path/extensions-simple-features ]] && \
  echo  -e "#   ├─  \e[0;32m/extensions-simple-features\e[0m         -> ├─ /extensions        " || \
  echo  -e "#   ├─  \e[1;31m/extensions-simple-features\e[0m         -> ├─ /extensions        (missing resource)"

  [[ -e $usr_share_wiki_path/vendor-simple-features ]] && \
  echo  -e "#   ├─  \e[0;32m/vendor-simple-features\e[0m             -> ├─ /vendor            " || \
  echo  -e "#   ├─  \e[1;31m/vendor-simple-features\e[0m             -> ├─ /vendor            (missing resource)"

  [[ -e $usr_share_wiki_path/composer-simple-features.json ]] && \
  echo  -e "#   ├─  \e[0;32mcomposer-simple-features.json\e[0m       -> ├─ composer.json      " || \
  echo  -e "#   ├─  \e[1;31mcomposer-simple-features.json\e[0m       -> ├─ composer.json      (missing resource)"

  [[ -e $usr_share_wiki_path/composer-simple-features.lock ]] && \
  echo  -e "#   ├─  \e[0;32mcomposer-simple-features.lock\e[0m       -> ├─ composer.lock      " || \
  echo  -e "#   ├─  \e[1;31mcomposer-simple-features.lock\e[0m       -> ├─ composer.lock      (missing resource)"

  [[ -e $usr_share_wiki_path/composer-simple-features.local.json ]] && \
  echo  -e "#   └─  \e[0;32mcomposer-simple-features.local.json\e[0m -> └─ composer.local.json" || \
  echo  -e "#   └─  \e[1;31mcomposer-simple-features.local.json\e[0m -> └─ composer.local.json (missing resource)"
;;

rich-features)
  echo -e  "# Is structure of $usr_share_wiki_path ready in place for setup case of «\e[31m$setup_case\e[0m»?:"
  printf   "#   %-41s %s\n" "$usr_share_wiki_path" "$vhost_wiki_path"
  [[ -e  $usr_share_wiki_path/extensions-rich-features ]] && \
  echo  -e "#   ├─  \e[0;32m/extensions-rich-features\e[0m           -> ├─ /extensions        " || \
  echo  -e "#   ├─  \e[1;31m/extensions-rich-features\e[0m           -> ├─ /extensions        (missing resource)"

  [[ -e  $usr_share_wiki_path/vendor-rich-features ]] && \
  echo  -e "#   ├─  \e[0;32m/vendor-rich-features\e[0m               -> ├─ /vendor            " || \
  echo  -e "#   ├─  \e[1;31m/vendor-rich-features\e[0m               -> ├─ /vendor            (missing resource)"

  [[ -e  $usr_share_wiki_path/composer-rich-features.json ]] && \
  echo  -e "#   ├─  \e[0;32mcomposer-rich-features.json\e[0m         -> ├─ composer.json      " || \
  echo  -e "#   ├─  \e[1;31mcomposer-rich-features.json\e[0m         -> ├─ composer.json      (missing resource)"

  [[ -e  $usr_share_wiki_path/composer-rich-features.lock ]] && \
  echo  -e "#   ├─  \e[0;32mcomposer-rich-features.lock\e[0m         -> ├─ composer.lock      " || \
  echo  -e "#   ├─  \e[1;31mcomposer-rich-features.lock\e[0m         -> ├─ composer.lock      (missing resource)"

  [[ -e  $usr_share_wiki_path/composer-rich-features.local.json ]] && \
  echo  -e "#   └─  \e[0;32mcomposer-rich-features.local.json\e[0m   -> └─ composer.local.json" || \
  echo  -e "#   └─  \e[1;31mcomposer-rich-features.local.json\e[0m   -> └─ composer.local.json (missing resource)"
;;

*)
  echo     "#   Unknown setup case. Please specify a setup_case in the bash script variables section:"
  echo     "#    setup_case=\"simple-features\" or \"rich-features\""
  echo     "#    (stop here)"
  exit 1
;;
esac
# end case simple rich features

# prompt User
echo     "#   "
[[ -e $vhost_wiki_path ]] && \
echo -ne "# Do you want to upgrade vhost-wiki $vhost_wiki_path ?\n[yes or no (default: no)]: " || \
echo -ne "# Do you want to create vhost-wiki $vhost_wiki_path ?\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


##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# STEP 1 wiki template folder
if [[ -d $vhost_wiki_template_path ]]; then 
  echo -e "# vhost-Wiki (1: set up new template): '$vhost_wiki_template_path' exists (empty it completely)"
  sudo -u root rm --recursive "${vhost_wiki_template_path}/*"
else
  echo    "# vhost-Wiki (1: set up new template): create template folder $vhost_wiki_template_path"
  sudo -u root -g mwadmin mkdir --parent "$vhost_wiki_template_path"
fi

# step 1 setup template: symbolic links folders
cd "${usr_share_wiki_path}"
# \( ! -name '.*' \) avoids finding hidden directories
for this_wiki_folder in `find . -maxdepth 1 \( ! -name '.*' \) -type d -printf "%f\n"`; do
  # skip the following
  [[ $this_wiki_folder == cache ]] && continue;
  [[ $this_wiki_folder == images ]] && continue;
  [[ $this_wiki_folder == extensions ]] && continue;
  [[ $this_wiki_folder == vendor ]] && continue;
  case "${setup_case}" in
  simple-features)
    # skip the following
    [[ $this_wiki_folder == *-rich-features* ]] && continue;
  ;;
  rich-features)
    # skip the following
    [[ $this_wiki_folder == *-simple-features* ]] && continue;
  ;;
  esac
  
  echo "#   symbolic link (folder):"
  case "$setup_case" in
  simple-features)
    [[ $this_wiki_folder == extensions-simple-features ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_folder}" "$vhost_wiki_template_path/extensions" && \ 
        echo  "#   ${usr_share_wiki_path}/${this_wiki_folder} -> $vhost_wiki_template_path/extensions"  && continue;
    [[ $this_wiki_folder == vendor-simple-features ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_folder}" "$vhost_wiki_template_path/vendor" && \ 
        echo  "#   ${usr_share_wiki_path}/${this_wiki_folder} -> $vhost_wiki_template_path/vendor"  && continue;
  ;;
  rich-features)
    [[ $this_wiki_folder == extensions-rich-features ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_folder}" "$vhost_wiki_template_path/extensions" && \ 
        echo  "#   ${usr_share_wiki_path}/${this_wiki_folder} -> $vhost_wiki_template_path/extensions" && continue;
    [[ $this_wiki_folder == vendor-rich-features ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_folder}" "$vhost_wiki_template_path/vendor" && \ 
        echo  "#   ${usr_share_wiki_path}/${this_wiki_folder} -> $vhost_wiki_template_path/vendor" && continue;
  ;;
  esac
  
  sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_folder}" "$vhost_wiki_template_path/${this_wiki_folder}" && \ 
    echo  "   ${usr_share_wiki_path}/${this_wiki_folder} -> $vhost_wiki_template_path/$this_wiki_folder"
done

# step 1 setup template: symbolic links files
cd "${usr_share_wiki_path}"
# \( ! -name '.*' \) avoids finding hidden directories
for this_wiki_file in `find . -maxdepth 1 \( ! -name '.*' \) -type f -printf "%f\n"`; do
  case "${setup_case}" in
  simple-features)
    # skip all *-rich-features*
    [[ $this_wiki_file == *-rich-features* ]] && continue;
  ;;
  rich-features)
    # skip all *-simple-features*
    [[ $this_wiki_file == *-simple-features* ]] && continue;
  ;;
  esac
  
  echo "#   symbolic link (file):"
  case "${setup_case}" in
  simple-features)
    [[ $this_wiki_file == composer-simple-features.json ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_file}" "${vhost_wiki_template_path}/composer.json" && \
      echo "#   ${vhost_wiki_template_path}/${this_wiki_file} -> ${vhost_wiki_template_path}/composer.json" && continue;
    [[ $this_wiki_file == composer-simple-features.lock ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_file}" "${vhost_wiki_template_path}/composer.lock" && \
      echo "#   ${vhost_wiki_template_path}/${this_wiki_file} -> ${vhost_wiki_template_path}/composer.lock" && continue;
    [[ $this_wiki_file == composer-simple-features.local.json ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_file}" "${vhost_wiki_template_path}/composer.local.json" && \
      echo "#   ${vhost_wiki_template_path}/${this_wiki_file} -> ${vhost_wiki_template_path}/composer.local.json" && continue;
  ;;
  rich-features)
    [[ $this_wiki_file == composer-rich-features.json ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_file}" "${vhost_wiki_template_path}/composer.json" && \
      echo "#   ${vhost_wiki_template_path}/${this_wiki_file} -> ${vhost_wiki_template_path}/composer.json" && continue;
    [[ $this_wiki_file == composer-rich-features.lock ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_file}" "${vhost_wiki_template_path}/composer.lock" && \
      echo "#   ${vhost_wiki_template_path}/${this_wiki_file} -> ${vhost_wiki_template_path}/composer.lock" && continue;
    [[ $this_wiki_file == composer-rich-features.local.json ]] && \
      sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_file}" "${vhost_wiki_template_path}/composer.local.json" && \
      echo "#   ${vhost_wiki_template_path}/${this_wiki_file} -> ${vhost_wiki_template_path}/composer.local.json" && continue;
  ;;
  esac

  echo "#   ${vhost_wiki_template_path}/${this_wiki_file} -> ${vhost_wiki_template_path}/${this_wiki_file}"
  sudo ln --symbolic --force "${usr_share_wiki_path}/${this_wiki_file}" "${vhost_wiki_template_path}/${this_wiki_file}"
done
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# step 2: backup or create wiki folder
if [[ -z ${vhost_wiki_backup_path// /} ]]; then 
  echo    "# vhost-Wiki (2: create folder) '$vhost_wiki_path' from '$vhost_wiki_template_path'"
else
  echo    "# vhost-Wiki (2: backup wiki) '$vhost_wiki_path' -> '$vhost_wiki_backup_path'"
  sudo -u root -g mwadmin mv "$vhost_wiki_path" "$vhost_wiki_backup_path"
fi
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# step 3: substitute template to wiki
if [[ -e $vhost_wiki_template_path ]];then
  echo    "# vhost-Wiki (3: substitute template to wiki) '$vhost_wiki_template_path' to '$vhost_wiki_path'"
  sudo -u root -g mwadmin mv "$vhost_wiki_template_path" "$vhost_wiki_path"
else
  echo    "# vhost-Wiki (3: substitute template to wiki) '$vhost_wiki_template_path' to '$vhost_wiki_path'"
  echo -e "#   \e[1;31mWarning: template folder does not exist $vhost_wiki_template_path\e[0m"
  echo -e "#   \e[1;31mto create $vhost_wiki_path. Something went wrong (stop)\e[0m"
  exit 1;
fi

# step 3: substitute (upgrade-case: backup exists, create-case: no backup exist)
[[ -e $vhost_wiki_backup_path ]] && \
printf   "# vhost-Wiki %-50s\n" "(4: transfer old LocalSettings.php, cache, media)" || \
printf   "# vhost-Wiki %-50s\n" "(4: create LocalSettings.php, cache, media)"
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

##↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# step 4 LocalSettings, cache, media
# cache
echo "#   check for /cache ..."
if [[ -z ${vhost_wiki_cache_path// /} ]];then # string length really zero ? path not given
  if [[ -d $vhost_wiki_backup_path/cache  ]]; then
    [[ -d $vhost_wiki_path/cache  ]] && \
      sudo -u root -g mwadmin mv --recursive "$vhost_wiki_path/cache" "$vhost_wiki_path/cache_BACKUP_OR_DELETE_ME" && \
      echo "#   move existing cache to backup: $vhost_wiki_path/cache -> $vhost_wiki_path/cache_BACKUP_OR_DELETE_ME"

    echo "#   copy $vhost_wiki_backup_path/cache -> $vhost_wiki_path/cache"
    sudo -u root -g mwadmin cp --recursive "$vhost_wiki_backup_path/cache" "$vhost_wiki_path/" # cp symlinked or folder
    sudo -u root -g mwadmin chown --recursive chown www-data:www-data  "$vhost_wiki_path/cache"
  else
    [[ -d $vhost_wiki_path/cache  ]] && \
      sudo -u root -g mwadmin mv --recursive "$vhost_wiki_path/cache" "$vhost_wiki_path/cache_BACKUP_OR_DELETE_ME" && \
      echo "#   move existing /cache to backup: $vhost_wiki_path/cache -> $vhost_wiki_path/cache_BACKUP_OR_DELETE_ME"

    echo "#   create $vhost_wiki_path/cache"
    sudo -u root -g mwadmin mkdir --parent "$vhost_wiki_path/cache"
    sudo -u root -g mwadmin chown --recursive chown www-data:www-data  "$vhost_wiki_path/cache"
  fi
else
  [[ -d $vhost_wiki_backup_path/cache  ]] && \
    echo "#   use $vhost_wiki_cache_path instead of existing /cache from old wiki (see $vhost_wiki_backup_path/cache)"

  [[ ! -e $vhost_wiki_cache_path ]] && \
    sudo -u root -g mwadmin mkdir --parent "$vhost_wiki_cache_path" && \
    sudo -u root -g mwadmin chown --recursive chown www-data:www-data  "$vhost_wiki_cache_path" && \
    echo "#   created $vhost_wiki_cache_path"
    
  echo "#   link $vhost_wiki_cache_path -> ${vhost_wiki_path}/cache"
  sudo ln --symbolic --force "$vhost_wiki_cache_path" "${vhost_wiki_path}/cache"
fi
# media
echo "#   check for /media ..."
if [[ -z ${vhost_wiki_media_path// /} ]];then # string length really zero ? path not given
  if [[ -d $vhost_wiki_backup_path/media  ]]; then
    [[ -d $vhost_wiki_path/media  ]] && \
      sudo -u root -g mwadmin mv --recursive "$vhost_wiki_path/media" "$vhost_wiki_path/media_BACKUP_OR_DELETE_ME" && \
      echo "#   move existing /media to backup: $vhost_wiki_path/media -> $vhost_wiki_path/media_BACKUP_OR_DELETE_ME"

    echo "#   copy $vhost_wiki_backup_path/media -> $vhost_wiki_path/media"
    sudo -u root -g mwadmin cp --recursive "$vhost_wiki_backup_path/media" "$vhost_wiki_path/" # cp symlinked or folder
    sudo -u root -g mwadmin chown --recursive chown www-data:www-data  "$vhost_wiki_path/media"
  else
    [[ -d $vhost_wiki_path/media  ]] && \
      sudo -u root -g mwadmin mv --recursive "$vhost_wiki_path/media" "$vhost_wiki_path/media_BACKUP_OR_DELETE_ME" && \
      echo "#   move existing media to backup: $vhost_wiki_path/media -> $vhost_wiki_path/media_BACKUP_OR_DELETE_ME"

    echo "#   create $vhost_wiki_path/media"
    sudo -u root -g mwadmin mkdir --parent "$vhost_wiki_path/media"
    sudo -u root -g mwadmin chown --recursive chown www-data:www-data  "$vhost_wiki_path/media"
  fi
else
  [[ -d $vhost_wiki_backup_path/media  ]] && \
    echo "#   use $vhost_wiki_media_path instead of existing /media from old wiki (see $vhost_wiki_backup_path/media) ..."

  [[ ! -e $vhost_wiki_media_path ]] && \
    sudo -u root -g mwadmin mkdir --parent "$vhost_wiki_media_path" && \
    sudo -u root -g mwadmin chown --recursive chown www-data:www-data  "$vhost_wiki_media_path" && \
    echo "#   created $vhost_wiki_media_path"
    
  echo "#   link $vhost_wiki_media_path -> ${vhost_wiki_path}/media ..."
  sudo ln --symbolic --force "$vhost_wiki_media_path" "${vhost_wiki_path}/media"
fi


# LocalSettings.php
if [[ -e $vhost_wiki_backup_path/LocalSettings.php ]];then
  echo "#   transfer old LocalSettings.php to ${vhost_wiki_path} ..."
  sudo -u root -g mwadmin cp --interactive "$vhost_wiki_backup_path/LocalSettings.php" "$vhost_wiki_path"
fi

if [[ ! -e $vhost_wiki_path/LocalSettings.php ]];then
  sudo -u root -g mwadmin touch "$vhost_wiki_path/LocalSettings.php"
  echo "#   created empty ${vhost_wiki_path}/LocalSettings.php ..."
  echo "#   make settings manually in LocalSettings.php read also RELEASE NOTES"
else
  echo "#   Read also RELEASE NOTES"
fi
echo    "#   (Done)"
echo    "# You can cd to wiki directory and check its structure using:"
echo    "   cd $vhost_wiki_path && ls -lp # or"
echo -e "   cd $vhost_wiki_path && tree -p -u -g -F -L 1 # \e[1mp\e[0m:permission \e[1mu\e[0m:user \e[1mg\e[0m:group \e[1mF\e[0m:append directory-slash/ \e[1mL\e[0m:levels-down"
##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑