This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
forked from parse-community/parse-server
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.sh
executable file
·209 lines (171 loc) · 4.81 KB
/
bootstrap.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
#!/bin/sh
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
BOLD='\033[1m'
CHECK="${GREEN}\xE2\x9C\x93${NC}"
DEFAULT_MONGODB_URI='mongodb://127.0.0.1:27017/parse'
confirm() {
DEFAULT=$1;
shift
printf "$@"
read -r YN
if [ "$YN" = "" ] && [ "$DEFAULT" = 'N' ]; then
exit 1
elif [ "$YN" != "" ] && [ "$YN" != "y" ] && [ "$YN" != "Y" ]; then
echo 'Bye Bye!'
exit 1
fi
}
genstring() {
local l=$1
[ "$l" == "" ] && l=40
LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c ${l}
}
check_node() {
node=`which node 2>&1`
ret=$?
if [ $ret -eq 0 ] && [ -x "$node" ]; then
echo "${CHECK} node:" $(node -v)
(exit 0)
else
echo "parse-server cannot be installed without Node.js." >&2
exit 1
fi
}
check_npm() {
npm=`which npm 2>&1`
ret=$?
if [ $ret -eq 0 ] && [ -x "$npm" ]; then
echo "${CHECK} npm:" $(npm -v)
(exit 0)
else
echo "parse-server cannot be installed without npm." >&2
exit 1
fi
}
echo ''
echo '
`.-://////:-..`
`:/oooooooooooooooo+:.`
`:+oooooooooooooooooooooo+/`
:+ooooooooooooooooooooooooooo/.
.+oooooooooooooo/:.....-:+ooooooo-
.+ooooooooooooo/` .:///:-` -+oooooo:
`+ooooooooooooo: `/ooooooo+- `ooooooo-
:oooooooooooooo :ooooooooo+` /oooooo+
+ooooooooooooo/ +ooooooooo+ /ooooooo.
oooooooooooooo+ ooooooooo` .oooooooo.
+ooooooooooo+/: `ooooooo` .:ooooooooo.
:ooooooo+.````````````` /+oooooooooo+
`+oooooo- `ooo+ /oooooooooooooooooooo-
.+ooooo/ :/:` -ooooooooooooooooooo:
.+ooooo+:-..-/ooooooooooooooooooo-
:+ooooooooooooooooooooooooooo/.
`:+oooooooooooooooooooooo+/`
`:/oooooooooooooooo+:.`
`.-://////:-..`
parse-server
'
INSTALL_DIR=""
printf "Enter an installation directory\n"
printf "(%s): " "${PWD}"
read -r INSTALL_DIR
if [ "$INSTALL_DIR" = "" ]; then
INSTALL_DIR="${PWD}"
fi
echo ''
printf "This will setup parse-server in %s\n" "${INSTALL_DIR}"
confirm 'Y' 'Do you want to continue? (Y/n): '
check_node
check_npm
printf "Setting up parse-server in %s\n" "${INSTALL_DIR}"
if [ -d "${INSTALL_DIR}" ]; then
echo "${CHECK} ${INSTALL_DIR} exists"
else
mkdir -p "${INSTALL_DIR}"
echo "${CHECK} Created ${INSTALL_DIR}"
fi
cd "${INSTALL_DIR}"
if [ -f "package.json" ]; then
echo "\n${RED}package.json exists${NC}"
confirm 'N' "Do you want to continue? \n${RED}this will erase your configuration${NC} (y/N): "
fi
if [ -f 'config.json' ]; then
echo "\n${RED}config.json exists${NC}"
confirm 'N' "Do you want to continue? \n${RED}this will erase your configuration${NC} (y/N): "
fi
APP_NAME=''
i=0
while [ "$APP_NAME" = "" ]
do
[[ $i != 0 ]] && printf "${RED}An application name is required!${NC}\n"
printf "Enter your ${BOLD}Application Name${NC}: "
read -r APP_NAME
i=$(($i+1))
done
printf "Enter your ${BOLD}Application Id${NC} (leave empty to generate): "
read -r APP_ID
[[ $APP_ID = '' ]] && APP_ID=$(genstring) && printf "\n$APP_ID\n\n"
printf "Enter your ${BOLD}Master Key${NC} (leave empty to generate): "
read -r MASTER_KEY
[[ $MASTER_KEY = '' ]] && MASTER_KEY=$(genstring) && printf "\n$MASTER_KEY\n\n"
printf "Enter your ${BOLD}mongodbURI${NC} (%s): " $DEFAULT_MONGODB_URI
read -r MONGODB_URI
[[ $MONGODB_URI = '' ]] && MONGODB_URI="$DEFAULT_MONGODB_URI"
cat > ./config.json << EOF
{
"appId": "${APP_ID}",
"masterKey": "${MASTER_KEY}",
"appName": "${APP_NAME}",
"cloud": "./cloud/main",
"databaseURI": "${MONGODB_URI}"
}
EOF
echo "${CHECK} Created config.json"
# Make a proper npm app name
NPM_APP_NAME=$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
cat > ./package.json << EOF
{
"name": "$NPM_APP_NAME",
"description": "parse-server for $APP_NAME",
"scripts": {
"start": "parse-server config.json"
},
"dependencies": {
"parse-server": "^2.0.0"
}
}
EOF
echo "${CHECK} Created package.json"
if [ -d "./cloud/" ]; then
echo "${CHECK} cloud/ exists"
else
mkdir -p ./cloud
echo "${CHECK} Created cloud/"
fi
if [ -e "./cloud/main.js" ]; then
echo "${CHECK} cloud/main.js exists"
else
echo "${CHECK} Created cloud/main.js"
cat > ./cloud/main.js << EOF
// Cloud Code entry point
EOF
fi
if [ -d "./public/" ]; then
echo "${CHECK} public/ exists"
else
mkdir -p ./public
echo "${CHECK} Created public/"
fi
echo "\n${CHECK} running npm install\n"
npm install -s
CURL_CMD=$(cat << EOF
curl -X POST -H 'X-Parse-Application-Id: ${APP_ID}' \\
-H 'Content-Type: application/json' \\
-d '{"foo":"bar"}' http://localhost:1337/parse/classes/TestObject
EOF)
echo "\n${CHECK} Happy Parsing!\n\n"
echo "${CHECK} Make sure you have ${BOLD}mongo${NC} listening on ${BOLD}${MONGODB_URI}${NC}"
echo "${CHECK} start parse-server by running ${BOLD}npm start${NC}"
echo "${CHECK} Test your setup with:\n\n${CURL_CMD}\n"