install.sh 7.99 KB
Newer Older
Florian's avatar
Florian committed
1
2
#!/bin/sh

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
# Variables 
if [ -z ${HOSTNAME+x}          ]; then HOSTNAME="coopbox"; fi;
if [ -z ${COOPBOX_PATH+x}      ]; then COOPBOX_PATH="$HOME/CoopBox"; fi;
if [ -z ${COOPBOX_USER+x}      ]; then COOPBOX_USER="pi"; fi;
if [ -z ${COOPBOX_GROUP+x}     ]; then COOPBOX_GROUP="pi"; fi;
if [ -z ${DATABASE_PASS+x}     ]; then DATABASE_PASS="coopboxdbrootpassword"; fi;
if [ -z ${ETHERPAD_DATABASE+x} ]; then ETHERPAD_DATABASE="etherpad"; fi;
if [ -z ${ETHERPAD_DBUSER+x}   ]; then ETHERPAD_DBUSER="etherpad"; fi;
if [ -z ${ETHERPAD_DBPASS+x}   ]; then ETHERPAD_DBPASS="etherpadPassword"; fi;
if [ -z ${YESWIKI_DATABASE+x}  ]; then YESWIKI_DATABASE="yeswiki"; fi;
if [ -z ${YESWIKI_DBUSER+x}    ]; then YESWIKI_DBUSER="yeswiki"; fi;
if [ -z ${YESWIKI_DBPASS+x}    ]; then YESWIKI_DBPASS="yeswikiPassword"; fi;
if [ -z ${YESWIKI_BRANCH+x}    ]; then YESWIKI_BRANCH="cercopitheque"; fi;

echo "INSTALLATION DE LA COOPBOX"
echo "Mise à jour du système"
sudo apt update -y
sudo apt dist-upgrade -y
echo "Installation des paquets pour avoir un serveur opérationnel"
sudo apt install mariadb-server php-fpm php-mysql php-common php-cli php-gd php-curl php-intl php-mbstring php-bcmath php-imap php-xml php-zip nginx nodejs avahi-daemon redis-server git wget -y

echo "Sécurisation du serveur MYSQL"
sudo mysql_secure_installation
# sudo service mysql stop
# sudo mysqld --skip-grant-tables &
# sudo mysqladmin -u root flush-privileges password '*'
# sudo service mysql stop
# sudo service mysql start
# sudo mysqladmin -u root password "$DATABASE_PASS"
# mysql -u root -p"$DATABASE_PASS" -e "UPDATE mysql.user SET Password=PASSWORD('$DATABASE_PASS') WHERE User='root'"
# mysql -u root -p"$DATABASE_PASS" -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')"
# mysql -u root -p"$DATABASE_PASS" -e "DELETE FROM mysql.user WHERE User=''"
# mysql -u root -p"$DATABASE_PASS" -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%'"
# mysql -u root -p"$DATABASE_PASS" -e "FLUSH PRIVILEGES"

echo "Installation d'Etherpad"
sudo mkdir -p $COOPBOX_PATH
sudo chown -R $COOPBOX_USER:$COOPBOX_GROUP $COOPBOX_PATH
sudo -u $COOPBOX_USER git clone --branch master https://github.com/ether/etherpad-lite.git $COOPBOX_PATH/etherpad
sudo -u $COOPBOX_USER cp $COOPBOX_PATH/etherpad/settings.json.template $COOPBOX_PATH/etherpad/settings.json
#ligne 64 title = titre du pad
#ligne 83 "skinName": "colibris",
#mettre de la ligne 132 a 136  en commentaire avec /* .... puis */
#décommenter de la ligne 143 a 153
#  "dbType" : "mysql",
#  "dbSettings" : {
#    "user":     "etherpad",
#    "host":     "localhost",
#    "port":     3306,
#    "password": "etherpadpassword",
#    "database": "etherpad",
#    "charset":  "utf8mb4"
#  },
  
 # ligne 158 : changer le texte par défaut par "Écrire à plusieurs ici"
 # ligne 176 : mettre en francais "lang" : "fr"
mysql -u root -p"$DATABASE_PASS" -e "CREATE DATABASE `$ETHERPAD_DATABASE`;"
mysql -u root -p"$DATABASE_PASS" -e "GRANT CREATE,ALTER,SELECT,INSERT,UPDATE,DELETE on `$ETHERPAD_DATABASE`.* to '$ETHERPAD_DBUSER'@'localhost' identified by '$ETHERPAD_DBPASS';"
mysql -u root -p"$DATABASE_PASS" -e "FLUSH PRIVILEGES"

cat > etherpad.service << EOF
Florian's avatar
Florian committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
[Unit]
Description=Etherpad (real-time collaborative document editing)
After=syslog.target network.target

[Service]
Type=simple
User=$COOPBOX_USER
Group=$COOPBOX_GROUP
Environment=NODE_ENV=production
Restart=always
ExecStart=$COOPBOX_PATH/etherpad/bin/run.sh

[Install]
WantedBy=multi-user.target
Florian's avatar
Florian committed
78
EOF >> 
Florian's avatar
Florian committed
79

80
81
82
83
sudo mv etherpad.service /etc/systemd/system/etherpad.service
sudo systemctl enable etherpad
echo "il faut faire le fichier de conf $COOPBOX_PATH/etherpad/settings.json et sudo systemctl enable etherpad "
#sudo systemctl start etherpad
Florian's avatar
Florian committed
84

85
86
87
88
89
90
91
92
# Installer le Wiki
echo "Installation de YesWiki"
mysql -u root -p"$DATABASE_PASS" -e "CREATE DATABASE `$YESWIKI_DATABASE`;"
mysql -u root -p"$DATABASE_PASS" -e "GRANT CREATE,ALTER,SELECT,INSERT,UPDATE,DELETE on `$YESWIKI_DATABASE`.* to '$YESWIKI_DBUSER'@'localhost' identified by '$YESWIKI_DBPASS';"
mysql -u root -p"$DATABASE_PASS" -e "FLUSH PRIVILEGES"
sudo -u $COOPBOX_USER git clone --branch cercopitheque https://github.com/YesWiki/yeswiki.git $COOPBOX_PATH/yeswiki
sudo -u $COOPBOX_USER cd $COOPBOX_PATH/yeswiki
# TODO install composer, setup autoupdate, extension ferme
Florian's avatar
Florian committed
93

94
95
# NGINX
sudo rm /etc/nginx/sites-enabled/default
Florian's avatar
Florian committed
96

97
sudo cat > /etc/nginx/sites-available/yeswiki << EOF
Florian's avatar
Florian committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root $COOPBOX_PATH/yeswiki;
    index index.php index.html;

    server_name $HOSTNAME.local;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    }
}
Florian's avatar
Florian committed
116
EOF >>
Florian's avatar
Florian committed
117

118
119
120
sudo ln -s /etc/nginx/sites-available/yeswiki /etc/nginx/sites-enabled/yeswiki
sudo systemctl restart nginx
# sudo nginx -t
Florian's avatar
Florian committed
121
122


123
124
125
126
# sudo  mousepad /etc/php/7.3/fpm/pool.d/www.conf 
# passer
# user = pi
# group = pi
Florian's avatar
Florian committed
127

128
129
# listen.owner = pi
# listen.group = pi
Florian's avatar
Florian committed
130
131


132
133
134
135
136
# sudo  mousepad /etc/php/7.3/fpm/php.ini
# max_execution_time = 120
# upload_max_filesize = 200M
# memory_limit = 512M
# max_input_time = 120
Florian's avatar
Florian committed
137

138
139
140
# sudo service php7.3-fpm restart
# sudo service php7.3-fpm status
# sudo service nginx restart
Florian's avatar
Florian committed
141

142
# sudo tail /var/log/php
Florian's avatar
Florian committed
143

144
145
146
147
148
# sudo tail /var/log/nginx/error.log
# , upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "localhost"
# 2019/11/08 12:16:24 [crit] 2284#2284: *1 connect() to unix:/var/run/php/php7.3-fpm.sock failed (13: Permission denied) while connecting to upstream, client: ::1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "localhost"
# 2019/11/08 12:16:25 [crit] 2284#2284: *1 connect() to unix:/var/run/php/php7.3-fpm.sock failed (13: Permission denied) while connecting to upstream, client: ::1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "localhost"
# 2019/11/08 12:16:38 [crit] 2284#2284: *5 connect() to unix:/var/run/php/php7.3-fpm.sock failed (13: Permission denied) while connecting to upstream, client: ::1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "localhost"
Florian's avatar
Florian committed
149

150
# sudo ls -al /var/run/php/php7.3-fpm.sock
Florian's avatar
Florian committed
151

152
153
154
# sudo service php7.3-fpm stop
# sudo chmod 777 /var/run/php/php7.3-fpm.sock
# sudo service php7.3-fpm restart
Florian's avatar
Florian committed
155

156
# sudo apt install php-common php-cli php-gd php-mysql php-curl php-intl php-mbstring php-bcmath php-imap php-xml php-zip
Florian's avatar
Florian committed
157

158
# sudo service php7.3-fpm restart
Florian's avatar
Florian committed
159

160
161
162
# sudo mousepad /etc/nginx/nginx.conf
# client_max_body_size 200M;
# user pi pi;
Florian's avatar
Florian committed
163

164
# sudo service nginx restart
Florian's avatar
Florian committed
165
166


167
# https://github.com/YesWiki/yeswiki-extension-ferme
Florian's avatar
Florian committed
168

169
170
171
172
# @laurent les trucs à changer en cas de copie de carte
# Avoir des noms sympas sur le réseau genre http://coopbox1.local
# https://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/
# sudo apt install avahi-daemon
Florian's avatar
Florian committed
173

174
175
# sudo mousepad /etc/hosts
# => mettre des noms differents pour  raspberrypi : coopbox1, coopbox2, etc,..
Florian's avatar
Florian committed
176

177
178
# sudo mousepad /etc/hostname
# => mettre des noms differents pour  raspberrypi : coopbox1, coopbox2, etc,..
Florian's avatar
Florian committed
179

180
# et changer dans wakka.config.php l'url du wiki
Florian's avatar
Florian committed
181

182
# sudo reboot
Florian's avatar
Florian committed
183
184


185
# installer framemo (postit)
Florian's avatar
Florian committed
186

187
188
# sudo apt install redis-server
# sudo systemctl enable --now redis-server.service
Florian's avatar
Florian committed
189

190
191
192
193
194
# cd $HOME/CoopBox
# git clone https://framagit.org/colibris/framemo.git postit
# cd postit
# npm install
# node server.js --port 9002
Florian's avatar
Florian committed
195

196
197
198
199
# Lancer automatiquement framemo
# sudo mousepad /etc/systemd/system/postit.service
# ou sudo gedit /etc/systemd/system/postit.service
# copier coller :
Florian's avatar
Florian committed
200

201
202
203
# [Unit]
# Description=postit (real-time collaborative postit)
# After=syslog.target network.target
Florian's avatar
Florian committed
204

205
206
207
208
209
210
211
212
# [Service]
# Type=simple
# User=pi
# Group=pi
# Environment=NODE_ENV=production
# Restart=always
# WorkingDirectory=/home/pi/CoopBox/postit
# ExecStart=/usr/bin/nodejs /home/pi/CoopBox/postit/server.js --port 9002
Florian's avatar
Florian committed
213

214
215
# [Install]
# WantedBy=multi-user.target
Florian's avatar
Florian committed
216

217
218
219
# puis exec
# systemctl enable postit
# systemctl start postit
Florian's avatar
Florian committed
220

221
# service postit status