aboutsummaryrefslogtreecommitdiffstats
path: root/install/stif-boiv-setup.sh
blob: 329bffd9c81ba3c79c90a2d2d23258e14056d20a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash -e

export DATABASE_HOST=${DATABASE_HOST:-"localhost"}
export SIDEKIQ_REDIS_URL=${SIDEKIQ_REDIS_URL:-"redis://localhost:6379/0"}

if [[ "$#" != "1" ]] ; then
  echo "Argument count mismatch. 1 and only 1 argument expected"
  exit -1
fi
 
SVRTYPE="$1"

if test "$SVRTYPE" == "front"; then
  echo "*** FRONT SERVER SELECTED"
elif [[ "$SVRTYPE" == "worker" ]] ; then
  echo "*** WORKER SERVER SELECTED"
else
  echo "server type must be front or worker"
  exit -2
fi

# mandatory packages and distribution upgrade
apt-get update && apt-get dist-upgrade
apt-get install -y wget sudo build-essential

# ruby
echo "==== Installation de Ruby 2.3"
cat > /etc/apt/sources.list.d/bearstech.list <<EOF
deb http://deb.bearstech.com/debian jessie-bearstech main
EOF

wget -q -O - http://deb.bearstech.com/bearstech-archive.gpg | apt-key add -
apt-get update
apt-get install -y ruby2.3 ruby2.3-dev
apt-get install -y libsqlite3-dev libproj-dev libpq-dev
gem2.3 install bundler

# Apache / Passenger
if test "$SVRTYPE" == "front"; then
echo "==== Installation de Apache 2.4 et Passenger"
apt-get install -y apache2 libapache2-mod-passenger

cp stif-boiv.conf /etc/apache2/sites-available/

a2enmod expires
a2ensite stif-boiv
fi

# Redis
if test "$SVRTYPE" == "front"; then

echo "==== Installation de Redis"

apt-get install -y redis-server
fi

# Sidekiq

if test "$SVRTYPE" == "worker"; then
echo "==== Installation de Sidekiq comme service"
cp sidekiq-stif-boiv.service /etc/systemd/system/
systemctl enable sidekiq-stif-boiv
fi

echo "==== Installation de PostgreSQL"
if [ "x$DATABASE_HOST" = "xlocalhost" ]; then
apt-get install -y postgresql-9.4 postgresql-9.4-postgis-2.1 postgresql-contrib-9.4
[ -d /usr/local/share/postgresql ] || mkdir -p /usr/local/share/postgresql/
cp template-stif-boiv.sql /usr/local/share/postgresql/
pushd .
cd /usr/local/share/postgresql
sudo -u postgres createdb --encoding UTF-8 template_stif_boiv < template-stif-boiv.sql
popd
echo "Saisissez le mot de passe de la base de données. Il vous sera redemandé ultérieurement"
sudo -u postgres createuser --pwprompt stif_boiv
sudo -u postgres createdb --owner stif_boiv --template template_stif_boiv stif_boiv
else
echo "W! Base de donnée externe : Pas d'installation"
fi

# NodeJS

#if test "$SVRTYPE" == "front"; then
#echo "==== Installation de NodeJS 5.x"
#apt-get install -y apt-transport-https
#
#cat > /etc/apt/sources.list.d/nodesource.list <<EOF
#deb https://deb.nodesource.com/node_5.x  jessie main
#EOF
#
#wget -q -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
#apt-get update
#
#apt-get install -y nodejs
#fi
# Configuration de l'applicatif

echo "==== Paramétrage de l'applicatif"
echo -n "Veuillez saisir le mot de passe d'accès à la base de données :"
read -s DATABASE_PASSWORD

echo ''
export DATABASE_PASSWORD

PGPASSWORD=$DATABASE_PASSWORD PGHOST=$DATABASE_HOST PGUSER=stif_boiv psql -q -c 'select 1' stif_boiv >/dev/null 2>&1 && echo "Mot de passe PG correct" || echo "ATTENTION : connexion impossible"

./deploy-helper.sh setup

echo "!!! Configuration intiale terminée. Vous pouvez maintenant déployer l'applicatif"