Extension:EmailToWiki/get EmailToWiki to extensions wmf-shared.sh

From Biowikifarm Metawiki
< Extension:EmailToWiki
Revision as of 15:08, 7 July 2016 by Andreas Plank (Talk | contribs) (fix sudo)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#!/bin/bash
######################################################
# Warning: run this only as script not as 
# copy and paste in console!!
# Documentation: the script will download the extension 
# into your home directory, extract it, creates some files
# set user rights according to https://www.mediawiki.org/wiki/Extension:EmailToWiki#Installation
# it needs sudo and prompt users to start. The script is interactive
######################################################

################################### settings start
# settings may be adjusted to your needs:
usr_share_wiki_path="/usr/share/mediawiki26"
usr_share_extension_path="${usr_share_wiki_path}/extensions-simple-features"
usr_share_extension_path="${usr_share_wiki_path}/extensions-rich-features"
output_archive="OrganicDesign_extensions_master.zip"
################################### settings end

# prompt User
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 prompt. 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

echo "####################################"
echo "# Set up for Extension:EmailToWiki"
if ! [[ -d ${usr_share_extension_path} ]];then
  echo "#   Target directory '${usr_share_extension_path}' does not exist (exit now)"
  exit 1
fi

if [[ -d ${usr_share_extension_path}/EmailToWiki ]];then
  echo "#   found existing directory ${usr_share_extension_path}/EmailToWiki. Please remove or use it (exit now)"
  exit 1
fi

echo -ne "# Do you want to download and set up EmailToWiki to ${usr_share_extension_path}/EmailToWiki?\n[yes or no (default: no)]: " 
 
read yno
case $yno in
  [yY]|[yY][Ee][Ss])
    echo "Continue ..."
  ;;
  [nN]|[nN][oO])
    echo "Stop";
    exit 1
  ;;
  *)
    [[ -z ${yno// /} ]] && \
      echo "No input (stop)" || \
      echo "Invalid input: $yno -- only y, yes or n, no are valid. (stop)" 
    exit 1
  ;;
esac

# get external https://www.mediawiki.org/wiki/Extension:EmailToWiki
if ! [[  -d ~/temp  ]] ; then
  echo "#   create ~/temp"
  mkdir --parents ~"/temp"
else
  echo "#   use ~/temp"
fi

echo "#   download https://github.com/OrganicDesign/extensions/archive/master.zip"
cd ~/temp && wget https://github.com/OrganicDesign/extensions/archive/master.zip --output-document="$output_archive"
if [[  -d ~/temp/extensions-master/MediaWiki/EmailToWiki/ ]] ; then
  echo -ne "#   delete existing ~/temp/extensions-master before unzip?\n[yes or no (default: no -- will stop)]: " 
   
  read yno
  case $yno in
    [yY]|[yY][Ee][Ss])
      echo "Delete ..."
      sudo rm --recursive ~/temp/extensions-master
    ;;
    [nN]|[nN][oO])
      echo "Stop";
      exit 1
    ;;
    *)
      [[ -z ${yno// /} ]] && \
        echo "No input (stop)" || \
        echo "Invalid input: $yno -- only y, yes or n, no are valid. (stop)" 
      exit 1
    ;;
  esac
fi
echo "#   unzip $output_archive"
unzip "$output_archive"

if [[  -d ~/temp/extensions-master/MediaWiki/EmailToWiki/ ]] ; then
  cd ~/temp/extensions-master/MediaWiki/EmailToWiki/
  echo "#   add README.biowikifarm to extension"
  echo "###################################" > README.biowikifarm
  echo "# This is a non MediaWiki extension see: https://www.mediawiki.org/wiki/Extension:EmailToWiki#Installation" >> README.biowikifarm
  echo "# It was downloaded and extracted manually via wget  https://github.com/OrganicDesign/extensions/archive/master.zip " >> README.biowikifarm
  echo "#   wget  https://github.com/OrganicDesign/extensions/archive/master.zip " >> README.biowikifarm
  echo "# and copied manually to this shared wiki directory. If this extension does not function properly after setup" >> README.biowikifarm
  echo "# deactivate and remove it. The configuration file EmailToWiki.conf should be owned by root (see documentation)" >> README.biowikifarm
  echo "# not by www-data, it must be readable by the perlscript and cron. (AP 2016-07-07)" >> README.biowikifarm
  if ! [[ -d ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.tmp ]];then
    echo "#   add empty EmailToWiki.tmp directory "
    mkdir --parents ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.tmp
  fi
  if ! [[ -e ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.log ]];then
    echo "#   add empty EmailToWiki.log file "
    touch ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.log
  fi
  if [[ -e ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf.sample ]];then
    echo "#   copy sample configuration to EmailToWiki.conf file "
    cp --interactive --preserve ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf.sample ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf
  fi
  echo "#   set ownership to www-data, but EmailToWiki.conf to root"
  sudo chown www-data:www-data --recursive ~/temp/extensions-master/MediaWiki/EmailToWiki 
  sudo chown root:root ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf

  echo "#   copy ~/temp/extensions-master/MediaWiki/EmailToWiki to ${usr_share_extension_path}"
  sudo cp --preserve --recursive ~/temp/extensions-master/MediaWiki/EmailToWiki "${usr_share_extension_path}"

  echo "#   Remove archive $output_archive from download ..."
  rm -i ~/"temp/$output_archive"
  
  echo -en "#   Remove extracted directory ~/temp/extensions-master completely?\n[yes or no (default: no)]: "
  read yno
  case $yno in
    [yY]|[yY][Ee][Ss])
      echo -en " Delete ..."
       sudo rm --recursive ~/"temp/extensions-master"
    ;;
    [nN]|[nN][oO])
      echo "#   See perhaps temporary extracted files in ~/temp/extensions-master/MediaWiki/EmailToWiki/"
      # exit 1
    ;;
    *)
      echo "#   See perhaps temporary extracted files in ~/temp/extensions-master/MediaWiki/EmailToWiki/"
    ;;
  esac

  echo "#   Consult https://www.mediawiki.org/wiki/Extension:EmailToWiki for further readings."
  echo "#   (done)"
  
else
  unzip -l "$output_archive" | grep --ignore-case 'emailtowiki'
  echo "#  structure of ZIP archive is different from expected"
  echo "#  check above (exit now)"
  exit 1
fi