-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathparse-setup.sh
239 lines (194 loc) · 8.14 KB
/
parse-setup.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
# Instructions
# sudo apt-get update
# sudo apt-get -y install git bc
# git clone https://github.com/prodigy2m/parse-full-server-setup-digitalocean.git
# sh parse-full-server-setup-digitalocean/parse-setup.sh
# Done
# Start updating server to up-to-date
echo "------------------------------------------------------------------"
echo "################# Starting Step-by-Step #########################"
echo "------------------------------------------------------------------"
echo "------------------------------------------------------------------"
echo "####################### REQUIREMENTS ############################"
echo " ---- DOMAIN NAME - DIGITAL OCEAN ACCOUNT - At least $5 Plan -----"
echo "------------------------------------------------------------------"
echo "------------------------------------------------------------------"
echo "########################## AGREEMENT ############################"
echo " I take no responsibilities on any of my code, or what happens after you run this script. Good Luck!"
echo "------------------------------------------------------------------"
echo -p "Do you have everything you need to start? (y/n)?"
read choice
case $choice in
y)
clear
sudo apt-get -y upgrade
# sudo apt-get -y update
echo "------------------------------------------------------------------"
echo "######################### SWAP SETUP $5 Server ##################"
echo "------------------------------------------------------------------"
echo "This section is for creating SWAP memory for smallest servers in DigitalOcean"
echo ""
echo "Are you using the CHEAPEST DigitalOcean Plan? (y/n)? "
read swap
case $swap in
y)
echo "Creating SWAP memory"
sudo fallocate -l 4G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# check if swap created
free -m
echo "Your SWAP Memory was increased. Good luck in next steps"
;;
n)
echo "Continue without SWAP changes";
;;
esac
sleep 2
echo "- Installing Node Essential. -"
sleep 1
cd ~
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
sudo -E bash ./nodesource_setup.sh
sudo apt-get -y install nodejs build-essential git
sudo apt-get -y install libkrb5-dev
echo "- Installing Express. -"
sleep 1
npm install -g express
npm link express
echo "- Installing NGINX Server. -"
sleep 1
sudo apt-get -y install nginx
sudo service nginx stop
# echo "Installing WS dependency"
# sleep 1
# sudo npm install ws
echo "- Installing MongoDb Org. -"
sleep 1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get -y update
sudo apt-get -y install mongodb-org
service mongod status
echo " ############### PARSE INSTALL #################"
sleep 5
echo "- Installing Parse Server (Example) -"
sleep 1
git clone https://github.com/ParsePlatform/parse-server-example.git
cd /root/parse-server-example/
npm install
echo "- Installing Parse Dashboard -"
sleep 1
# cd ~/parse-server-example
cd ..
git clone https://github.com/ParsePlatform/parse-dashboard.git
cd parse-dashboard
npm install -g parse-dashboard
echo "- Installing Forever and Forever-Service for Running Production -"
sleep 1
npm install -g forever
npm install -g forever-service
echo " ############### SSL INSTALL #################"
sleep 2
echo "- Installing SSL Licence. -"
sleep 1
sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
cd /opt/letsencrypt
./letsencrypt-auto certonly --standalone
echo " ########### CONGFIGURATION PROCESS #############"
sleep 1
echo "You must have DOMAIN name assigned to this server for it to work."
echo -p "Do you have DOMAIN name assigned to this server? (y/n)?"
read choice
case $choice in
y)
echo "Enter your domain name (WITHOUT -> http/https): "
read input
domain=$input
sed 's/domain/'"$input"'/g' /root/parse-full-server-setup-digitalocean/default_sample > /etc/nginx/sites-available/default
echo "Your SSH for nginx is all setup and done."
sleep 2
echo "- Porting NGINX and MongoDb SSL Licence. -"
sleep 2
# Had to do it this way because dynamic domain didn't work in SH , had to export dynamic name to BASH
export domain
bash ~/parse-full-server-setup-digitalocean/mongoSSL.sh
;;
n)
echo "Please assign a DOMAIN name for this server to work and re-run this script again";
;;
esac
echo "- Starting NGINX. -"
sleep 1
sudo service nginx restart
echo "- Configuring Autostart for Parse Server & Livequery & Parse Dashboard -"
sleep 2
cd ~/parse-server-example
sudo forever-service install parse-server --script index.js
sudo start parse-server
cd ..
# Shutting forever off for now. - Only direct parse-dashboard works in /etc/init/parse-dashboard.conf
# cd parse-dashboard
# sudo forever-service install parse-dashboard --script ./Parse-Dashboard/index.js --scriptOptions " allowInsecureHTTP"
# sudo start parse-dashboard
echo "start on startup\nexec parse-dashboard --config /root/parse-dashboard/Parse-Dashboard/parse-dashboard-config.json --allowInsecureHTTP true" > /etc/init/parse-dashboard.conf
echo "- Generating Unique Master & Client Keys -"
sleep 2
# Generate 20 Alpha/NumericalCaseSensative ID's
NEW_ID_MASTER=$(cat /dev/urandom | tr -dc "a-zA-Z0-9" | fold -w 20 | head -n 1)
NEW_ID_CLIENT=$(cat /dev/urandom | tr -dc "a-zA-Z0-9" | fold -w 20 | head -n 1)
sleep 2
# Creating new user name and password for Parse Dashboard Login.
echo "############### IMPORTANT #######################"
echo "--- Please create your new User name and Password "
echo "--------------------------------------------------"
echo ""
echo "Parse User Name (Case sensative): "
read user
echo "Parse Password (Case sensative): "
read pass
sleep 1
sed 's/masterid/'"$NEW_ID_MASTER"'/g; s/appid/'"$NEW_ID_CLIENT"'/g; s/domain/'"$input"'/g; s/user-sample/'"$user"'/g; s/pass-sample/'"$pass"'/g' /root/parse-full-server-setup-digitalocean/parse-dashboard-config.json > /root/parse-dashboard/Parse-Dashboard/parse-dashboard-config.json
# Embed new Generated ID's to Index.js file for Parse Server
sed 's/masterid/'"$NEW_ID_MASTER"'/g; s/appid/'"$NEW_ID_CLIENT"'/g; s/domain/'"$input"'/g' /root/parse-full-server-setup-digitalocean/parse_app_setup.js > /root/parse-server-example/index.js
echo "- Creating First MongoDb Entry -"
sleep 2
curl -X POST \
-H "X-Parse-Application-Id: $NEW_ID_CLIENT" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sammy","cheatMode":false}' \
https://localhost:1337/parse/classes/GameScore
echo "------------------------------------------------------------------"
echo "############## IMPORTANT - WRITE THIS DOWN ######################"
echo " ---- MASTER KEY (Keep this private): $NEW_ID_MASTER"
echo " ---- CLIENT KEY: $NEW_ID_CLIENT"
echo ""
echo " ----------------------- LOCATIONS -------------------------------"
echo " - Parse Dashboard: http://$input:4040 - Sorry still can't get HTTPS to work"
echo " - Parse Server: https://$input/parse"
echo " - Parse LiveQuery Server: ws://$input:1337"
echo ""
echo "################ GOOD LUCK BUILDING STUFF ######################"
echo "------------------------------------------------------------------"
sleep 5
echo -p "Do you have everything you need to start? (y/n)?"
read restart_this
case $restart_this in
y)
echo "Rebooting now";
reboot
;;
n)
echo "- Some services might not work if you don't restart the server -"
;;
esac
;;
n)
echo "------------------------------------------------------------------"
echo "- You can restart this script once you have everything prepared. -"
echo "------------------------------------------------------------------"
;;
esac