Difference between revisions of "Extension:EmailToWiki/get EmailToWiki to extensions wmf-shared.sh"

From Biowikifarm Metawiki
Jump to: navigation, search
m
m (fix sudo)
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
#!/bin/bash
 
#!/bin/bash
 
######################################################
 
######################################################
# Warning: run this only as script not via copy and paste in console!!
+
# Warning: run this only as script not as
 +
# copy and paste in console!!
 
# Documentation: the script will download the extension  
 
# Documentation: the script will download the extension  
 
# into your home directory, extract it, creates some files
 
# into your home directory, extract it, creates some files
 
# set user rights according to https://www.mediawiki.org/wiki/Extension:EmailToWiki#Installation
 
# set user rights according to https://www.mediawiki.org/wiki/Extension:EmailToWiki#Installation
# and it needs sudo to be executed
+
# it needs sudo and prompt users to start. The script is interactive
 
######################################################
 
######################################################
  
 
################################### settings start
 
################################### settings start
 
# settings may be adjusted to your needs:
 
# settings may be adjusted to your needs:
usr_share_wiki_path="/usr/share/mediawiki27wmf"
+
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-simple-features"
 +
usr_share_extension_path="${usr_share_wiki_path}/extensions-rich-features"
 +
output_archive="OrganicDesign_extensions_master.zip"
 
################################### settings end
 
################################### settings end
  
Line 25: Line 28:
 
exit 1
 
exit 1
 
fi
 
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
 
# get external https://www.mediawiki.org/wiki/Extension:EmailToWiki
 
if ! [[  -d ~/temp  ]] ; then
 
if ! [[  -d ~/temp  ]] ; then
   echo "# Extension:EmailToWiki: create ~/temp"
+
   echo "#   create ~/temp"
 
   mkdir --parents ~"/temp"
 
   mkdir --parents ~"/temp"
 +
else
 +
  echo "#  use ~/temp"
 
fi
 
fi
  
echo "# Extension:EmailToWiki: download https://github.com/OrganicDesign/extensions/archive/master.zip"
+
echo "#   download https://github.com/OrganicDesign/extensions/archive/master.zip"
cd ~/temp && wget https://github.com/OrganicDesign/extensions/archive/master.zip --output-document=OrganicDesign_extensions_master.zip
+
cd ~/temp && wget https://github.com/OrganicDesign/extensions/archive/master.zip --output-document="$output_archive"
echo "# Extension:EmailToWiki: unzip OrganicDesign_extensions_master.zip"
+
if [[  -d ~/temp/extensions-master/MediaWiki/EmailToWiki/ ]] ; then
unzip OrganicDesign_extensions_master.zip
+
  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
 
if [[  -d ~/temp/extensions-master/MediaWiki/EmailToWiki/ ]] ; then
 
   cd ~/temp/extensions-master/MediaWiki/EmailToWiki/
 
   cd ~/temp/extensions-master/MediaWiki/EmailToWiki/
   echo "# Extension:EmailToWiki: add README.biowikifarm to extension"
+
   echo "#   add README.biowikifarm to extension"
 
   echo "###################################" > README.biowikifarm
 
   echo "###################################" > README.biowikifarm
 
   echo "# This is a non MediaWiki extension see: https://www.mediawiki.org/wiki/Extension:EmailToWiki#Installation" >> README.biowikifarm
 
   echo "# This is a non MediaWiki extension see: https://www.mediawiki.org/wiki/Extension:EmailToWiki#Installation" >> README.biowikifarm
Line 46: Line 104:
 
   echo "# deactivate and remove it. The configuration file EmailToWiki.conf should be owned by root (see documentation)" >> 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
 
   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 ]]
+
   if ! [[ -d ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.tmp ]];then
     echo "# Extension:EmailToWiki: add empty EmailToWiki.tmp directory "
+
     echo "#   add empty EmailToWiki.tmp directory "
 
     mkdir --parents ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.tmp
 
     mkdir --parents ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.tmp
 
   fi
 
   fi
   if ! [[ -e ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.log ]]
+
   if ! [[ -e ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.log ]];then
     echo "# Extension:EmailToWiki: add empty EmailToWiki.log file "
+
     echo "#   add empty EmailToWiki.log file "
 
     touch ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.log
 
     touch ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.log
 
   fi
 
   fi
   if [[ -e ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf.sample ]]
+
   if [[ -e ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf.sample ]];then
     echo "# Extension:EmailToWiki: copy sample configuration to EmailToWiki.conf file "
+
     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
 
     cp --interactive --preserve ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf.sample ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf
 
   fi
 
   fi
   echo "# Extension:EmailToWiki: set ownership to www-data, but EmailToWiki.conf to root"
+
   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 www-data:www-data --recursive ~/temp/extensions-master/MediaWiki/EmailToWiki  
 
   sudo chown root:root ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf
 
   sudo chown root:root ~/temp/extensions-master/MediaWiki/EmailToWiki/EmailToWiki.conf
  
   echo "# Extension:EmailToWiki: copy ~/temp/extensions-master/MediaWiki/EmailToWiki to ${usr_share_extension_path}"
+
   echo "#   copy ~/temp/extensions-master/MediaWiki/EmailToWiki to ${usr_share_extension_path}"
   sudo -u www-data -g www-data cp --preserve --recursive ~/temp/extensions-master/MediaWiki/EmailToWiki "${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
 
else
   unzip -l OrganicDesign_extensions_master.zip | grep --ignore-case 'emailtowiki'
+
   unzip -l "$output_archive" | grep --ignore-case 'emailtowiki'
   echo "# Extension:EmailToWiki: structure of ZIP archive is different from expected"
+
   echo "# structure of ZIP archive is different from expected"
   echo "# Extension:EmailToWiki: check above (skipped copy extension)"
+
   echo "# check above (exit now)"
 +
  exit 1
 
fi
 
fi
 
</syntaxhighlight>
 
</syntaxhighlight>
 
[[Category:Bash script]]
 
[[Category:Bash script]]

Latest revision as of 15:08, 7 July 2016

#!/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