Newer
Older
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
#!/bin/bash -eux
source /etc/environment
echo ">> adding softlink from /piwik to /"
rm -rf /usr/share/nginx/html
ln -s /piwik /usr/share/nginx/html
if [ -z ${DB_PASS+x} ] || [ -z ${DB_USER+x} ]
then
echo ">> piwik started, initial setup needs to be done in browser!"
echo ">> be fast! - anyone with access to your server can configure it!"
exit 0
fi
echo
echo ">> #####################"
echo ">> init piwik"
echo ">> #####################"
echo
nginx 2> /tmp/nginx.log > /tmp/nginx.log &
/opt/mysql-check.sh
if [ `echo "SHOW TABLES FROM $DB_NAME;" | mysql -h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASS | grep "piwik_" | wc -l` -lt 1 ]
then
echo ">> no DB installed, MYSQL User or Password specified - seems like the first start"
#cat /config.ini.php | sed "s/PIWIK_MYSQL_PORT/$DB_PORT/g" | sed "s/PIWIK_MYSQL_USER/$DB_USER/g" | sed "s/PIWIK_MYSQL_PASSWORD/$DB_PASS/g" | sed "s/PIWIK_MYSQL_DBNAME/$DB_NAME/g" > /piwik/config/config.ini.php
cp -R /piwik-config/* /piwik/config/
chown -R www-data:www-data /usr/share/nginx/html/
echo ">> init Piwik"
if [ -z ${EMAIL+x} ]
then
PIWIK_ADMIN="admin"
echo ">> piwik admin user: $EMAIL"
fi
if [ -z ${PIWIK_ADMIN_PASSWORD+x} ]
then
PIWIK_ADMIN_PASSWORD=`perl -e 'my @chars = ("A".."Z", "a".."z"); my $string; $string .= $chars[rand @chars] for 1..10; print $string;'`
echo ">> generated piwik admin password: $PIWIK_ADMIN_PASSWORD"
fi
if [ -z ${PIWIK_SUBSCRIBE_NEWSLETTER+x} ]
then
PIWIK_SUBSCRIBE_NEWSLETTER=0
fi
if [ -z ${PIWIK_SUBSCRIBE_PRO_NEWSLETTER+x} ]
then
PIWIK_SUBSCRIBE_PRO_NEWSLETTER=0
fi
if [ -z ${EMAIL+x} ]
then
EMAIL="no@no.tld"
PIWIK_SUBSCRIBE_NEWSLETTER=0
PIWIK_SUBSCRIBE_PRO_NEWSLETTER=0
fi
if [ -z ${SITE_NAME+x} ]
then
SITE_NAME="My local Website"
fi
if [ -z ${SITE_URL+x} ]
then
PRIMARY_DOMAIN=`echo $URL | cut -d. -f2,3`
SITE_URL="http://${PRIMARY_DOMAIN}"
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
fi
if [ -z ${SITE_TIMEZONE+x} ]
then
SITE_TIMEZONE="Europe/Paris"
fi
if [ -z ${SITE_ECOMMERCE+x} ]
then
SITE_ECOMMERCE=0
fi
if [ -z ${ANONYMISE_IP+x} ]
then
ANONYMISE_IP=1
fi
if [ -z ${DO_NOT_TRACK+x} ]
then
DO_NOT_TRACK=1
fi
echo ">> piwik wizard: #1 open installer"
curl "http://${URL}/" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \
2> /dev/null | grep " % Done"
sleep 5
echo ">> piwik wizard: #2 open system check"
curl "http://${URL}/index.php?action=systemCheck&trackerStatus=0" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \
2> /dev/null | grep " % Done"
sleep 5
echo ">> piwik wizard: #3 open database settings"
curl "http://${URL}/index.php?action=databaseSetup&trackerStatus=0" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=systemCheck&trackerStatus=0' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \
2> /dev/null | grep " % Done"
sleep 5
echo ">> piwik wizard: #4 store database settings"
curl "http://${URL}/index.php?action=databaseSetup&trackerStatus=0" \
-H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Origin: http://${URL}/' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://${URL}/index.php?action=databaseSetup&trackerStatus=0' -H 'Connection: keep-alive' --compressed \
--data-urlencode host="$DB_HOST:$DB_PORT" \
--data-urlencode username="$DB_USER" \
--data-urlencode password="$DB_PASS" \
--data-urlencode dbname="$DB_NAME" \
--data-urlencode tables_prefix="piwik_" \
--data 'adapter=PDO%5CMYSQL&submit=Next+%C2%BB' \
2> /dev/null
curl "http://${URL}/index.php?action=tablesCreation&trackerStatus=0&module=Installation" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=databaseSetup&trackerStatus=0' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed \
2> /dev/null | grep " % Done"
sleep 5
echo ">> piwik wizard: #5 open piwik settings"
curl "http://${URL}/index.php?action=setupSuperUser&trackerStatus=0&module=Installation" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=tablesCreation&trackerStatus=0&module=Installation' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \
2> /dev/null | grep " % Done"
sleep 5
echo ">> piwik wizard: #6 store piwik settings"
curl "http://${URL}/index.php?action=setupSuperUser&trackerStatus=0&module=Installation" \
-H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Origin: http://${URL}' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://${URL}/index.php?action=setupSuperUser&trackerStatus=0&module=Installation' -H 'Connection: keep-alive' --compressed \
--data-urlencode login="$EMAIL" \
--data-urlencode password="$PIWIK_ADMIN_PASSWORD" \
--data-urlencode password_bis="$PIWIK_ADMIN_PASSWORD" \
--data-urlencode email="$EMAIL" \
--data-urlencode subscribe_newsletter_piwikorg="$PIWIK_SUBSCRIBE_NEWSLETTER" \
--data-urlencode subscribe_newsletter_piwikpro="$PIWIK_SUBSCRIBE_PRO_NEWSLETTER" \
--data 'submit=Next+%C2%BB' \
2> /dev/null
curl "http://${URL}/index.php?action=firstWebsiteSetup&trackerStatus=0&module=Installation" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=setupSuperUser&trackerStatus=0&module=Installation' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed \
2> /dev/null | grep " % Done"
sleep 5
echo ">> piwik wizard: #7 store piwik site settings"
curl "http://${URL}/index.php?action=firstWebsiteSetup&trackerStatus=0&module=Installation" \
-H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Origin: http://${URL}' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://${URL}/index.php?action=firstWebsiteSetup&trackerStatus=0&module=Installation' -H 'Connection: keep-alive' --compressed \
--data-urlencode siteName="$SITE_NAME" \
--data-urlencode url="$SITE_URL" \
--data-urlencode timezone="$SITE_TIMEZONE" \
--data-urlencode ecommerce="$SITE_ECOMMERCE" \
--data 'submit=Next+%C2%BB' \
2> /dev/null
curl "http://${URL}/index.php?action=trackingCode&trackerStatus=0&module=Installation&site_idSite=1&site_name=default" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=firstWebsiteSetup&trackerStatus=0&module=Installation' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed \
2> /dev/null | grep " % Done"
sleep 5
echo ">> piwik wizard: #8 skip js page"
curl "http://${URL}/index.php?action=finished&trackerStatus=0&module=Installation&site_idSite=1&site_name=default" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=trackingCode&trackerStatus=0&module=Installation&site_idSite=1&site_name=justabot' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' --compressed \
2> /dev/null | grep " % Done"
sleep 5
echo ">> piwik wizard: #9 final settings"
curl "http://${URL}/index.php?action=finished&trackerStatus=0&module=Installation&site_idSite=1&site_name=default" \
-H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Origin: http://${URL}/' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://${URL}/index.php?action=finished&trackerStatus=0&module=Installation&site_idSite=1&site_name=justabot' -H 'Connection: keep-alive' --compressed \
--data-urlencode do_not_track="$DO_NOT_TRACK" \
--data-urlencode anonymise_ip="$ANONYMISE_IP" \
--data 'submit=Continue+to+Piwik+%C2%BB' \
2> /dev/null
curl "http://${URL}/index.php" \
-H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,de;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://${URL}/index.php?action=finished&trackerStatus=0&module=Installation&site_idSite=1&site_name=justabot' -H 'Cookie: pma_lang=en; pma_collation_connection=utf8_general_ci; pma_mcrypt_iv=n%2Bxpbn2a%2Btg%3D; pmaUser-1=L60fYDVIaz0%3D' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' --compressed \
2> /dev/null
sleep 5
fi
/piwik/console core:update --yes
chown -R www-data:www-data /piwik
chmod -R 755 /piwik/tmp
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
echo ">> update CorePlugins"
curl "http://${URL}/index.php?updateCorePlugins=1" \
2> /dev/null
sleep 2
killall nginx
cat <<EOF
Add the following JS-Code to your Site -> don't forget to change the URLs ;)
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//!!!YOUR-URL!!!/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="//!!!YOUR-URL!!!/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
EOF
# Put the right MySQL adapter
if ! grep -q adapter /piwik/config/config.ini.php; then
sed -i '/\[database\]/a adapter=MYSQLI' /piwik/config/config.ini.php
fi
# Fix IP behind proxy
if ! grep -q proxy_client_headers /piwik/config/config.ini.php; then
sed -i '/\[General\]/a proxy_client_headers[] = HTTP_X_FORWARDED_FOR' /piwik/config/config.ini.php
fi
if ! grep -q proxy_host_headers /piwik/config/config.ini.php; then
sed -i '/\[General\]/a proxy_host_headers[] = HTTP_X_FORWARDED_HOST' /piwik/config/config.ini.php
fi