2016-05-26 04:06:17 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-12-04 16:09:59 +01:00
|
|
|
# Arête le script quand :
|
|
|
|
# - une erreur survient
|
|
|
|
# - on essaie d'utiliser une variable non définie
|
|
|
|
# - on essaie d'écraser un fichier avec une redirection (>).
|
|
|
|
set -euC
|
2018-02-11 17:01:26 +01:00
|
|
|
|
2020-12-04 16:09:59 +01:00
|
|
|
# Configuration de la base de données, redis, Django, etc.
|
|
|
|
# Tous les mots de passe sont constant et en clair dans le fichier car c'est
|
2016-05-26 04:06:17 +02:00
|
|
|
# pour une installation de dév locale qui ne sera accessible que depuis la
|
|
|
|
# machine virtuelle.
|
2020-12-04 16:09:59 +01:00
|
|
|
readonly DBUSER="cof_gestion"
|
|
|
|
readonly DBNAME="cof_gestion"
|
|
|
|
readonly DBPASSWD="4KZt3nGPLVeWSvtBZPSM3fSzXpzEU4"
|
|
|
|
readonly REDIS_PASSWD="dummy"
|
2021-02-07 17:17:15 +01:00
|
|
|
readonly DJANGO_SETTINGS_MODULE="gestioasso.settings.dev"
|
2020-12-04 16:09:59 +01:00
|
|
|
|
2016-05-26 04:06:17 +02:00
|
|
|
|
2020-12-07 19:58:00 +01:00
|
|
|
# ---
|
|
|
|
# Installation des paquets systèmes
|
|
|
|
# ---
|
|
|
|
|
|
|
|
get_packages_list () {
|
|
|
|
sed 's/#.*$//' /vagrant/provisioning/packages.list | grep -v '^ *$'
|
|
|
|
}
|
|
|
|
|
2020-12-04 16:09:59 +01:00
|
|
|
# https://github.com/chef/bento/issues/661
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2020-12-07 19:58:00 +01:00
|
|
|
|
|
|
|
apt-get update
|
2020-12-04 16:09:59 +01:00
|
|
|
apt-get -y upgrade
|
2020-12-07 19:58:00 +01:00
|
|
|
get_packages_list | xargs apt-get install -y
|
2016-05-26 04:06:17 +02:00
|
|
|
|
2020-12-07 20:04:19 +01:00
|
|
|
|
|
|
|
# ---
|
|
|
|
# Configuration de la base de données
|
|
|
|
# ---
|
|
|
|
|
2017-08-09 23:07:49 +02:00
|
|
|
# Postgresql
|
2020-12-04 16:09:59 +01:00
|
|
|
pg_user_exists () {
|
|
|
|
sudo -u postgres psql postgres -tAc \
|
|
|
|
"SELECT 1 FROM pg_roles WHERE rolname='$1'" \
|
|
|
|
| grep -q '^1$'
|
|
|
|
}
|
|
|
|
|
|
|
|
pg_db_exists () {
|
|
|
|
sudo -u postgres psql postgres -tAc \
|
|
|
|
"SELECT 1 FROM pg_database WHERE datname='$1'" \
|
|
|
|
| grep -q '^1$'
|
|
|
|
}
|
|
|
|
|
|
|
|
pg_db_exists "$DBNAME" || sudo -u postgres createdb "$DBNAME"
|
|
|
|
pg_user_exists "$DBUSER" || sudo -u postgres createuser -SdR "$DBUSER"
|
2017-08-09 23:07:49 +02:00
|
|
|
sudo -u postgres psql -c "ALTER USER $DBUSER WITH PASSWORD '$DBPASSWD';"
|
|
|
|
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DBNAME TO $DBUSER;"
|
2016-05-26 04:06:17 +02:00
|
|
|
|
|
|
|
|
2020-12-07 20:04:19 +01:00
|
|
|
# ---
|
|
|
|
# Configuration de redis (pour django-channels)
|
|
|
|
# ---
|
|
|
|
|
2017-08-09 23:07:49 +02:00
|
|
|
# Redis
|
2020-12-04 16:09:59 +01:00
|
|
|
redis-cli CONFIG SET requirepass "$REDIS_PASSWD"
|
|
|
|
redis-cli -a "$REDIS_PASSWD" CONFIG REWRITE
|
2017-04-24 22:27:01 +02:00
|
|
|
|
2020-12-07 20:04:19 +01:00
|
|
|
|
|
|
|
# ---
|
|
|
|
# Préparation de Django
|
|
|
|
# ---
|
|
|
|
|
|
|
|
# Dossiers pour le contenu statique
|
2017-08-13 15:36:45 +02:00
|
|
|
mkdir -p /srv/gestiocof/media
|
|
|
|
mkdir -p /srv/gestiocof/static
|
2020-12-04 16:09:59 +01:00
|
|
|
chown -R vagrant:www-data /srv/gestiocof
|
2017-08-09 23:07:49 +02:00
|
|
|
|
|
|
|
# Environnement virtuel python
|
2020-12-04 16:09:59 +01:00
|
|
|
sudo -H -u vagrant python3 -m venv ~vagrant/venv
|
|
|
|
sudo -H -u vagrant ~vagrant/venv/bin/pip install -U pip
|
|
|
|
sudo -H -u vagrant ~vagrant/venv/bin/pip install \
|
|
|
|
-r /vagrant/requirements-prod.txt \
|
|
|
|
-r /vagrant/requirements-devel.txt \
|
2017-08-09 23:07:49 +02:00
|
|
|
|
2017-08-10 17:55:36 +02:00
|
|
|
# Préparation de Django
|
|
|
|
cd /vagrant
|
2021-02-07 17:17:15 +01:00
|
|
|
ln -s -f secret_example.py gestioasso/settings/secret.py
|
2020-12-04 16:09:59 +01:00
|
|
|
sudo -H -u vagrant \
|
|
|
|
DJANGO_SETTINGS_MODULE="$DJANGO_SETTINGS_MODULE"\
|
|
|
|
/bin/sh -c ". ~vagrant/venv/bin/activate && /bin/sh provisioning/prepare_django.sh"
|
|
|
|
~vagrant/venv/bin/python manage.py collectstatic \
|
|
|
|
--noinput \
|
|
|
|
--settings "$DJANGO_SETTINGS_MODULE"
|
2017-08-10 17:55:36 +02:00
|
|
|
|
2020-12-07 20:04:19 +01:00
|
|
|
|
|
|
|
# ---
|
|
|
|
# Units systemd
|
|
|
|
# ---
|
|
|
|
|
2020-12-04 16:58:25 +01:00
|
|
|
# - Daphne fait tourner le serveur asgi
|
|
|
|
# - worker = https://channels.readthedocs.io/en/stable/topics/worker.html
|
|
|
|
# - Mails de rappels du BdA
|
|
|
|
# - Mails de revente du BdA
|
|
|
|
ln -sf /vagrant/provisioning/systemd/daphne.service /etc/systemd/system/daphne.service
|
|
|
|
ln -sf /vagrant/provisioning/systemd/worker.service /etc/systemd/system/worker.service
|
|
|
|
ln -sf /vagrant/provisioning/systemd/reventes.service /etc/systemd/system/reventes.service
|
|
|
|
ln -sf /vagrant/provisioning/systemd/rappels.service /etc/systemd/system/rappels.service
|
|
|
|
ln -sf /vagrant/provisioning/systemd/reventes.timer /etc/systemd/system/reventes.timer
|
|
|
|
ln -sf /vagrant/provisioning/systemd/rappels.timer /etc/systemd/system/rappels.timer
|
2020-12-04 16:09:59 +01:00
|
|
|
systemctl enable --now daphne.service
|
|
|
|
systemctl enable --now worker.service
|
2020-12-04 16:58:25 +01:00
|
|
|
systemctl enable rappels.timer
|
|
|
|
systemctl enable reventes.timer
|
2020-12-04 16:09:59 +01:00
|
|
|
|
2020-12-07 20:04:19 +01:00
|
|
|
|
|
|
|
# ---
|
|
|
|
# Configuration du shell de l'utilisateur 'vagrant' pour utiliser le bon fichier
|
|
|
|
# de settings et et bon virtualenv.
|
|
|
|
# ---
|
|
|
|
|
2020-12-04 16:09:59 +01:00
|
|
|
# On utilise .bash_aliases au lieu de .bashrc pour ne pas écraser la
|
|
|
|
# configuration par défaut.
|
|
|
|
rm -f ~vagrant/.bash_aliases
|
|
|
|
cat > ~vagrant/.bash_aliases <<EOF
|
2016-05-26 04:06:17 +02:00
|
|
|
# On utilise la version de développement de GestioCOF
|
2020-12-04 16:09:59 +01:00
|
|
|
export DJANGO_SETTINGS_MODULE='$DJANGO_SETTINGS_MODULE'
|
2016-05-26 04:06:17 +02:00
|
|
|
|
2016-11-06 15:39:50 +01:00
|
|
|
# Charge le virtualenv
|
2020-12-04 16:09:59 +01:00
|
|
|
. ~/venv/bin/activate
|
2016-11-06 15:39:50 +01:00
|
|
|
|
2016-05-26 04:06:17 +02:00
|
|
|
# On va dans /vagrant où se trouve le code de gestioCOF
|
|
|
|
cd /vagrant
|
|
|
|
EOF
|
2020-12-07 20:04:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
# ---
|
|
|
|
# Configuration d'nginx
|
|
|
|
# ---
|
|
|
|
|
|
|
|
ln -s -f /vagrant/provisioning/nginx/gestiocof.conf /etc/nginx/sites-enabled/gestiocof.conf
|
|
|
|
rm -f /etc/nginx/sites-enabled/default
|
|
|
|
systemctl reload nginx
|