Commit a547091f authored by sim's avatar sim

Remove configuration file from version control

parent 2b57f633
......@@ -2,3 +2,4 @@
__pycache__
/static
.env
gargantext.ini
.PHONY: dev prod env
.PHONY: dev prod env conf
dev: env
dev: conf env
@echo "• Installing dependencies..."
pipenv install --dev
@echo
prod: env
prod: conf env
@echo "• Installing dependencies..."
pipenv install
@echo
......@@ -14,3 +14,8 @@ env:
@echo "• Setup django settings module..."
./tools/mkenv.sh
@echo
conf:
@echo "• Setup gargantext configuration..."
./tools/mkconf.sh
@echo
[django]
DEBUG = True
SECRET_KEY = !%ktkh981)piil1%t5r0g4$^0=uvdafk!=f2x8djxy7_gq(n5%
DB_PASS = C8kdcUrAQy66U
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = {DEBUG}
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = {SECRET_KEY}
# PostgreSQL access
DB_HOST = 127.0.0.1
DB_PORT = 5432
DB_NAME = {DB_NAME}
DB_USER = {DB_USER}
DB_PASS = {DB_PASS}
[uwsgi]
......
#!/usr/bin/env python
from string import ascii_letters as L, digits as D, punctuation as P
from random import SystemRandom as R, randint
def gensecret(chars, min_len=20, max_len=None):
bounds = (min_len,) if max_len is None else (min_len, max_len)
return ''.join([R().choice(chars) for i in range(randint(*bounds))])
if __name__ == "__main__":
import sys
charsets = {'L': L, 'D': D, 'P': P}
chars = L+D+P
bounds = []
for arg in sys.argv:
if arg.isalpha():
chars = ''.join(charsets.get(c, "") for c in arg)
elif arg.isdigit() and len(bounds) < 2:
bounds.append(int(arg))
if not bounds:
bounds = [45, 50]
print(gensecret(chars, *bounds))
#!/usr/bin/env bash
# Handle arguments
while getopts f option; do
case "${option}"
in
f) FORCE=1;;
esac
done
# Gargantext configuration file
[ -z "$GARGANTEXT_CONF" ] && GARGANTEXT_CONF=gargantext.ini
# Configuration template
TEMPLATE=tools/gargantext.template.ini
if [ -f "$GARGANTEXT_CONF" -a -z "$FORCE" ]; then
echo "Configuration file $GARGANTEXT_CONF already exists. To generate a" \
"new configuration anyway you can do: ./tools/mkconf.sh -f"
exit
fi
D=$(dirname $GARGANTEXT_CONF)
if ! (mkdir -p $D && touch $GARGANTEXT_CONF 2>/dev/null); then
echo "Can't create $GARGANTEXT_CONF, please check permissions."
exit 1
fi
echo "Generate secret key for Django..."
SECRET_KEY=$(python ./tools/gensecret.py)
echo "PostgreSQL configuration..."
DB_NAME_DEFAULT=gargandb
DB_USER_DEFAULT=gargantua
read -p "Database name [$DB_NAME_DEFAULT]: " DB_NAME
DB_NAME=${DB_NAME:-$DB_NAME_DEFAULT}
read -p "Database user [$DB_USER_DEFAULT]: " DB_USER
DB_USER=${DB_USER:-$DB_USER_DEFAULT}
read -s -p "Please provide the password for $DB_USER: " DB_PASS && echo
SECRET_KEY=$(echo -n "$SECRET_KEY" | sed -e 's/[\\\/&\"]/\\\\&/g')
DB_NAME=$(echo -n "$DB_NAME" | sed -e 's/[\\\/&\"]/\\\\&/g')
DB_USER=$(echo -n "$DB_USER" | sed -e 's/[\\\/&\"]/\\\\&/g')
DB_PASS=$(echo -n "$DB_PASS" | sed -e 's/[\\\/&\"]/\\\\&/g')
echo "Generate configuration file from $TEMPLATE..."
sed -E -e 's/[{]DEBUG[}]/True/g' \
-e "s/[{]SECRET_KEY[}]/$SECRET_KEY/g" \
-e "s/[{]DB_NAME[}]/$DB_NAME/g" \
-e "s/[{]DB_USER[}]/$DB_USER/g" \
-e "s/[{]DB_PASS[}]/$DB_PASS/g" \
"$TEMPLATE" > "$GARGANTEXT_CONF" \
&& echo "Configuration written successfully in $GARGANTEXT_CONF."
[ -z "$DB_PASS" ] && echo "You didn't provide any database password, please" \
"edit $GARGANTEXT_CONF before running Gargantext."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment