forked from FriendUPCloud/friendup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·300 lines (256 loc) · 9.13 KB
/
install.sh
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
#!/bin/bash
# install.sh
# Admin Fetches friendup from git, runs this script, which
# installs dependencies, and autobuilds the Friend Core dir structure
#
sudo apt-get install dialog
declare -i INSTALL_SCRIPT_NUMBER=0
dialog --backtitle "Friend installer" --yesno " Welcome to Friend\n\n\
This script will install FriendCore on your machine.\n\n
Do you want to proceed with installation?" 10 45
if [ $? -eq "1" ]; then
clear
exit 1
fi
#echo ""
#echo "=====Configuration..."
#echo "========================================================="
#echo
INSTALL_ON_EXISTING_DB="N"
USE_DEFAULT_DB_STRUCTURE="Y"
while true; do
dbhost='localhost'
dbport=3306
dbname='friendup'
dbuser='friendup'
dbpass='friendup1'
dialog --backtitle "Friend installer" --yesno "Do you want to install Friend on an existing database?" 8 45
if [ $? = "0" ]
then
INSTALL_ON_EXISTING_DB="Y"
else
INSTALL_ON_EXISTING_DB="N"
fi
#read mysql db root password
mysqlRootPass=$(dialog --backtitle "Friend installer" --inputbox "Enter mysql root password:" 8 45 --output-fd 1)
if [ $? = "1" ]
then
clear
exit 1
fi
dialog --defaultno --backtitle "Friend installer" --yesno "Default mysql settings:\n\n\
host: $dbhost\n\
port: $dbport\n\
database: $dbname\n\
user: $dbuser\n\
password: $dbpass\n\n\
Do you want to use the default settings?" 15 50
if [ $? = "1" ]
then
dbhost=$(dialog --backtitle "Friend installer" --inputbox "Please enter the mysql host name:" 8 45 --output-fd 1)
if [ $? = "1" ]; then
clear
exit 1
fi
dbport=$(dialog --backtitle "Friend installer" --inputbox "Please enter the mysql database port:" 8 45 --output-fd 1)
if [ $? = "1" ]; then
clear
exit 1
fi
dbname=$(dialog --backtitle "Friend installer" --inputbox "Please enter the mysql database name:" 8 45 --output-fd 1)
if [ $? = "1" ]; then
clear
exit 1
fi
dbuser=$(dialog --backtitle "Friend installer" --inputbox "Please enter the user name:" 8 45 --output-fd 1)
if [ $? = "1" ]; then
clear
exit 1
fi
dbpass=$(dialog --backtitle "Friend installer" --inputbox "Please enter the user password:" 8 45 --output-fd 1)
if [ $? = "1" ]; then
clear
exit 1
fi
fi
dialog --defaultno --backtitle "Friend installer" --yesno "Using the following values for connecting to mysql:\n\n\
root password: $mysqlRootPass\n\
host name: $dbhost\n\
database port: $dbport\n\
database name: $dbname\n\
user name: $dbuser\n\
user password: $dbpass\n\n\
Please check the values and confirm..." 15 60
if [ $? = "0" ]; then
break;
fi
done
clear
#echo ""
#echo "=====Checking linux distribution..."
#echo "========================================================="
# check system
if cat /etc/*-release | grep ^ID | grep ubuntu; then
echo "ubuntu distro found"
if cat /etc/*-release | grep ^VERSION_ID | grep 14; then
echo "version 14"
INSTALL_SCRIPT_NUMBER=1
elif cat /etc/*-release | grep ^VERSION_ID | grep 15; then
echo "version 15"
INSTALL_SCRIPT_NUMBER=1
elif cat /etc/*-release | grep ^VERSION_ID | grep 16; then
echo "version 16"
INSTALL_SCRIPT_NUMBER=2
elif cat /etc/*-release | grep ^VERSION_ID | grep 17; then
echo "version 17"
INSTALL_SCRIPT_NUMBER=2
elif cat /etc/*-release | grep ^VERSION_ID | grep 18; then
echo "version 18"
INSTALL_SCRIPT_NUMBER=2
else
echo "version other"
INSTALL_SCRIPT_NUMBER=0
fi
elif cat /etc/*-release | grep ^ID | grep debian; then
echo "debian distro found"
if cat /etc/*-release | grep ^VERSION_ID | grep 8; then
echo "version 8"
INSTALL_SCRIPT_NUMBER=1
elif cat /etc/*-release | grep ^VERSION_ID | grep 9; then
echo "version 9"
INSTALL_SCRIPT_NUMBER=2
else
echo "version other"
INSTALL_SCRIPT_NUMBER=0
fi
elif cat /etc/*-release | grep ^ID | grep mint; then
echo "mint distro found"
if cat /etc/*-release | grep ^VERSION_ID | grep 16; then
echo "version 16"
INSTALL_SCRIPT_NUMBER=1
elif cat /etc/*-release | grep ^VERSION_ID | grep 17; then
echo "version 17"
INSTALL_SCRIPT_NUMBER=1
elif cat /etc/*-release | grep ^VERSION_ID | grep 18; then
echo "version 18"
INSTALL_SCRIPT_NUMBER=2
else
echo "version other"
INSTALL_SCRIPT_NUMBER=0
fi
else
INSTALL_SCRIPT_NUMBER=-1
fi
echo ""
echo "=====Installing dependencies..."
echo "========================================================="
if [ "$INSTALL_SCRIPT_NUMBER" -eq "1" ];then
sudo apt-get install libssh2-1-dev libssh-dev libssl-dev libaio-dev \
php5-cli php5-curl php5-mysql php5-gd php5-imap mysql-server \
libmysqlclient-dev build-essential libmatheval-dev libmagic-dev \
libgd-dev libwebsockets-dev rsync valgrind-dbg libxml2-dev php5-readline \
cmake ssh phpmyadmin make
elif [ "$INSTALL_SCRIPT_NUMBER" -eq "2" ];then
sudo apt-get install libssh2-1-dev libssh-dev libssl-dev libaio-dev \
mysql-server \
php-curl libmysqlclient-dev build-essential libmatheval-dev libmagic-dev \
libgd-dev rsync valgrind-dbg libxml2-dev cmake make libwebsockets-dev libssh-dev
else
dialog --backtitle "Friend installer" --msgbox "Supported linux version not found!\n\n\
Write to us: developer@friendos.com" 8 40
clear
exit 1
fi
# set up mysql database + user + access
# echo "removing old database, if it exists: $mysql"
# sudo rm $mysql
# echo "initializing database $mysql"
# localhost/phpmyadmin
# username: root
# password: ubpaul
# need to first setup a user account for the MySQL "root" user, using an unencrypted password.
# echo "Enter mysql username, followed by [ENTER]"
#read mysqlusername
mysqlconnect="--host=$dbhost --port=$dbport --user=root --password=$mysqlRootPass"
mysqlconnectdb=$mysqlconnect" --database=$dbname"
echo "Skipping database if it exists"
dbexists=`mysqlshow $mysqlconnect $dbname | grep Tables`
if [ -z "$dbexists" ]; then
# no db
# echo "no db named $dbname, creating"
# mysql $mysqlconnect \
# --execute="DROP DATABASE $dbname"
echo "create database"
mysql $mysqlconnect \
--execute="CREATE DATABASE $dbname;"
echo "create db user $dbuser"
mysql $mysqlconnect \
--execute="DROP USER '$dbuser'@'localhost';"
mysql $mysqlconnect \
--execute="CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbpass';"
mysql $mysqlconnect \
--execute="GRANT ALL ON $dbname.* TO '$dbuser'@'localhost'; FLUSH PRIVILEGES;"
echo "create tables"
mysql $mysqlconnectdb \
--execute="SOURCE db/FriendCoreDatabase.sql"
# TBD: point instead to a clean, pristine database template, with one or two users
# already setup, such as admin, and simple user (non-admin group)
# maybe try: user: guest, password: guest
#
# /*-- INSERT INTO `FUser` (`Name`,`Password`) VALUES ("guest","guest" ); */
#INSERT INTO `FUser` (`ID`,`Name`,`Password`) VALUES (1,"guest",CONCAT("{S6}",SHA2(CONCAT("HASHED",SHA2("guest",256)),256)));
else
echo "found db $dbname, skipping"
fi
echo ""
echo "=====Compilation process in progress..."
echo "========================================================="
cd friendup
make setup
# sets up all the directories properly
make clean setup compile install
# make clean - clean all objects and binaries
# make setup - create required directories and files
# make compile - compile source in debug mode
# make install - install all generated components to build directory
# this creates a build/ folder in the friendup root directory
# next, need to add cfg.ini file to build/cfg/ folder
# generate default file from example in docs/cfg.ini.example
echo ""
echo "=====Generating cfg.ini file..."
echo "========================================================="
# cd build/cfg
echo "[DatabaseUser]" > build/cfg/cfg.ini
echo "login = $dbuser" >> build/cfg/cfg.ini
echo "password = $dbpass" >> build/cfg/cfg.ini
echo "host = $dbhost" >> build/cfg/cfg.ini
echo "dbname = $dbname" >> build/cfg/cfg.ini
echo "port = $dbport" >> build/cfg/cfg.ini
echo " " >> build/cfg/cfg.ini
# was 3389
echo "[FriendCore]" >> build/cfg/cfg.ini
echo "fchost = localhost" >> build/cfg/cfg.ini
echo "port = 6502" >> build/cfg/cfg.ini
echo "fcupload = storage/" >> build/cfg/cfg.ini
echo " " >> build/cfg/cfg.ini
echo "[Core]" >> build/cfg/cfg.ini
echo "port = 6502" >> build/cfg/cfg.ini
echo "SSLEnable = 0" >> build/cfg/cfg.ini
#echo ""
#echo "=====Installation complete"
#echo "========================================================="
dialog --backtitle "Friend installer" --yesno " Installation complete.\n\n\
Once FriendCore is launched, you can access your local machine at:\n\
http://localhost:6502\n\n\
Would you like to launch FriendCore?" 12 45
if [ $? = "0" ]
then
clear
cd build/
echo "launching FriendCore in background"
nohup ./FriendCore >> /dev/null &
else
clear
echo "You can start FriendCore from the build folder."
fi
echo "FriendUP installation comleted :)"