Script d'installation

This commit is contained in:
Klafyvel 2018-03-02 19:55:38 +01:00
parent a62fe5a16a
commit 82c947245c
3 changed files with 88 additions and 19 deletions

42
deploy.sh Normal file
View file

@ -0,0 +1,42 @@
#! /bin/bash
PYTHON = "/usr/bin/python3"
printf "\033[0;32m > Création du virtualenv \033[0m\n"
virtualenv env_site -p $PYTHON
source env_site/bin/activate
printf "\033[0;32m > Installation des dépendances \033[0m\n"
pip install -r requirements.txt
printf "\033[0;32m > Génération des settings locaux. \033[0m\n"
printf "\033[0;32m > Génération de la secret_key \033[0m\n"
django_secret_key=$(python -c "import random; print(''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789%=+') for i in range(50)]))")
cp site_tps/settings_local.example.py site_tps/settings_local.py
sed -i 's/SUPER_SECRET_KEY/'"$django_secret_key"'/g' site_tps/settings_local.py
printf "\033[0;32m > Configuration de MySQL \033[0m\n"
read -p "Hôte > " db_host
read -p "Nom de la base de données > " db_name
read -p "Utilisateur MySQL > " db_user
read -p -s "Mot de passe > " db_pass
sed -i 's/db_engine/django.db.backends.mysql/g' site_tps/settings_local.py
sed -i 's/db_name/'"$db_name"'/g' site_tps/settings_local.py
sed -i 's/db_user/'"$db_user"'/g' site_tps/settings_local.py
sed -i 's/db_pass/'"$db_pass"'/g' site_tps/settings_local.py
sed -i 's/db_host/'"$db_host"'/g' site_tps/settings_local.py
#printf "\033[0;32m > Configuration des mails \033[0m\n"
#read -p "Domaine d'envoi des mails > " domain_name
#read -p "Mail de l'administrateur > " admin_mail
printf "\033[0;32m > Domaine\033[0m\n"
read -p "Domaine autorisé > " url_server
sed -i 's/URL_SERVER/'"$url_server"'/g' site_tps/settings_local.py
printf "\033[0;32m > settings_local.py créé \033[0m\n"

View file

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
""" """
import os import os
from settings_local import *
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -19,17 +20,6 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '1o5n7!p2@@bcd9om*6^d^=@es==*yf2^^cax=j(ij4s3#9-y(m'
AES_KEY = "0123456789ABCDEF"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
@ -79,12 +69,6 @@ WSGI_APPLICATION = 'site_tps.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation # Password validation
@ -109,9 +93,9 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/ # https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'UTC' TIME_ZONE = 'Europe/Paris'
USE_I18N = True USE_I18N = True

View file

@ -0,0 +1,43 @@
SECRET_KEY = 'SUPER_SECRET_KEY'
DB_PASSWORD = 'db_pass'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
# ADMINS = [('My Beloved Administrator', 'admin_mail')]
# SERVER_EMAIL = 'no-reply@example.org'
# Obligatoire, liste des host autorisés
ALLOWED_HOSTS = ['URL_SERVER']
if not DEBUG:
DATABASES = {
'default': {
'ENGINE': 'db_engine',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': DB_PASSWORD,
'HOST': 'db_host',
},
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Security settings, à activer une fois https en place
SECURE_CONTENT_TYPE_NOSNIFF = False
SECURE_BROWSER_XSS_FILTER = False
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
CSRF_COOKIE_HTTPONLY = False
X_FRAME_OPTIONS = 'DENY'
SESSION_COOKIE_AGE = 60 * 60 * 3
# EMAIL_HOST = 'MY_EMAIL_HOST'
# EMAIL_PORT = MY_EMAIL_PORT