-
Notifications
You must be signed in to change notification settings - Fork 22
/
INSTALL
331 lines (299 loc) · 13.7 KB
/
INSTALL
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
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
207
208
209
210
211
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash
##: Server Setup on Ubuntu LTS 14.x and up.
##:
##: This install script can be run as-is on a virgin system. If you're installing on an existing box
##: it'd be better to walk through it first and adjust things
##:
##: Before starting, download and unzip the git source to the directory you're in. Then run this
##: file like "sudo cartulary-master/INSTALL"
##: This script needs to be run with sudo
SOURCEROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCEBASE=`basename $SOURCEROOT`
INSTALLDIR="/opt/cartulary"
ROOT_UID="0"
CURRENTLY=`pwd`
#echo "Installing from: [$SOURCEROOT -> $SOURCEBASE]";
#We need to be one level up from the source code folder so we can move it into the install folder
if [ "$CURRENTLY" == "$SOURCEROOT" ]; then
echo "Jumping up..."
cd ..
fi
pwd
#Check if run as root
if [ "$UID" -ne "$ROOT_UID" ] ; then
echo "You must run this script with sudo."
exit 1
fi
#Check that we're on Ubuntu
if ! lsb_release -r | grep -i "1[4-9]\.[0-9][0-9]"; then
echo "This script only works on Ubuntu LTS 14 and up. Sorry."
exit 1
fi
function pause(){
read -p "Press [Enter] to continue..."
}
##: 0. Warning.
clear
echo 'This install script assumes it is being run on a virgin install of Ubuntu server LTS v12 and up.'
echo 'Running this file as-is on a production system is going to most likely wreck a lot of stuff.'
echo 'If that is the case, you should **STOP NOW** and do the installation by hand.'
echo
read -p "Press [Enter] if you are sure you want to run this script..."
echo
read -p "We're about to modify a whole bunch of stuff, like php.ini, mysql, etc.? Are you really sure? [Enter]"
echo
read -p "This is your last chance to back out. Are you really, really sure this is a virgin system? [Enter]"
##: 1. Install Apache and PHP
clear
echo 'Installing Apache, PHP and some modules...'
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
apt-get update
if lsb_release -r | grep -i "16\.[0-9][0-9]"; then
apt-get install -y apache2 php7.0 php7.0-cli libapache2-mod-php7.0 php7.0-mcrypt php7.0-curl php7.0-imap php7.0-tidy php7.0-gd php7.0-mbstring ccze cstream ntp php7.0-xsl nodejs build-essential
phpenmod imap
elif lsb_release -r | grep -i "18\.[0-9][0-9]"; then
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main multiverse restricted universe"
add-apt-repository -y ppa:ondrej/php
apt-get update
apt-get upgrade -y
apt-get install -y apache2 php7.0 php7.0-cli libapache2-mod-php7.0 php7.0-mcrypt php7.0-curl php7.0-imap php7.0-tidy php7.0-gd php7.0-mbstring php7.0-xsl
apt-get install -y ccze cstream ntp nodejs
apt-get install -y build-essential
phpenmod imap
else
apt-get install -y apache2 php5 php5-cli libapache2-mod-php5 php5-mcrypt php5-curl php5-imap php5-tidy php5-gd ccze cstream ntp php5-xsl nodejs build-essential
php5enmod imap
fi
#sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
cd $SOURCEROOT/aggrivate
sudo npm -g install npm@latest
sudo npm cache clean --force
sudo npm i -g npm
rm -rf node_modules
sudo --user=$LOGNAME npm install
cd -
##: 2. Install MySql
clear
if lsb_release -r | grep -i "16\.[0-9][0-9]"; then
echo 'Give MySQL a root password and write it down.'
apt-get install -y mysql-server php7.0-mysql
elif lsb_release -r | grep -i "18\.[0-9][0-9]"; then
apt-get -y install mysql-server php7.0-mysql
else
echo 'Give MySQL a root password and write it down.'
apt-get install -y mysql-server php5-mysql
fi
#[you should set a root password during this step and write it down]
#mysql_secure_installation
#[No, Yes, Yes, Yes, Yes]
##: 3. Build Database
clear
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Type your MySQL root password here if asked. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
echo "Configuring MySQL. Please wait..."
if lsb_release -r | grep -i "1[6-8]\.[0-9][0-9]"; then
echo >> /etc/mysql/conf.d/mysql.cnf
echo '[mysqld]' >> /etc/mysql/conf.d/mysql.cnf
echo "sql_mode='NO_ENGINE_SUBSTITUTION'" >> /etc/mysql/conf.d/mysql.cnf
echo >> /etc/mysql/conf.d/mysql.cnf
echo '[mysqld_safe]' >> /etc/mysql/conf.d/mysql.cnf
echo "sql_mode='NO_ENGINE_SUBSTITUTION'" >> /etc/mysql/conf.d/mysql.cnf
fi
/etc/init.d/mysql restart
if lsb_release -r | grep -i "18\.[0-9][0-9]"; then
mysql -u root < $SOURCEROOT/templates/newdb.sql >>/tmp/cartinstall.log 2>&1
else
mysql -u root -p < $SOURCEROOT/templates/newdb.sql >>/tmp/cartinstall.log 2>&1
fi
mysql -ucartulary -pcartulary cartulary < $SOURCEROOT/templates/cartulary.sql >>/tmp/cartinstall.log 2>&1
##: 4. Configure PHP
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Configuring PHP to know where our app is. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
if lsb_release -r | grep -i "16\.[0-9][0-9]"; then
echo >> /etc/php/7.0/apache2/php.ini
echo '[cartulary]' >> /etc/php/7.0/apache2/php.ini
echo "cartulary_conf=$INSTALLDIR" >> /etc/php/7.0/apache2/php.ini
echo 'post_max_size=300M' >> /etc/php/7.0/apache2/php.ini
echo 'upload_max_filesize=300M' >> /etc/php/7.0/apache2/php.ini
echo 'max_execution_time=90' >> /etc/php/7.0/apache2/php.ini
echo 'short_open_tag=On' >> /etc/php/7.0/apache2/php.ini
echo >> /etc/php/7.0/cli/php.ini
echo '[cartulary]' >> /etc/php/7.0/cli/php.ini
echo "cartulary_conf=$INSTALLDIR" >> /etc/php/7.0/cli/php.ini
echo "short_open_tag=On" >> /etc/php/7.0/cli/php.ini
elif lsb_release -r | grep -i "18\.[0-9][0-9]"; then
echo >> /etc/php/7.0/apache2/php.ini
echo '[cartulary]' >> /etc/php/7.0/apache2/php.ini
echo "cartulary_conf=$INSTALLDIR" >> /etc/php/7.0/apache2/php.ini
echo 'post_max_size=300M' >> /etc/php/7.0/apache2/php.ini
echo 'upload_max_filesize=300M' >> /etc/php/7.0/apache2/php.ini
echo 'max_execution_time=90' >> /etc/php/7.0/apache2/php.ini
echo 'short_open_tag=On' >> /etc/php/7.0/apache2/php.ini
echo >> /etc/php/7.0/cli/php.ini
echo '[cartulary]' >> /etc/php/7.0/cli/php.ini
echo "cartulary_conf=$INSTALLDIR" >> /etc/php/7.0/cli/php.ini
echo "short_open_tag=On" >> /etc/php/7.0/cli/php.ini
else
echo >> /etc/php5/apache2/php.ini
echo '[cartulary]' >> /etc/php5/apache2/php.ini
echo "cartulary_conf=$INSTALLDIR" >> /etc/php5/apache2/php.ini
echo 'post_max_size=300M' >> /etc/php5/apache2/php.ini
echo 'upload_max_filesize=300M' >> /etc/php5/apache2/php.ini
echo 'max_execution_time=90' >> /etc/php5/apache2/php.ini
echo 'short_open_tag=On' >> /etc/php5/apache2/php.ini
echo >> /etc/php5/cli/php.ini
echo '[cartulary]' >> /etc/php5/cli/php.ini
echo "cartulary_conf=$INSTALLDIR" >> /etc/php5/cli/php.ini
echo "short_open_tag=On" >> /etc/php5/cli/php.ini
fi
##: 5. Install Cartulary Files
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Installing application file structure. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
mv $SOURCEBASE $INSTALLDIR >>/tmp/cartinstall.log 2>&1
##: 6. Configure Apache
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Configuring Apache. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
if lsb_release -r | grep -i "12\.[0-9][0-9]"; then
cp $INSTALLDIR/templates/apache12.conf /etc/apache2/sites-available/cartulary.conf >>/tmp/cartinstall.log 2>&1
else
cp $INSTALLDIR/templates/apache.conf /etc/apache2/sites-available/cartulary.conf >>/tmp/cartinstall.log 2>&1
fi
ln -s /etc/apache2/sites-available/cartulary.conf /etc/apache2/sites-enabled/000-cartulary.conf >>/tmp/cartinstall.log 2>&1
sed -i "s,\[CONFROOT\],$INSTALLDIR,g" /etc/apache2/sites-available/cartulary.conf
a2enmod headers
/etc/init.d/apache2 restart >>/tmp/cartinstall.log 2>&1
##: 7. Set permissions
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Setting File Permissions. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
touch $INSTALLDIR/logs/error.log
touch $INSTALLDIR/logs/debug.log
touch $INSTALLDIR/logs/access.log
chown www-data $INSTALLDIR/logs >>/tmp/cartinstall.log 2>&1
chown www-data $INSTALLDIR/logs/* >>/tmp/cartinstall.log 2>&1
chown www-data $INSTALLDIR/spool >>/tmp/cartinstall.log 2>&1
##: 8. Create Cartulary Config File
clear
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Create cartulary.conf file. '
echo '## '
echo '## - Your fully qualified domain name(fqdn) will be '
echo '## how the outside world gets to your site. '
echo '## Example: my.server.com. '
echo '## '
echo '## - If you mess up, just go edit: '
echo "## $INSTALLDIR/conf/cartulary.conf by hand to "
echo '## correct after the install finishes. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
php $INSTALLDIR/bin/confcheck.php minimal 2>>/tmp/cartinstall.log
##: 9. Check database version
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Bring database current. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
php $INSTALLDIR/bin/dbcheck.php 2>>/tmp/cartinstall.log
##: 10. Install Cartulary Admin User
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Create Admin user account. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
php $INSTALLDIR/bin/usercheck.php 2>>/tmp/cartinstall.log >/tmp/cartinstall.pass
##: 11. Install Crontab
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Installing CRON jobs. '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
php $INSTALLDIR/bin/syscheck.php >>/tmp/cartinstall.log 2>&1
/etc/init.d/cron restart >>/tmp/cartinstall.log 2>&1
##: 12. Do an initial feed scan
echo
echo '#####################################################'
echo '##---------------------------------------------------'
echo '## '
echo '## Do initial feed/outline scan and river build. '
echo '## ** This may take a minute or so. Be patient. :-) '
echo '## '
echo '##---------------------------------------------------'
echo '#####################################################'
echo
php $INSTALLDIR/bin/outlinescan.php
cd $INSTALLDIR/aggrivate
node aggrivate
cd -
php $INSTALLDIR/bin/feedscan.php
php $INSTALLDIR/bin/buildrivers.php
##: All done!
clear
echo '##-----------------------------------------------------------------------------------'
echo
echo 'Installation is finished. Just point your browser at the FQDN you gave above and '
echo 'log in with:'
echo
cat /tmp/cartinstall.pass
echo
echo 'At this point it would be a good idea to peruse through the cartulary.conf file and '
echo 'make any tweaks you want before using the system in earnest, like setting the'
echo 'timezone and setting up a more secure password for the cartulary MySQL user.'
echo
echo 'It would also be a good idea to tweak your php.ini file to allow for larger file '
echo 'uploads (for enclosures) and longer script timeouts (for slow feeds). '
echo
echo 'A log of the installation is at /tmp/cartinstall.log Enjoy!'
echo
echo '##-----------------------------------------------------------------------------------'
##: Remove the password temp file.
rm /tmp/cartinstall.pass