From de3147527cae11e78677ed876f828cff8187d185 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 27 Jan 2017 10:11:27 +0100 Subject: Workon on install --- bin/chimere-create-instance | 267 ++++++++++++++++++++++++++++ bin/chimere-install | 420 ++++++++++++++++++++++++++++++++++++++++++++ bin/install-chimere.sh | 420 -------------------------------------------- 3 files changed, 687 insertions(+), 420 deletions(-) create mode 100755 bin/chimere-create-instance create mode 100755 bin/chimere-install delete mode 100755 bin/install-chimere.sh diff --git a/bin/chimere-create-instance b/bin/chimere-create-instance new file mode 100755 index 0000000..f20b36e --- /dev/null +++ b/bin/chimere-create-instance @@ -0,0 +1,267 @@ +#!/bin/bash + +# +# You can call this file interactively or pass environment variables. +# Available environment variable: +# * CONF_FILE - for an alternate configuration file - default: /etc/chimere/config +# * INSTANCE_NAME - name of the instance - mandatory for a non interactive call +# * URL - url - mandatory for a non interactive call +# + +conf_file=${CONF_FILE-"/etc/chimere/config"} + +if [ ! -e "$conf_file" ]; then + echo $conf_file" is not a valid configuration file. You should run chimere-install script before this one." + echo "If your configuration file is not at the standard place. Overload the default place with the environment variable: \"CONF_FILE\" " + echo "" + exit 1 +fi + +instance_name=${INSTANCE_NAME-""} + +if [ "$instance_name" == '' ]; then + cat >&2 <<-'EOF' + + ------------------------------------------------------------------------------- + You should provide an instance name for new instance Chimère. This name + should be in lower case, no special characters, no spaces. Underscores and + number are possible but not as first character. + + EOF + while [ "$instance_name" == '' ] + do + read -p "* What is your instance name? " choice + if [ "$choice" != '' ]; then + instance_name=$choice + fi + done +fi + +url=${URL-""} + +if [ "$url" == '' ]; then + cat >&2 <<-'EOF' + + ------------------------------------------------------------------------------- + Chimère uses a virtual host configuration. A specific hostname should be + provided, it will be the root of URLs for your website. + For instance, you should set "my_chimere.my_domain.net" to have a + Chimère responding to "http://my_chimere.my_domain.net/". + + Of course DNS configuration should be done to match this hostname with + this server. + + EOF + while [ "$url" == '' ] + do + read -p "* What hostname should be used? " choice + if [ "$choice" != '' ]; then + url=$choice + fi + done +fi + +source $conf_file + +DB_PORT=${DB_PORT-5432} + +UWSGI_PORT=${LAST_UWSGI_PORT-8891} + +# if a virtualenv is used put the full path of the python to use +PYTHON=python + + +# default for debian +UWSGI_AVAILABLE_PATH='/etc/uwsgi/apps-available/' +UWSGI_ENABLE_PATH='/etc/uwsgi/apps-enabled/' +NGINX_AVAILABLE_PATH='/etc/nginx/sites-available/' +NGINX_ENABLE_PATH='/etc/nginx/sites-enabled/' + + +echo "* installing dependencies" + +DB_PASSWORD=`apg -a 0 -M ncl -n 6 -x 10 -m 10 |head -n 1` + +DB_NAME='ishtar'$APP_NAME +INSTALL_PATH=$INSTALL_PREFIX$DB_NAME +DATE=`date +%F` +CDIR=`pwd` +SECRET_KEY=`apg -a 0 -M ncl -n 6 -x 10 -m 40 |head -n 1` + +if [ $DB_HOST = '127.0.0.1' ] +then + +echo "* create database and user" +DB_PASSWORD=$DB_PASSWORD DB_NAME=$DB_NAME PROJECT_NAME=$PROJECT_NAME PG_VERSION=$PG_VERSION su postgres <<'EOF' +cd +if [ `psql -l | grep template_postgis | wc -l` -ne 1 ]; then + echo " * create template_postgis" + createdb template_postgis + psql -d template_postgis -f /usr/share/postgresql/$PG_VERSION/contrib/postgis-1.5/postgis.sql 2> /dev/null > /dev/null + psql -d template_postgis -f /usr/share/postgresql/$PG_VERSION/contrib/postgis-1.5/spatial_ref_sys.sql 2> /dev/null > /dev/null + +fi +if [ `psql -l | grep $DB_NAME | wc -l` -ne 1 ]; then + echo " * create "$DB_NAME + createuser --echo --adduser --createdb --encrypted $DB_NAME 2> /dev/null > /dev/null + psql --command "ALTER USER \""$DB_NAME"\" with password '"$DB_PASSWORD"';" 2> /dev/null > /dev/null + createdb -T template_postgis --echo --owner $DB_NAME --encoding UNICODE $DB_NAME "$PROJECT_NAME" 2> /dev/null > /dev/null + +fi +EOF + +fi + + +echo '* get sources' + +mkdir $INSTALL_PATH +mkdir $INSTALL_PATH'/conf' +cd $INSTALL_PATH + +echo ' * ishtar' +git clone https://gitlab.com/iggdrasil/ishtar.git 2> /dev/null +# echo ' * oook!' +# git clone git://git.proxience.com/git/oook_replace.git 2> /dev/null +# ln -s $INSTALL_PATH'/oook_replace/oook_replace' $INSTALL_PATH'/ishtar/' + +cd ishtar +git fetch 2> /dev/null +git checkout $VERSION 2> /dev/null + +cd django-simple-history +python setup.py install +cd .. + +cp -ra example_project $APP_NAME 2> /dev/null > /dev/null + +rm $APP_NAME/settings.py +ln -s $INSTALL_PATH"/ishtar/example_project/settings.py" $INSTALL_PATH"/ishtar/"$APP_NAME"/" + +APP_DIR=$INSTALL_PATH'/ishtar/'$APP_NAME + +echo '* load parameters' +sed -s "s|#APP_NAME#|$APP_NAME|g;\ + s|#INSTALL_PATH#|$INSTALL_PATH|g;\ + s|#DATE#|$DATE|g;\ + s|#PROJECT_NAME#|$PROJECT_NAME|g;\ + s|#DB_HOST#|$DB_HOST|g;\ + s|#DB_NAME#|$DB_NAME|g;\ + s|#DB_PORT#|$DB_PORT|g;\ + s|#APP_DIR#|$APP_DIR|g;\ + s|#SECRET_KEY#|$SECRET_KEY|g;\ + s|#DB_PASSWORD#|$DB_PASSWORD|g;\ + s|#UWSGI_PORT#|$UWSGI_PORT|g;" $CDIR'/local_settings.py.sample' > \ + $INSTALL_PATH'/conf/local_settings.py' + +ln -s $INSTALL_PATH'/conf/local_settings.py' $APP_DIR'/local_settings.py' + +# rights +mkdir -p "$APP_DIR/media/imported" +mkdir -p "$APP_DIR/media/upload" +chown -R root:www-data $APP_DIR'/media' +chmod -R g+w $APP_DIR'/media' + +# logs +mkdir -p /var/log/django/ +chown root:www-data '/var/log/django' +touch '/var/log/django/ishtar-'$APP_NAME'.log' +chown root:www-data '/var/log/django/ishtar-'$APP_NAME'.log' +chmod g+w '/var/log/django/ishtar-'$APP_NAME'.log' + +cd $APP_DIR +./manage.py collectstatic --noinput 2> /dev/null > /dev/null + +# load locale data + +cd $INSTALL_PATH'/ishtar/archaeological_context_records' +django-admin compilemessages -l fr 2> /dev/null +cd $INSTALL_PATH'/ishtar/archaeological_files' +django-admin compilemessages -l fr 2> /dev/null +cd $INSTALL_PATH'/ishtar/archaeological_finds' +django-admin compilemessages -l fr 2> /dev/null +cd $INSTALL_PATH'/ishtar/archaeological_operations' +django-admin compilemessages -l fr 2> /dev/null +cd $INSTALL_PATH'/ishtar/archaeological_warehouse' +django-admin compilemessages -l fr 2> /dev/null +cd $INSTALL_PATH'/ishtar/ishtar_common' +django-admin compilemessages -l fr 2> /dev/null + +echo "* sync database" + +cd $APP_DIR +python ./manage.py syncdb --noinput 2> /dev/null > /dev/null +python ./manage.py migrate ishtar_common 2> /dev/null > /dev/null +python ./manage.py migrate archaeological_files 0013 2> /dev/null > /dev/null +python ./manage.py migrate archaeological_operations 2> /dev/null > /dev/null +python ./manage.py migrate archaeological_files 2> /dev/null > /dev/null +python ./manage.py migrate 2> /dev/null > /dev/null + +echo "* load default data" +# data migrations have created some default data - return to a clean state +python ./manage.py flush --noinput 2> /dev/null + +python ./manage.py loaddata \ + '../fixtures/initial_data-auth-'$DEFAULT_DATA'.json' 2> /dev/null +python ./manage.py loaddata \ + '../ishtar_common/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null +python ./manage.py loaddata \ + '../ishtar_common/fixtures/initial_towns-'$DEFAULT_DATA'.json' 2> /dev/null +python ./manage.py loaddata \ + '../archaeological_operations/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null +python ./manage.py loaddata \ + '../archaeological_files/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null +python ./manage.py loaddata \ + '../archaeological_context_records/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null +python ./manage.py loaddata \ + '../archaeological_finds/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null +python ./manage.py loaddata \ + '../archaeological_warehouse/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null + +echo "* create superuser" +python ./manage.py createsuperuser + +# "de-flush" migrations +$PYTHON ./manage.py migrate --fake 2> /dev/null > /dev/null + +# add a default site +#echo '[{"pk":null, "model": "sites.site", "fields": {"domain": "'$URL'", "name": "'$PROJECT_NAME'"}}]' > \ +# /tmp/site.json +#python ./manage.py loaddata /tmp/site.json +#rm /tmp/site.json + +echo '* uwsgi configuration' + +sed -s "s|#APP_NAME#|$APP_NAME|g;\ + s|#DB_NAME#|$DB_NAME|g;\ + s|#URL#|$URL|g;\ + s|#UWSGI_PORT#|$UWSGI_PORT|g;" $CDIR'/uwsgi.ini.template' > \ + $INSTALL_PATH'/conf/uwsgi.ini' + +sed -s "s#APP_NAME#/$APP_NAME/g;" $CDIR'/django.wsgi.template' > \ + $INSTALL_PATH'/conf/'$APP_NAME'.wsgi' + +ln -s $INSTALL_PATH'/conf/uwsgi.ini' \ + $UWSGI_AVAILABLE_PATH$APP_NAME'.ini' +ln -s $UWSGI_AVAILABLE_PATH$APP_NAME'.ini' \ + $UWSGI_ENABLE_PATH$APP_NAME'.ini' + +service uwsgi restart + +echo '* nginx configuration' + + +sed -s "s|#APP_NAME#|$APP_NAME|g;\ + s|#UWSGI_PORT#|$UWSGI_PORT|g;\ + s|#DB_NAME#|$DB_NAME|g;\ + s|#DATE#|$DATE|g;\ + s|#NGINX_PORT#|$NGINX_PORT|g;\ + s|#URL#|$URL|g;" $CDIR'/nginx.conf.template' > \ + $INSTALL_PATH'/conf/nginx.conf' +ln -s $INSTALL_PATH'/conf/nginx.conf' \ + $NGINX_AVAILABLE_PATH$APP_NAME'.conf' +ln -s $NGINX_AVAILABLE_PATH$APP_NAME'.conf' \ + $NGINX_ENABLE_PATH$APP_NAME'.conf' + +service nginx restart + diff --git a/bin/chimere-install b/bin/chimere-install new file mode 100755 index 0000000..e5c36f9 --- /dev/null +++ b/bin/chimere-install @@ -0,0 +1,420 @@ +#!/bin/bash + +set -e + +command_exists() { + command -v "$@" > /dev/null 2>&1 +} + +# Check if this is a forked Linux distro +check_forked() { + # Check for lsb_release command existence, it usually exists in forked distros + if command_exists lsb_release; then + # Check if the `-u` option is supported + set +e + lsb_release -a -u > /dev/null 2>&1 + lsb_release_exit_code=$? + set -e + + # Check if the command has exited successfully, it means we're in a forked distro + if [ "$lsb_release_exit_code" = "0" ]; then + # Print info about current distro + cat <<-EOF + You're using '$lsb_dist' version '$dist_version'. +EOF + + # Get the upstream release info + lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]') + dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]') + + # Print info about upstream distro + cat <<-EOF + Upstream release is '$lsb_dist' version '$dist_version'. +EOF + fi + fi +} + +do_install() { + + cat >&2 <<-'EOF' +******************************************************************************* +++++++ Chimère installation script ++++++ +******************************************************************************* + +EOF + + # check user + user="$(id -un 2>/dev/null || true)" + + sh_c='sh -c' + if [ "$user" != 'root' ]; then + if command_exists sudo; then + sh_c='sudo -E sh -c' + elif command_exists su; then + sh_c='su -c' + else + cat >&2 <<-'EOF' + Error: this installer needs the ability to run commands as root. + We are unable to find either "sudo" or "su" available to make this happen. +EOF + exit 1 + fi + fi + + # check distribution + lsb_dist='' + dist_version='' + if command_exists lsb_release; then + lsb_dist="$(lsb_release -si)" + fi + if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then + lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" + fi + if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then + lsb_dist='debian' + fi + if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then + lsb_dist='fedora' + fi + if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then + lsb_dist='oracleserver' + fi + if [ -z "$lsb_dist" ]; then + if [ -r /etc/centos-release ] || [ -r /etc/redhat-release ]; then + lsb_dist='centos' + fi + fi + if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then + lsb_dist="$(. /etc/os-release && echo "$ID")" + fi + + lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" + + case "$lsb_dist" in + + ubuntu) + if command_exists lsb_release; then + dist_version="$(lsb_release --codename | cut -f2)" + fi + if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then + dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" + fi + ;; + + debian) + dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" + case "$dist_version" in + 8) + dist_version="jessie" + ;; + 7) + dist_version="wheezy" + ;; + esac + ;; + + oracleserver) + # need to switch lsb_dist to match yum repo URL + lsb_dist="oraclelinux" + dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" + ;; + + fedora|centos) + dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" + ;; + + *) + if command_exists lsb_release; then + dist_version="$(lsb_release --codename | cut -f2)" + fi + if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then + dist_version="$(. /etc/os-release && echo "$VERSION_ID")" + fi + ;; + + + esac + + # Check if this is a forked Linux distro + check_forked + + case "$lsb_dist" in + ubuntu|debian) + ;; + *) + cat >&2 <<-'EOF' + + Sorry. Either your platform is not easily detectable or not supported by + this installer. + +EOF + exit 1 + esac + + default_db='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + A PostgreSQL database is needed to install Chimère. If you do not plan to use + a database host on another computer you need to install PostgreSQL. + +EOF + while [ "$default_db" == '' ] + do + read -p '* Default PostgreSQL host? [localhost] ' choice + if [ "$choice" == '' ]; then + default_db='127.0.0.1' + elif [ "$choice" == 'localhost' ]; then + default_db='127.0.0.1' + else + default_db=$choice + fi + done + + webserver='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + A webserver is needed to make Chimère available to the outside. + Be carreful if another webserver is already configured, you'll have to serve + your pages on a different port. + +EOF + MSG="" + while [ "$webserver" == '' ] + do + read -p '* Which webserver do you want to use? ([nginx]/none) ' choice + case "$choice" in + nginx ) webserver="nginx";; + none ) webserver="none";; + '' ) webserver="nginx";; + esac + done + + version='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + Two version are usually available for Chimère: master/v3.0. Master is the + bleeding edge version and you can experience problems with this version. + v3.0 is the safest choice. + +EOF + while [ "$version" == '' ] + do + read -p "* Which version would you like to use? ([v3.0]/master) " choice + case "$choice" in + v3.0 ) version="v3.0";; + master ) version="master";; + '' ) version="v3.0";; + esac + done + + etc_path="/etc/chimere/" + if [ -d "$etc_path" ]; then + echo "" + echo "ERROR: it seems that "$etc_path" already exists. If this is a remnant " + echo "of an old installation please delete this path before installing." + exit 1 + fi + + + use_virtualenv='' + cat >&2 <<-'EOF' + + +------------------------------------------------------------------------------- + Do you want to use a virtualenv for python libraries? If "yes" libraries not + available on your linux distribution will be isolated to be used only for + Chimère other with theses library will be available system-wide. If the main + use of this webserver is Chimère it should be OK to install theses libraries + system-wide but the safest choice should be to use a virtualenv (a little + more space is needed). + +EOF + while [ "$use_virtualenv" == '' ] + do + read -p "* Use a virtualenv? [yes]/no " choice + if [ -z "$choice" ]; then + use_virtualenv='yes' + elif [ "$choice" == 'yes' ]; then + use_virtualenv='yes' + elif [ "$choice" == 'no' ]; then + use_virtualenv='no' + fi + done + + + install_path='' + cat >&2 <<-'EOF' + + +------------------------------------------------------------------------------- + By default Chimère base path is '/srv/'. With this base path Chimère is + installed in '/srv/chimere/'. + +EOF + while [ "$install_path" == '' ] + do + read -p "* Which base install path for Chimère? [/srv] " choice + if [ -z "$choice" ]; then + install_path='/srv' + elif [ ! -d "$choice" ]; then + echo 'Not a valid path.' + else + install_path=$choice + fi + done + + full_install_path=$install_path'/chimere/' + if [ -d "$full_install_path" ]; then + echo "" + echo "ERROR: it seems that "$full_install_path" already exists. If this is a " + echo "remanant of an old installation please delete this directory before installing." + exit 1 + fi + + echo "" + echo "*******************************************************************************" + echo "" + + # Run setup for each distro accordingly + case "$lsb_dist" in + ubuntu|debian) + if [ "$dist_version" != "jessie" ]; then + cat >&2 <<-'EOF' + + Sorry this script cannot manage your version of Debian/Ubuntu. + +EOF + exit 1 + fi + + set +e + cat /etc/apt/sources.list | grep jessie-backports | grep -v "^ *#" > /dev/null + if [ $? == 1 ]; then + cat >&2 <<-'EOF' + + Before installing Chimère you need to add backports to your sources.list. + For instance, run: + echo "deb http://ftp.debian.org/debian jessie-backports main contrib" >> \ + /etc/apt/sources.list + +EOF + exit 1 + fi + set -e + + export DEBIAN_FRONTEND=noninteractive + ( set -x; $sh_c 'sleep 3; apt-get update' ) + if [ "$default_db" == '127.0.0.1' ]; then + echo "-------------------------------------------------------------------------------"; + echo "Installing postgresql..."; + echo ""; + if [ "$dist_version" == "jessie" ]; then + POSTGIS=postgresql-9.4-postgis-2.1 + fi + ( set -x; $sh_c 'sleep 3; apt-get install -y -q postgresql '$POSTGIS ) + fi + if ! command_exists git; then + echo "-------------------------------------------------------------------------------"; + echo "Installing git..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q git' ) + fi + if ! command_exists apg; then + echo "-------------------------------------------------------------------------------"; + echo "Installing apg..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q apg' ) + fi + if ! command_exists pip3; then + echo "-------------------------------------------------------------------------------"; + echo "Installing pip3 and dev libraries..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q python3-pip libexiv2-dev libboost-python-dev' ) + fi + if [ "$use_virtualenv" == 'yes' ]; then + echo "-------------------------------------------------------------------------------"; + echo "Installing virtualenv..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q virtualenv' ) + fi + if [ "$webserver" == 'nginx' ]; then + echo "-------------------------------------------------------------------------------"; + echo "Installing nginx and uwsgi..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q uwsgi uwsgi-plugin-python3 nginx' ) + fi + + echo "-------------------------------------------------------------------------------"; + echo "Installing Chimère dependencies" + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q \ + -t jessie-backports python3-django python3-django-haystack' ) + ( set -x; $sh_c 'sleep 3; apt-get install -y -q \ + python3-bs4 python3-psycopg2 gettext python3-pil \ + python3-lxml python3-feedparser python3-icalendar python3-chardet \ + python3-gdal python3-osmapi python3-geopy' ) + + ;; + + esac + + if [ "$use_virtualenv" == 'yes' ]; then + echo "-------------------------------------------------------------------------------"; + echo "Set virtualenv" + echo ""; + ( set -x; $sh_c 'virtualenv '$install_path'"/chimere-venv" --system-site-package -p /usr/bin/python3' ) + source $install_path"/chimere-venv/bin/activate" + fi + + echo "-------------------------------------------------------------------------------"; + echo "Installing py3exiv2" + echo ""; + + ( set -x; $sh_c 'pip3 install py3exiv2==0.2.1' ) + echo "-------------------------------------------------------------------------------"; + echo "Installing pysolr" + echo ""; + ( set -x; $sh_c 'pip3 install pysolr==3.3' ) + + echo "-------------------------------------------------------------------------------"; + echo "Installing Chimère sources" + echo ""; + + mkdir -p $full_install_path + cd $full_install_path + ( set -x; git clone https://gitlab.com/iggdrasil/chimere.git 2> /dev/null ) + cd chimere + git fetch 2> /dev/null + git checkout $version 2> /dev/null + + mkdir -p $etc_path + echo "INSTALL_PATH="$full_install_path > $etc_path"config" + echo "DEFAULT_DB="$default_db >> $etc_path"config" + echo "WEBSERVER="$webserver >> $etc_path"config" + echo "VERSION="$version >> $etc_path"config" + if [ "$use_virtualenv" == 'yes' ]; then + echo "VENV="$install_path"/chimere-venv" >> $etc_path"config" + else + echo "VENV=" >> $etc_path"config" + fi + echo "" + echo "*******************************************************************************"; + echo ""; + echo "Installation done." + echo ""; + echo "* configuration file: "$etc_path"config" + echo "* source and instances path: "$full_install_path + if [ "$use_virtualenv" == 'yes' ]; then + echo "* virtualenv path: "$install_path"/chimere-venv" + fi + echo ""; + echo "Next you'll have to create an instance." + echo ""; + +} + +do_install diff --git a/bin/install-chimere.sh b/bin/install-chimere.sh deleted file mode 100755 index 3b0b1c6..0000000 --- a/bin/install-chimere.sh +++ /dev/null @@ -1,420 +0,0 @@ -#!/bin/bash - -set -e - -command_exists() { - command -v "$@" > /dev/null 2>&1 -} - -# Check if this is a forked Linux distro -check_forked() { - # Check for lsb_release command existence, it usually exists in forked distros - if command_exists lsb_release; then - # Check if the `-u` option is supported - set +e - lsb_release -a -u > /dev/null 2>&1 - lsb_release_exit_code=$? - set -e - - # Check if the command has exited successfully, it means we're in a forked distro - if [ "$lsb_release_exit_code" = "0" ]; then - # Print info about current distro - cat <<-EOF - You're using '$lsb_dist' version '$dist_version'. -EOF - - # Get the upstream release info - lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]') - dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]') - - # Print info about upstream distro - cat <<-EOF - Upstream release is '$lsb_dist' version '$dist_version'. -EOF - fi - fi -} - -do_install() { - - cat >&2 <<-'EOF' -******************************************************************************* -++++++ Chimère installation script ++++++ -******************************************************************************* - -EOF - - # check user - user="$(id -un 2>/dev/null || true)" - - sh_c='sh -c' - if [ "$user" != 'root' ]; then - if command_exists sudo; then - sh_c='sudo -E sh -c' - elif command_exists su; then - sh_c='su -c' - else - cat >&2 <<-'EOF' - Error: this installer needs the ability to run commands as root. - We are unable to find either "sudo" or "su" available to make this happen. -EOF - exit 1 - fi - fi - - # check distribution - lsb_dist='' - dist_version='' - if command_exists lsb_release; then - lsb_dist="$(lsb_release -si)" - fi - if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then - lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" - fi - if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then - lsb_dist='debian' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then - lsb_dist='fedora' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then - lsb_dist='oracleserver' - fi - if [ -z "$lsb_dist" ]; then - if [ -r /etc/centos-release ] || [ -r /etc/redhat-release ]; then - lsb_dist='centos' - fi - fi - if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then - lsb_dist="$(. /etc/os-release && echo "$ID")" - fi - - lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" - - case "$lsb_dist" in - - ubuntu) - if command_exists lsb_release; then - dist_version="$(lsb_release --codename | cut -f2)" - fi - if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then - dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" - fi - ;; - - debian) - dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" - case "$dist_version" in - 8) - dist_version="jessie" - ;; - 7) - dist_version="wheezy" - ;; - esac - ;; - - oracleserver) - # need to switch lsb_dist to match yum repo URL - lsb_dist="oraclelinux" - dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" - ;; - - fedora|centos) - dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" - ;; - - *) - if command_exists lsb_release; then - dist_version="$(lsb_release --codename | cut -f2)" - fi - if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then - dist_version="$(. /etc/os-release && echo "$VERSION_ID")" - fi - ;; - - - esac - - # Check if this is a forked Linux distro - check_forked - - case "$lsb_dist" in - ubuntu|debian) - ;; - *) - cat >&2 <<-'EOF' - - Sorry. Either your platform is not easily detectable or not supported by - this installer. - -EOF - exit 1 - esac - - default_db='' - cat >&2 <<-'EOF' - -------------------------------------------------------------------------------- - A PostgreSQL database is needed to install Chimère. If you do not plan to use - a database host on another computer you need to install PostgreSQL. - -EOF - while [ "$default_db" == '' ] - do - read -p '* Default PostgreSQL host? [localhost] ' choice - if [ "$choice" == '' ]; then - default_db='127.0.0.1' - elif [ "$choice" == 'localhost' ]; then - default_db='127.0.0.1' - else - default_db=$choice - fi - done - - webserver='' - cat >&2 <<-'EOF' - -------------------------------------------------------------------------------- - A webserver is needed to make Chimère available to the outside. - Be carreful if another webserver is already configured, you'll have to serve - your pages on a different port. - -EOF - MSG="" - while [ "$webserver" == '' ] - do - read -p '* Which webserver do you want to use? ([nginx]/none) ' choice - case "$choice" in - nginx ) webserver="nginx";; - none ) webserver="none";; - '' ) webserver="nginx";; - esac - done - - version='' - cat >&2 <<-'EOF' - -------------------------------------------------------------------------------- - Two version are usually available for Chimère: master/v3.0. Master is the - bleeding edge version and you can experience problems with this version. - v3.0 is the safest choice. - -EOF - while [ "$version" == '' ] - do - read -p "* Which version would you like to use? ([v3.0]/master) " choice - case "$choice" in - v3.0 ) version="v3.0";; - master ) version="master";; - '' ) version="v3.0";; - esac - done - - etc_path="/etc/chimere/" - if [ -d "$etc_path" ]; then - echo "" - echo "ERROR: it seems that "$etc_path" already exists. If this is a remnant " - echo "of an old installation please delete this path before installing." - exit 1 - fi - - - use_virtualenv='' - cat >&2 <<-'EOF' - - -------------------------------------------------------------------------------- - Do you want to use a virtualenv for python libraries? If "yes" libraries not - available on your linux distribution will be isolated to be used only for - Chimère other with theses library will be available system-wide. If the main - use of this webserver is Chimère it should be OK to install theses libraries - system-wide but the safest choice should be to use a virtualenv (a little - more space is needed). - -EOF - while [ "$use_virtualenv" == '' ] - do - read -p "* Use a virtualenv? [yes]/no " choice - if [ -z "$choice" ]; then - use_virtualenv='yes' - elif [ "$choice" == 'yes' ]; then - use_virtualenv='yes' - elif [ "$choice" == 'no' ]; then - use_virtualenv='no' - fi - done - - - install_path='' - cat >&2 <<-'EOF' - - -------------------------------------------------------------------------------- - By default Chimère base path is '/srv/'. With this base path Chimère is - installed in '/srv/chimere/choosen_version/'. - -EOF - while [ "$install_path" == '' ] - do - read -p "* Which base install path for Chimère? [/srv] " choice - if [ -z "$choice" ]; then - install_path='/srv' - elif [ ! -d "$choice" ]; then - echo 'Not a valid path.' - else - install_path=$choice - fi - done - - full_install_path=$install_path'/chimere/' - if [ -d "$full_install_path" ]; then - echo "" - echo "ERROR: it seems that "$full_install_path" already exists. If this is a " - echo "remanant of an old installation please delete this directory before installing." - exit 1 - fi - - echo "" - echo "*******************************************************************************" - echo "" - - # Run setup for each distro accordingly - case "$lsb_dist" in - ubuntu|debian) - if [ "$dist_version" != "jessie" ]; then - cat >&2 <<-'EOF' - - Sorry this script cannot manage your version of Debian/Ubuntu. - -EOF - exit 1 - fi - - set +e - cat /etc/apt/sources.list | grep jessie-backports | grep -v "^ *#" > /dev/null - if [ $? == 1 ]; then - cat >&2 <<-'EOF' - - Before installing Chimère you need to add backports to your sources.list. - For instance, run: - echo "deb http://ftp.debian.org/debian jessie-backports main contrib" >> \ - /etc/apt/sources.list - -EOF - exit 1 - fi - set -e - - export DEBIAN_FRONTEND=noninteractive - ( set -x; $sh_c 'sleep 3; apt-get update' ) - if [ "$default_db" == 'localhost' ]; then - echo "-------------------------------------------------------------------------------"; - echo "Installing postgresql..."; - echo ""; - if [ "$dist_version" == "jessie" ]; then - POSTGIS=postgresql-9.4-postgis-2.1 - fi - ( set -x; $sh_c 'sleep 3; apt-get install -y -q postgresql '$POSTGIS ) - fi - if ! command_exists git; then - echo "-------------------------------------------------------------------------------"; - echo "Installing git..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q git' ) - fi - if ! command_exists apg; then - echo "-------------------------------------------------------------------------------"; - echo "Installing apg..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q apg' ) - fi - if ! command_exists pip3; then - echo "-------------------------------------------------------------------------------"; - echo "Installing pip3 and dev libraries..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q python3-pip libexiv2-dev libboost-python-dev' ) - fi - if [ "$use_virtualenv" == 'yes' ]; then - echo "-------------------------------------------------------------------------------"; - echo "Installing virtualenv..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q virtualenv' ) - fi - if [ "$webserver" == 'nginx' ]; then - echo "-------------------------------------------------------------------------------"; - echo "Installing nginx and uwsgi..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q uwsgi uwsgi-plugin-python3 nginx' ) - fi - - echo "-------------------------------------------------------------------------------"; - echo "Installing Chimère dependencies" - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q \ - -t jessie-backports python3-django python3-django-haystack' ) - ( set -x; $sh_c 'sleep 3; apt-get install -y -q \ - python3-bs4 python3-psycopg2 gettext python3-pil \ - python3-lxml python3-feedparser python3-icalendar python3-chardet \ - python3-gdal python3-osmapi python3-geopy' ) - - ;; - - esac - - if [ "$use_virtualenv" == 'yes' ]; then - echo "-------------------------------------------------------------------------------"; - echo "Set virtualenv" - echo ""; - ( set -x; $sh_c 'virtualenv '$install_path'"/chimere-venv" --system-site-package -p /usr/bin/python3' ) - source $install_path"/chimere-venv/bin/activate" - fi - - echo "-------------------------------------------------------------------------------"; - echo "Installing py3exiv2" - echo ""; - - ( set -x; $sh_c 'pip3 install py3exiv2==0.2.1' ) - echo "-------------------------------------------------------------------------------"; - echo "Installing pysolr" - echo ""; - ( set -x; $sh_c 'pip3 install pysolr==3.3' ) - - echo "-------------------------------------------------------------------------------"; - echo "Installing Chimère sources" - echo ""; - - mkdir -p $full_install_path - cd $full_install_path - ( set -x; git clone https://gitlab.com/iggdrasil/chimere.git 2> /dev/null ) - cd chimere - git fetch 2> /dev/null - git checkout $version 2> /dev/null - - mkdir -p $etc_path - echo "INSTALL_PATH="$full_install_path > $etc_path"config" - echo "DEFAULT_DB="$default_db >> $etc_path"config" - echo "WEBSERVER="$webserver >> $etc_path"config" - echo "VERSION="$version >> $etc_path"config" - if [ "$use_virtualenv" == 'yes' ]; then - echo "VENV="$install_path"/chimere-venv" >> $etc_path"config" - else - echo "VENV=" >> $etc_path"config" - fi - echo "" - echo "*******************************************************************************"; - echo ""; - echo "Installation done." - echo ""; - echo "* configuration file: "$etc_path"config" - echo "* source and instances path: "$full_install_path - if [ "$use_virtualenv" == 'yes' ]; then - echo "* virtualenv path: "$install_path"/chimere-venv" - fi - echo ""; - echo "Next you'll have to create an instance." - echo ""; - -} - -do_install -- cgit v1.2.3