<commit_before>#!/bin/bash

# Installation script for ndstore backend
# Maintainer: <NAME> <<EMAIL>>

# update the sys packages and upgrade them
sudo apt-get update && sudo apt-get upgrade -y

# apt-get install mysql packages
echo "mysql-server-5.6 mysql-server/root_password password <PASSWORD>" | sudo debconf-set-selections
echo "mysql-server-5.6 mysql-server/root_password_again password <PASSWORD>" | sudo debconf-set-selections
sudo debconf-set-selections <<< "postfix postfix/mailname string openconnecto.me"
sudo debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"

sudo apt-get -y install mysql-client-core-5.6 libhdf5-serial-dev mysql-client-5.6

# apt-get install packages
sudo apt-get -y install nginx git bash-completion python-virtualenv libhdf5-dev libxslt1-dev libmemcached-dev g++ libjpeg-dev virtualenvwrapper python-dev mysql-server-5.6 libmysqlclient-dev xfsprogs supervisor rabbitmq-server uwsgi uwsgi-plugin-python liblapack-dev wget memcached postfix libffi-dev libssl-dev

# create the log directory
sudo mkdir /var/log/neurodata
sudo touch /var/log/neurodata/ndstore.log
sudo chown -R www-data:www-data /var/log/neurodata
sudo chmod -R 777 /var/log/neurodata/

# add group and user neurodata
sudo addgroup neurodata
sudo useradd -m -p neur0data -g neurodata -s /bin/bash neurodata

# switch user to neurodata and clone the repo with sub-modules
cd /home/neurodata
sudo -u neurodata git clone https://github.com/neurodata/ndstore
cd /home/neurodata/ndstore

if [ -z "$1" ]; then
  sudo -u neurodata git checkout microns
else
  sudo -u neurodata git checkout "$1"
fi

sudo -u neurodata git submodule init
sudo -u neurodata git submodule update


# pip install packages
cd /home/neurodata/ndstore/setup/
#sudo pip install -U -r requirements.txt
sudo pip install cython numpy
sudo pip install -U -r requirements.txt
#sudo pip install django h5py pytest
#sudo pip install pillow posix_ipc boto3 nibabel networkx requests lxml pylibmc blosc django-registration django-celery mysql-python libtiff jsonschema json-spec redis

# switch user to neurodata and make ctypes functions
cd /home/neurodata/ndstore/ndlib/c_version
sudo -u neurodata make -f makefile_LINUX

# configure mysql
cd /home/neurodata/ndstore/django/
sudo service mysql start
mysql -u root -pneur0data -i -e "create user 'neurodata'@'localhost' identified by 'neur0data';" && mysql -u root -pneur0data -i -e "grant all privileges on *.* to 'neurodata'@'localhost' with grant option;" && mysql -u neurodata -pneur0data -i -e "CREATE DATABASE neurodjango;"

# configure django setttings
cd /home/neurodata/ndstore/django/ND/
sudo -u neurodata cp settings.py.example settings.py
sudo -u neurodata ln -s /home/neurodata/ndstore/setup/docker_config/django/docker_settings_secret.py settings_secret.py

# add openconnecto.me to django_sites
mysql -u neurodata -pneur0data -i -e "use neurodjango; insert into django_site (id, domain, name) values (2, 'openconnecto.me', 'openconnecto.me');"

# migrate the database and create the superuser
sudo chmod -R 777 /var/log/neurodata/
cd /home/neurodata/ndstore/django/
sudo -u neurodata python manage.py migrate
echo "from django.contrib.auth.models import User; User.objects.create_superuser('neurodata', '<EMAIL>', '<PASSWORD>')" | python manage.py shell
sudo -u neurodata python manage.py collectstatic --noinput

# move the nginx config files and start service
sudo rm /etc/nginx/sites-enabled/default<commit_msg>Productionify database<commit_after>#!/bin/bash

# Installation script for ndstore backend
# Maintainer: <NAME> <<EMAIL>>

# update the sys packages and upgrade them
sudo apt-get update && sudo apt-get upgrade -y

# apt-get install mysql packages
echo "mysql-server-5.6 mysql-server/root_password password <PASSWORD>" | sudo debconf-set-selections
echo "mysql-server-5.6 mysql-server/root_password_again password <PASSWORD>" | sudo debconf-set-selections
sudo debconf-set-selections <<< "postfix postfix/mailname string openconnecto.me"
sudo debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"

sudo apt-get -y install mysql-client-core-5.6 libhdf5-serial-dev mysql-client-5.6

# apt-get install packages
sudo apt-get -y install nginx git bash-completion python-virtualenv libhdf5-dev libxslt1-dev libmemcached-dev g++ libjpeg-dev virtualenvwrapper python-dev mysql-server-5.6 libmysqlclient-dev xfsprogs supervisor rabbitmq-server uwsgi uwsgi-plugin-python liblapack-dev wget memcached postfix libffi-dev libssl-dev

# create the log directory
sudo mkdir /var/log/neurodata
sudo touch /var/log/neurodata/ndstore.log
sudo chown -R www-data:www-data /var/log/neurodata
sudo chmod -R 777 /var/log/neurodata/

# add group and user neurodata
sudo addgroup neurodata
sudo useradd -m -p neur0data -g neurodata -s /bin/bash neurodata

# switch user to neurodata and clone the repo with sub-modules
cd /home/neurodata
sudo -u neurodata git clone https://github.com/neurodata/ndstore
cd /home/neurodata/ndstore

if [ -z "$1" ]; then
  sudo -u neurodata git checkout microns
else
  sudo -u neurodata git checkout "$1"
fi

sudo -u neurodata git submodule init
sudo -u neurodata git submodule update


# pip install packages
cd /home/neurodata/ndstore/setup/
#sudo pip install -U -r requirements.txt
sudo pip install cython numpy
sudo pip install -U -r requirements.txt
#sudo pip install django h5py pytest
#sudo pip install pillow posix_ipc boto3 nibabel networkx requests lxml pylibmc blosc django-registration django-celery mysql-python libtiff jsonschema json-spec redis

# switch user to neurodata and make ctypes functions
cd /home/neurodata/ndstore/ndlib/c_version
sudo -u neurodata make -f makefile_LINUX

# configure mysql
cd /home/neurodata/ndstore/django/
sudo service mysql start
mysql -u root -pneur0data -i -e "create user 'neurodata'@'localhost' identified by 'neur0data';" && mysql -u root -pneur0data -i -e "grant all privileges on *.* to 'neurodata'@'localhost' with grant option;" && mysql -u neurodata -pneur0data -i -e "CREATE DATABASE neurodjango;"

# configure django setttings
cd /home/neurodata/ndstore/django/ND/
sudo -u neurodata cp settings.py.example settings.py
sudo -u neurodata ln -s /home/neurodata/ndstore/setup/docker_config/django/docker_settings_secret.py settings_secret.py

# add openconnecto.me to django_sites
if [ -z "$2" ]; then
  mysql -u neurodata -pneur0data -i -e "use neurodjango; insert into django_site (id, domain, name) values (2, 'openconnecto.me', 'openconnecto.me');"
else
  if [ "$2" == "PRODUCTION" ]; then
    mysql -u neurodata -pneur0data -i -e "use neurodjango; insert into django_site (id, domain, name) values (2, '$3', '$3');"
  fi
fi

# migrate the database and create the superuser
sudo chmod -R 777 /var/log/neurodata/
cd /home/neurodata/ndstore/django/
sudo -u neurodata python manage.py migrate
echo "from django.contrib.auth.models import User; User.objects.create_superuser('neurodata', '<EMAIL>', 'neur0data')" | python manage.py shell
sudo -u neurodata python manage.py collectstatic --noinput

# move the nginx config files and start service
sudo rm /etc/nginx/sites-enabled/default
{'fraction_non_alphanumeric': 0.09556457254792221, 'fraction_numerical': 0.00937456275360291, 'mean_word_length': 4.554001554001554, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1518303', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2278, 'n_words': 781}