diff --git a/scripts/populate-instance.sh b/scripts/populate-instance.sh index d95fec292..bffb2a4fd 100755 --- a/scripts/populate-instance.sh +++ b/scripts/populate-instance.sh @@ -1,139 +1,134 @@ #!/usr/bin/env bash # # This file is part of Invenio. # Copyright (C) 2015, 2016 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # Invenio is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Invenio; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307, USA. # # In applying this license, CERN does not # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. # check environment variables: if [ -v ${INVENIO_WEB_HOST} ]; then echo "[ERROR] Please set environment variable INVENIO_WEB_HOST before runnning this script." echo "[ERROR] Example: export INVENIO_WEB_HOST=192.168.50.10" exit 1 fi if [ -v ${INVENIO_WEB_INSTANCE} ]; then echo "[ERROR] Please set environment variable INVENIO_WEB_INSTANCE before runnning this script." echo "[ERROR] Example: export INVENIO_WEB_INSTANCE=invenio3" exit 1 fi if [ -v ${INVENIO_WEB_VENV} ]; then echo "[ERROR] Please set environment variable INVENIO_WEB_VENV before runnning this script." echo "[ERROR] Example: export INVENIO_WEB_VENV=invenio3" exit 1 fi if [ -v ${INVENIO_USER_EMAIL} ]; then echo "[ERROR] Please set environment variable INVENIO_USER_EMAIL before runnning this script." echo "[ERROR] Example: export INVENIO_USER_EMAIL=info@inveniosoftware.org" exit 1 fi if [ -v ${INVENIO_USER_PASS} ]; then echo "[ERROR] Please set environment variable INVENIO_USER_PASS before runnning this script." echo "[ERROR] Example: export INVENIO_USER_PASS=uspass123" exit 1 fi if [ -v ${INVENIO_POSTGRESQL_HOST} ]; then echo "[ERROR] Please set environment variable INVENIO_POSTGRESQL_HOST before runnning this script." echo "[ERROR] Example: export INVENIO_POSTGRESQL_HOST=192.168.50.11" exit 1 fi if [ -v ${INVENIO_POSTGRESQL_DBNAME} ]; then echo "[ERROR] Please set environment variable INVENIO_POSTGRESQL_DBNAME before runnning this script." echo "[ERROR] Example: INVENIO_POSTGRESQL_DBNAME=invenio3" exit 1 fi if [ -v ${INVENIO_POSTGRESQL_DBUSER} ]; then echo "[ERROR] Please set environment variable INVENIO_POSTGRESQL_DBUSER before runnning this script." echo "[ERROR] Example: INVENIO_POSTGRESQL_DBUSER=invenio3" exit 1 fi if [ -v ${INVENIO_POSTGRESQL_DBPASS} ]; then echo "[ERROR] Please set environment variable INVENIO_POSTGRESQL_DBPASS before runnning this script." echo "[ERROR] Example: INVENIO_POSTGRESQL_DBPASS=dbpass123" exit 1 fi if [ -v ${INVENIO_REDIS_HOST} ]; then echo "[ERROR] Please set environment variable INVENIO_REDIS_HOST before runnning this script." echo "[ERROR] Example: export INVENIO_REDIS_HOST=192.168.50.12" exit 1 fi if [ -v ${INVENIO_ELASTICSEARCH_HOST} ]; then echo "[ERROR] Please set environment variable INVENIO_ELASTICSEARCH_HOST before runnning this script." echo "[ERROR] Example: export INVENIO_ELASTICSEARCH_HOST=192.168.50.13" exit 1 fi if [ -v ${INVENIO_RABBITMQ_HOST} ]; then echo "[ERROR] Please set environment variable INVENIO_RABBITMQ_HOST before runnning this script." echo "[ERROR] Example: export INVENIO_RABBITMQ_HOST=192.168.50.14" exit 1 fi if [ -v ${INVENIO_WORKER_HOST} ]; then echo "[ERROR] Please set environment variable INVENIO_WORKER_HOST before runnning this script." echo "[ERROR] Example: export INVENIO_WORKER_HOST=192.168.50.15" exit 1 fi # load virtualenvrapper: source $(which virtualenvwrapper.sh) # switch virtual environment: workon ${INVENIO_WEB_VENV} # quit on errors and unbound symbols: set -o errexit set -o nounset # sphinxdoc-create-database-begin ${INVENIO_WEB_INSTANCE} db init ${INVENIO_WEB_INSTANCE} db create # sphinxdoc-create-database-end # sphinxdoc-create-user-account-begin ${INVENIO_WEB_INSTANCE} users create \ ${INVENIO_USER_EMAIL} \ --password ${INVENIO_USER_PASS} \ --active # sphinxdoc-create-user-account-end # sphinxdoc-populate-with-demo-records-begin # discover the location of demo MARC21 record file: demomarc21pathname=$(echo "from __future__ import print_function; \ import pkg_resources; \ print(pkg_resources.resource_filename('invenio_records', \ 'data/marc21/bibliographic.xml'))" | python) -# count the number of demo MARC21 records: -demomarc21nbrecs=$(grep -c '' $demomarc21pathname) - # convert demo records from MARC21 to JSON and load them # using randomly generated UUIDs: -demouuids=$(dojson do -i $demomarc21pathname -l marcxml marc21 | \ - ${INVENIO_WEB_INSTANCE} records create \ - $(for i in $(seq 1 $demomarc21nbrecs); \ - do echo "-i " $(uuid); done)) +demouuids=$(dojson -i $demomarc21pathname -l marcxml do marc21 | \ + ${INVENIO_WEB_INSTANCE} records create) # sphinxdoc-populate-with-demo-records-end # sphinxdoc-register-pid-begin recid=1 for demouuid in $demouuids; do ${INVENIO_WEB_INSTANCE} pid create \ -t rec -i $demouuid -s REGISTERED recid $recid let recid=recid+1 done # sphinxdoc-register-pid-end diff --git a/scripts/provision-web.sh b/scripts/provision-web.sh index 970eae3b9..708e5c96f 100755 --- a/scripts/provision-web.sh +++ b/scripts/provision-web.sh @@ -1,231 +1,227 @@ #!/usr/bin/env bash # # This file is part of Invenio. # Copyright (C) 2015, 2016 CERN. # # Invenio is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # Invenio is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Invenio; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307, USA. # # In applying this license, CERN does not # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. # quit on errors: set -o errexit # quit on unbound symbols: set -o nounset # sphinxdoc-install-detect-sudo-begin # runs as root or needs sudo? if [[ "$EUID" -ne 0 ]]; then sudo='sudo' else sudo='' fi # sphinxdoc-install-detect-sudo-end # unattended installation: export DEBIAN_FRONTEND=noninteractive provision_web_common_ubuntu_trusty () { # sphinxdoc-install-useful-system-tools-trusty-begin # update list of available packages: $sudo apt-get -y update # install useful system tools: $sudo apt-get -y install \ curl \ git \ rlwrap \ screen \ vim - - # install uuid generator (useful for loading demo records): - $sudo apt-get -y install \ - uuid # sphinxdoc-install-useful-system-tools-trusty-end # sphinxdoc-add-nodejs-external-repository-trusty-begin if [[ ! -f /etc/apt/sources.list.d/nodesource.list ]]; then curl -sL https://deb.nodesource.com/setup_4.x | $sudo bash - fi # sphinxdoc-add-nodejs-external-repository-trusty-end # sphinxdoc-install-web-common-trusty-begin $sudo apt-get -y install \ libffi-dev \ libfreetype6-dev \ libjpeg-dev \ libmsgpack-dev \ libssl-dev \ libtiff-dev \ libxml2-dev \ libxslt-dev \ nodejs \ python-dev \ python-pip # sphinxdoc-install-web-common-trusty-end } provision_web_libpostgresql_ubuntu_trusty () { # sphinxdoc-install-web-libpostgresql-trusty-begin $sudo apt-get -y install \ libpq-dev # sphinxdoc-install-web-libpostgresql-trusty-end } provision_web_common_centos7 () { # sphinxdoc-install-useful-system-tools-centos7-begin # install useful system tools: $sudo yum install -y \ curl \ git \ rlwrap \ screen \ vim # install uuid generator (useful for loading demo records): $sudo yum install -y \ uuid # sphinxdoc-install-useful-system-tools-centos7-end # sphinxdoc-add-nodejs-external-repository-centos7-begin # add EPEL external repository: $sudo yum install -y epel-release # sphinxdoc-add-nodejs-external-repository-centos7-end # sphinxdoc-install-web-common-centos7-begin # install development tools: $sudo yum update -y $sudo yum groupinstall -y "Development Tools" $sudo yum install -y \ libffi-devel \ libxml2-devel \ libxslt-devel \ npm \ python-devel \ python-pip # sphinxdoc-install-web-common-centos7-end } provision_web_libpostgresql_centos7 () { # sphinxdoc-install-web-libpostgresql-centos7-begin $sudo yum install -y \ postgresql-devel # sphinxdoc-install-web-libpostgresql-centos7-end } setup_npm_and_css_js_filters () { # sphinxdoc-install-npm-and-css-js-filters-begin $sudo su -c "npm install -g npm" $sudo su -c "npm install -g node-sass clean-css requirejs uglify-js" # sphinxdoc-install-npm-and-css-js-filters-end } setup_virtualenvwrapper () { # disable quitting on errors due to virtualenvrapper: set +o errexit set +o nounset # sphinxdoc-install-virtualenvwrapper-begin $sudo pip install -U virtualenvwrapper pip if ! grep -q virtualenvwrapper ~/.bashrc; then mkdir -p $HOME/.virtualenvs echo "export WORKON_HOME=$HOME/.virtualenvs" >> $HOME/.bashrc echo "source $(which virtualenvwrapper.sh)" >> $HOME/.bashrc fi export WORKON_HOME=$HOME/.virtualenvs source $(which virtualenvwrapper.sh) # sphinxdoc-install-virtualenvwrapper-end # enable quitting on errors back: set -o errexit set -o nounset } cleanup_web_ubuntu_trusty () { # sphinxdoc-install-web-cleanup-trusty-begin $sudo apt-get -y autoremove && $sudo apt-get -y clean # sphinxdoc-install-web-cleanup-trusty-end } cleanup_web_centos7 () { # sphinxdoc-install-web-cleanup-centos7-begin $sudo yum clean -y all # sphinxdoc-install-web-cleanup-centos7-end } main () { # detect OS distribution and release version: if hash lsb_release 2> /dev/null; then os_distribution=$(lsb_release -i | cut -f 2) os_release=$(lsb_release -r | cut -f 2) elif [ -e /etc/redhat-release ]; then os_distribution=$(cat /etc/redhat-release | cut -d ' ' -f 1) os_release=$(cat /etc/redhat-release | grep -oE '[0-9]+\.' | cut -d. -f1 | head -1) else os_distribution="UNDETECTED" os_release="UNDETECTED" fi # call appropriate provisioning functions: if [ -f /.dockerinit ]; then # running inside Docker provision_web_common_ubuntu_trusty provision_web_libpostgresql_ubuntu_trusty setup_npm_and_css_js_filters setup_virtualenvwrapper cleanup_web_ubuntu_trusty elif [ "$os_distribution" = "Ubuntu" ]; then if [ "$os_release" = "14.04" ]; then provision_web_common_ubuntu_trusty provision_web_libpostgresql_ubuntu_trusty setup_npm_and_css_js_filters setup_virtualenvwrapper cleanup_web_ubuntu_trusty else echo "[ERROR] Sorry, unsupported release ${os_release}." exit 1 fi elif [ "$os_distribution" = "CentOS" ]; then if [ "$os_release" = "7" ]; then provision_web_common_centos7 provision_web_libpostgresql_centos7 setup_npm_and_css_js_filters setup_virtualenvwrapper cleanup_web_centos7 else echo "[ERROR] Sorry, unsupported release ${os_release}." exit 1 fi else echo "[ERROR] Sorry, unsupported distribution ${os_distribution}." exit 1 fi } main