<commit_before>#!/bin/sh -e

if [ -z "$NODE_ENV" ] || [ -z "$COUCHDB_HOST_ADDRESS" ]; then
    echo >&2 'Error: Both COUCHDB_HOST_ADDRESS and NODE_ENV environment variables need to be set'
    exit 1
fi

# Modify the following line in the Preferences Server's config to point to a
# real CouchDB instance:
# https://github.com/GPII/universal/blob/ec89640347d0977f3d4642cdd5b91b65896c482f/gpii/node_modules/rawPreferencesServer/configs/production.json#L14
sed -e "s|^ *\"rawPreferencesSourceUrl\": .*$|\"rawPreferencesSourceUrl\": \"http://${COUCHDB_HOST_ADDRESS}:5984/user/%userToken\"|" -i /opt/universal/gpii/node_modules/rawPreferencesServer/configs/production.json

# Test preferences stored in the GPII Universal repository need to be modified
# before they can be uploaded to CouchDB
if [ -n "$PRIME_DB" ]; then
    mkdir /tmp/modified_preferences
    /usr/local/bin/modify_preferences.sh /opt/universal/testData/preferences /tmp/modified_preferences
    curl -X PUT http://${COUCHDB_HOST_ADDRESS}:5984/user
    npm -g install kanso
    for preference in /tmp/modified_preferences/*.json; do
        kanso upload $preference http://${COUCHDB_HOST_ADDRESS}:5984/user;
    done
    rm -rf /tmp/modified_preferences
    npm -g uninstall kanso
fi

cat >/etc/supervisord.d/preferences_server.ini<<EOF
[program:preferences_server]
command=node /opt/universal/gpii.js
environment=NODE_ENV="${NODE_ENV}"
user=nobody
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
EOF

supervisord -c /etc/supervisord.conf<commit_msg>update endpoints from /user to /preferences<commit_after>#!/bin/sh -e

if [ -z "$NODE_ENV" ] || [ -z "$COUCHDB_HOST_ADDRESS" ]; then
    echo >&2 'Error: Both COUCHDB_HOST_ADDRESS and NODE_ENV environment variables need to be set'
    exit 1
fi

# Modify the following line in the Preferences Server's config to point to a
# real CouchDB instance:
# https://github.com/GPII/universal/blob/ec89640347d0977f3d4642cdd5b91b65896c482f/gpii/node_modules/rawPreferencesServer/configs/production.json#L14
sed -e "s|^ *\"rawPreferencesSourceUrl\": .*$|\"rawPreferencesSourceUrl\": \"http://${COUCHDB_HOST_ADDRESS}:5984/preferences/%userToken\"|" -i /opt/universal/gpii/node_modules/rawPreferencesServer/configs/production.json

# Test preferences stored in the GPII Universal repository need to be modified
# before they can be uploaded to CouchDB
if [ -n "$PRIME_DB" ]; then
    mkdir /tmp/modified_preferences
    /usr/local/bin/modify_preferences.sh /opt/universal/testData/preferences /tmp/modified_preferences
    curl -X PUT http://${COUCHDB_HOST_ADDRESS}:5984/preferences
    npm -g install kanso
    for preference in /tmp/modified_preferences/*.json; do
        kanso upload $preference http://${COUCHDB_HOST_ADDRESS}:5984/preferences;
    done
    rm -rf /tmp/modified_preferences
    npm -g uninstall kanso
fi

cat >/etc/supervisord.d/preferences_server.ini<<EOF
[program:preferences_server]
command=node /opt/universal/gpii.js
environment=NODE_ENV="${NODE_ENV}"
user=nobody
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
EOF

supervisord -c /etc/supervisord.conf
{'fraction_non_alphanumeric': 0.11304073255446795, 'fraction_numerical': 0.02841806125670982, 'mean_word_length': 4.866666666666666, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1126740', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1067, 'n_words': 240}