-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·184 lines (154 loc) · 3.38 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
#!/bin/zsh
#
# Configuration & Setup for Roomies
#
echo "Welcome to the installation of Roomies."
echo
install() {
ask_questions
echo "Checking out $GIT_TAG..."
git checkout $GIT_TAG
echo "...done"
echo "Running setup..."
make setup
echo "...done"
echo "Writing configuration..."
write_configuration
echo "...done"
echo -n "Creating postgres DB or running migration..."
db
echo "done"
echo -n "Updating zshrc..."
update_zshrc
echo "done"
echo "Finished. Please run 'npm start' now."
echo
}
ask_questions() {
echo "Available git tags:"
echo "---------------------"
git tag -l
echo "---------------------"
read -p "Which tag shall be checked out? " GIT_TAG
read -p "Roomies Facebook App Secret? " FB_APP_SECRET
}
write_configuration() {
SESSION_SECRET=`openssl rand -base64 32`
(
cat <<ENDCONF
module.exports = {
db: {
database: 'roomies'
, username: 'roomies'
, password: '12345'
, options: {
host: 'localhost'
, port: 5432
, dialect: 'postgres'
, logging: false
}
}
, facebook: {
clientID: 496325690405368
, clientSecret: "$FB_APP_SECRET"
, callbackUrl: '/auth/facebook/callback'
, channelUrl: '/fbchannel'
, checkStatus: true
, useCookies: true
, parseXfbml: false
}
, http: {
protocol: 'http'
, port: 3000
, hostname: '0.0.0.0'
, displayedHostname: 'localhost'
, displayedPort: 9001
}
, connectTimeout: {
time: 16000
}
, enableClustering: true
, logging: {
errorLogLevel: "info"
, requestLogLevel: "info"
, disableErrorLog: false
, disableRequestLog: true
}
, clientsideJavaScriptOptimizations: {
debug: false
, gzip: true
, minify: true
}
, livereload: {
exts: [
"html", "css", "scss", "js", "hbs"
, "png", "gif", "jpg"
]
}
, sessionSecret: "$SESSION_SECRET"
}
ENDCONF
) > config.development.js
cat config.development.js > config.production.js
}
db() {
psql -h localhost -U postgres -c "CREATE ROLE roomies WITH PASSWORD '12345' LOGIN" >/dev/null 2>&1
psql -h localhost -U postgres -c "CREATE DATABASE roomies WITH OWNER roomies" >/dev/null 2>&1
mkdir config/
(
cat <<ENDCONF
{
"development": {
"username": "roomies"
, "password": "12345"
, "database": "roomies"
, "host": "localhost"
, "dialect": "postgres"
, "port": 5432
}
, "test": {
"username": "roomies"
, "password": "12345"
, "database": "roomies_test"
, "host": "localhost"
, "dialect": "postgres"
, "port": 5432
}
, "production": {
"username": "roomies"
, "password": "12345"
, "database": "roomies"
, "host": "localhost"
, "dialect": "postgres"
, "port": 5432
}
}
ENDCONF
) > config/config.json
# figure out if table already exists and we need to do a migration
echo -n "Checking if Communities Table already exists..."
TABLE_EXISTS=`psql -U postgres -t -h localhost -d roomies -c "SELECT true FROM pg_tables WHERE tablename = 'Communities'";`
TABLE_EXISTS=`echo $TABLE_EXISTS | tr -d ' '`
if [ "$TABLE_EXISTS" == "t" ]; then
echo "yes."
echo -n "Running migrations..."
./node_modules/.bin/sequelize -m >/dev/null 2>&1
echo "done."
fi
echo -n "Cleaning created files..."
rm config/config.json
rmdir config
echo "done"
}
update_zshrc() {
if ! grep -Fxq "DISABLE_AUTO_UPDATE=true" ~/.zshrc
then
echo 'DISABLE_AUTO_UPDATE=true' >> ~/.zshrc
fi
if ! grep -Fxq 'export NODE_ENV="production"' ~/.zshrc
then
echo 'export NODE_ENV="production"' >> ~/.zshrc
fi
source ~/.zshrc
}
install