<commit_before>#!/bin/bash
set -e

color() {
      printf '\033[%sm%s\033[m\n' "$@"
      # usage color "31;5" "string"
      # 0 default
      # 5 blink, 1 strong, 4 underlined
      # fg: 31 red,  32 green, 33 yellow, 34 blue, 35 purple, 36 cyan, 37 white
      # bg: 40 black, 41 red, 44 blue, 45 purple
      }

if [ ! -f ./config.cfg ]; then
    color '31;1' 'config.cfg file not found!'
    exit 1
fi

color '36;1' "
      _____       _
     |_   _|     | |
       | |  _ __ | |__   _____  __
       | | | '_ \| '_ \ / _ \ \/ /
      _| |_| | | | |_) | (_) >  <
     |_____|_| |_|_.__/ \___/_/\_\\

     This script installs dependencies for Inbox.

     For more details, visit:
     https://www.github.com/inboxapp/inbox
"

color '35;1' "Press enter to continue..."
read enterKey

color '35;1' 'Updating packages...'
apt-get update
apt-get -y install python-software-properties

# Preconfigure MySQL root password
echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections

color '35;1' 'Installing dependencies from apt-get...'
apt-get -y install git \
                   wget \
                   supervisor \
                   mysql-server \
                   mysql-client \
                   redis-server \
                   python \
                   python-dev \
                   python-pip \
                   python-setuptools \
                   build-essential \
                   libmysqlclient-dev \
                   gcc \
                   python-gevent \
                   python-xapian \
                   libzmq-dev \
                   python-zmq \
                   libxml2-dev \
                   libxslt-dev \
                   lib32z1-dev \
                   libffi-dev \
                   python-lxml \
                   libmagickwand-dev \
                   tmux \
                   curl \
                   stunnel4

color '35;1' 'Installing dependencies from pip...'
pip install --upgrade setuptools
pip install -r requirements.txt

pip install -e src
if [ -d "../inbox-eas" ]; then
    pip install -e ../inbox-eas
fi

if ! grep -qe "^PYTHONIOENCODING=utf_8$" "~/.bashrc";
then
    echo "# Adding default Python IO encoding" >> ~/.bashrc
    echo 'export PYTHONIOENCODING=utf_8' >> ~/.bashrc
else
    color '32;1' "# PYTHONIOENCODING already set to utf_8"
fi
source ~/.bashrc

color '35;1' 'Finished installing dependencies.'
# mysql config
cp ./etc/my.cnf /etc/mysql/conf.d/inboxapp.cnf

mysqld_safe &
sleep 10

color '35;1' 'Creating databases...'
python tools/create_db.py
find . -name \*.pyc -delete

color '35;1' 'Cleaning up...'
apt-get -y purge build-essential
apt-get -y autoremove

mkdir /var/lib/inboxapp
chown $SUDO_USER /var/lib/inboxapp

mkdir /var/log/inboxapp
chown $SUDO_USER /var/log/inboxapp

color '35;1' 'Done!.'<commit_msg>ensure addition to .bashrc in setup.sh is idempotent<commit_after>#!/bin/bash
set -e

color() {
      printf '\033[%sm%s\033[m\n' "$@"
      # usage color "31;5" "string"
      # 0 default
      # 5 blink, 1 strong, 4 underlined
      # fg: 31 red,  32 green, 33 yellow, 34 blue, 35 purple, 36 cyan, 37 white
      # bg: 40 black, 41 red, 44 blue, 45 purple
      }

if [ ! -f ./config.cfg ]; then
    color '31;1' 'config.cfg file not found!'
    exit 1
fi

color '36;1' "
      _____       _
     |_   _|     | |
       | |  _ __ | |__   _____  __
       | | | '_ \| '_ \ / _ \ \/ /
      _| |_| | | | |_) | (_) >  <
     |_____|_| |_|_.__/ \___/_/\_\\

     This script installs dependencies for Inbox.

     For more details, visit:
     https://www.github.com/inboxapp/inbox
"

color '35;1' "Press enter to continue..."
read enterKey

color '35;1' 'Updating packages...'
apt-get update
apt-get -y install python-software-properties

# Preconfigure MySQL root password
echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections

color '35;1' 'Installing dependencies from apt-get...'
apt-get -y install git \
                   wget \
                   supervisor \
                   mysql-server \
                   mysql-client \
                   redis-server \
                   python \
                   python-dev \
                   python-pip \
                   python-setuptools \
                   build-essential \
                   libmysqlclient-dev \
                   gcc \
                   python-gevent \
                   python-xapian \
                   libzmq-dev \
                   python-zmq \
                   libxml2-dev \
                   libxslt-dev \
                   lib32z1-dev \
                   libffi-dev \
                   python-lxml \
                   libmagickwand-dev \
                   tmux \
                   curl \
                   stunnel4

color '35;1' 'Installing dependencies from pip...'
pip install --upgrade setuptools
pip install -r requirements.txt

pip install -e src
if [ -d "../inbox-eas" ]; then
    pip install -e ../inbox-eas
fi

if ! grep -qe "^export PYTHONIOENCODING=utf_8$" ~/.bashrc;
then
    echo "# Adding default Python IO encoding" >> ~/.bashrc
    echo 'export PYTHONIOENCODING=utf_8' >> ~/.bashrc
else
    color '32;1' "# PYTHONIOENCODING already set to utf_8"
fi
source ~/.bashrc

color '35;1' 'Finished installing dependencies.'
# mysql config
cp ./etc/my.cnf /etc/mysql/conf.d/inboxapp.cnf

mysqld_safe &
sleep 10

color '35;1' 'Creating databases...'
python tools/create_db.py
find . -name \*.pyc -delete

color '35;1' 'Cleaning up...'
apt-get -y purge build-essential
apt-get -y autoremove

mkdir /var/lib/inboxapp
chown $SUDO_USER /var/lib/inboxapp

mkdir /var/log/inboxapp
chown $SUDO_USER /var/log/inboxapp

color '35;1' 'Done!.'
{'fraction_non_alphanumeric': 0.11930659415363698, 'fraction_numerical': 0.026852481305234533, 'mean_word_length': 1.5936535918907007, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '3882016', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1859, 'n_words': 485}