|  | #!/bin/bash
# @name: solr_import.sh
# @version: 0.1
# @creation_date: 2022-03-11
# @license: The MIT License <https://opensource.org/licenses/MIT>
# @author: Simon Bowie <ad7588@coventry.ac.uk>
# @purpose: Runs imports of files into Solr indexes
# @acknowledgements:
# https://www.redhat.com/sysadmin/arguments-options-bash-scripts
############################################################
# Subprograms                                              #
############################################################
License()
{
  echo 'Copyright 2022 Simon Bowie <ad7588@coventry.ac.uk>'
  echo
  echo 'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:'
  echo
  echo 'The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.'
  echo
  echo 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'
}
Help()
{
   # Display Help
   echo "This script performs Solr import functions for different cores."
   echo
   echo "Syntax: solr_import.sh [-m|h|a|b]"
   echo "options:"
   echo "l     Print the MIT License notification."
   echo "h     Print this Help."
   echo "z     Index all."
   echo "a     Index ACTIVE folder."
   echo "e     Index EXPANDING folder."
   echo "i     Index INVISIBLE folder."
   echo "m     Index MULTI-SPECIES folder."
   echo "s     Index SURVIVING folder."
   echo
}
Import()
{
  docker exec -it solr solr create_core -c $core
  docker exec -ti --user=solr solr bash -c "cp -r /opt/solr/example/files/conf/* /var/solr/data/$core/conf/"
  docker restart solr
  sleep 30
  docker run --rm -v "/Users/ad7588/$location:/$core" --network=host solr:latest post -c $core /$core
}
############################################################
############################################################
# Main program                                             #
############################################################
############################################################
# Set variables
# Get the options
while getopts ":hlimzaes" option; do
   case $option in
      l) # display License
        License
        exit;;
      h) # display Help
        Help
        exit;;
      z) # index all
        core="all"
        location="Downloads/2018 (10381)"
        Import
        exit;;
      a) # index ACTIVE folder
        core="active"
        location="Downloads/pop_rtfs/ACTIVE (160)"
        Import
        exit;;
      e) # index EXPANDING folder
        core="expanding"
        location="Downloads/pop_rtfs/EXPANDING (169)"
        Import
        exit;;
      i) # index INVISIBLE folder
        core="invisible"
        location="Downloads/pop_rtfs/IN.VISIBLE (204)"
        Import
        exit;;
      m) # index MULTI-SPECIES folder
        core="multispecies"
        location="Downloads/pop_rtfs/MULTI-SPECIES (180)"
        Import
        exit;;
      s) # index SURVIVING folder
        core="surviving"
        location="Downloads/pop_rtfs/SURVIVING (166)"
        Import
        exit;;
      \?) # Invalid option
        echo "Error: Invalid option"
        exit;;
   esac
done
 |