forked from cocos2d/cocos2d-objc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·337 lines (253 loc) · 8.74 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
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
332
333
334
335
#!/bin/bash
# ----------------------------------------------------
# Cocos2D Installer
# Author: Lars Birkemose (based on original script made by Dominik Hadl, Stuart Carnie and Ricardo Quesada)
# Date: June 2015
# ----------------------------------------------------
VERSION="Cocos2D-ObjC v3.4.x"
TEMPLATE_NAME="cocos2d v3.4"
EXECUTION_FOLDER="$(dirname $0)"
BASE_FOLDER="$HOME/Library/Developer/Xcode/Templates"
TEMPLATE_FOLDER="$HOME/Library/Developer/Xcode/Templates/$TEMPLATE_NAME"
LOG_FOLDER="/tmp/cocos2d-install"
LOG_FILE="${LOG_FOLDER}/error.log"
# ----------------------------------------------------
log_error()
{
echo ""
if [[ "$1" -eq "1" ]]; then
echo "Invoke the installer with the following options"
echo "./install.sh -i to install Cocos2D"
echo "./install.sh -u to update Cocos2D"
echo "./install.sh -d to delete Cocos2D"
elif [[ "$1" -eq "2" ]]; then
echo "Cocos2D is already installed"
echo "Invoke the installer with option -u, to update Cocos2D"
elif [[ "$1" -eq "3" ]]; then
echo "Installer was executes as root"
echo "To install Cocos2D, run './install.sh -i' from the folder where you downloaded Cocos2D"
else
echo "An unknown error occured"
fi
echo ""
echo "Cocos2d exited with an error"
echo "For details see: $LOG_FILE"
echo ""
mv -f "${LOG_FILE}" "${HOME}/Desktop/cocos2d-install.log"
exit "$1"
}
# ----------------------------------------------------
check_status()
{
if [[ "$?" != "0" ]]; then
log_error 99
fi
}
# ----------------------------------------------------
status_ok()
{
printf " [Ok]\n"
}
# ----------------------------------------------------
check_folders()
{
if [[ ! -d "$BASE_FOLDER" ]]; then
mkdir -p "$BASE_FOLDER" 1>/dev/null 2>>"${LOG_FILE}"
check_status
else
perms=$(find "$HOME/Library/Developer/Xcode/Templates" -name "Templates" -perm 0755 -type d)
if [[ ! "$perms" =~ "$BASE_FOLDER" ]]; then
didPrint=true
echo "In order to install templates you need access to the Xcode templates folder. Please enter your password if prompted."
sudo chmod 755 "$BASE_FOLDER" 1>/dev/null 2>>"${LOG_FILE}"
check_status
echo ""
fi
fi
if [[ ! -d "$HOME/Library/Developer/Xcode/Templates/File Templates" ]]; then
mkdir "$HOME/Library/Developer/Xcode/Templates/File Templates" 1>/dev/null 2>>"${LOG_FILE}"
check_status
fi
}
# ----------------------------------------------------
copy_files()
{
if [[ ! -d "$2" ]]; then
mkdir -p "$2"
fi
SOURCE_DIR="${EXECUTION_FOLDER}/${1}"
rsync -r --exclude=".*" "$SOURCE_DIR" "$2" 1>/dev/null 2>>"${LOG_FILE}"
check_status
}
# ----------------------------------------------------
download_chipmunk()
{
echo -n "Downloading Chipmunk"
DOWNLOAD_DIR="$EXECUTION_FOLDER/external"
mkdir -p "$DOWNLOAD_DIR" 1>/dev/null 2>>"${LOG_FILE}"
check_status
curl -L -# "https://github.com/slembcke/Chipmunk2D/archive/Cocos2D-3.0.zip" -o "$DOWNLOAD_DIR/chipmunk.zip" 1>/dev/null 2>>"${LOG_FILE}"
check_status
if [[ ! -d "${DOWNLOAD_DIR}/Chipmunk/" ]]; then
mkdir -p "${DOWNLOAD_DIR}/Chipmunk/" 1>/dev/null 2>>"${LOG_FILE}"
check_status
fi
tar -xf "$DOWNLOAD_DIR/chipmunk.zip" -C "${DOWNLOAD_DIR}/Chipmunk/" --strip-components=1 1>>"${LOG_FILE}" 2>>"${LOG_FILE}"
check_status
rm "$DOWNLOAD_DIR/chipmunk.zip"
status_ok
}
# ----------------------------------------------------
download_objectal()
{
echo -n "Downloading ObjectAL"
DOWNLOAD_DIR="$EXECUTION_FOLDER/external"
mkdir -p "$DOWNLOAD_DIR" 1>/dev/null 2>>"${LOG_FILE}"
check_status
curl -L -# "http://github.com/kstenerud/ObjectAL-for-iPhone/tarball/v2.2" -o "$DOWNLOAD_DIR/objectal.tar.gz" 1>/dev/null 2>>"${LOG_FILE}"
check_status
if [[ ! -d "${DOWNLOAD_DIR}/ObjectAL/" ]]; then
mkdir -p "${DOWNLOAD_DIR}/ObjectAL/" 1>/dev/null 2>>"${LOG_FILE}"
check_status
fi
tar -xf "$DOWNLOAD_DIR/objectal.tar.gz" -C "${DOWNLOAD_DIR}/ObjectAL/" --strip-components=1 1>>"${LOG_FILE}" 2>>"${LOG_FILE}"
check_status
rm "$DOWNLOAD_DIR/objectal.tar.gz"
status_ok
}
# ----------------------------------------------------
install_cocos2d()
{
echo -n "Installing Cocos2D Libraries"
LIBS_DIR="$TEMPLATE_FOLDER/Support/Libraries/cocos2d-base.xctemplate/Libraries/"
copy_files "cocos2d" "$LIBS_DIR"
copy_files "LICENSE_cocos2d.txt" "$LIBS_DIR"
LIBS_DIR="$TEMPLATE_FOLDER/Support/Libraries/cocos2d-effects.xctemplate/Libraries/"
copy_files "cocos2d" "$LIBS_DIR"
LIBS_DIR="$TEMPLATE_FOLDER/Support/Libraries/cocos2d-platform.xctemplate/Libraries/"
copy_files "cocos2d" "$LIBS_DIR"
LIBS_DIR="$TEMPLATE_FOLDER/Support/Libraries/cocos2d-support.xctemplate/Libraries/"
copy_files "cocos2d" "$LIBS_DIR"
LIBS_DIR="$TEMPLATE_FOLDER/Support/Libraries/cocos2d-ui.xctemplate/Libraries/"
copy_files "cocos2d-ui" "$LIBS_DIR"
LIBS_DIR="$TEMPLATE_FOLDER/Support/Libraries/cocos2d-ccb.xctemplate/Libraries/"
copy_files "cocos2d-ui/CCBReader" "$LIBS_DIR"
check_status
status_ok
}
# ----------------------------------------------------
install_chipmunk()
{
echo -n "Installing Chipmunk Libraries"
LIBS_DIR="$TEMPLATE_FOLDER/Support/Libraries/chipmunk.xctemplate/Libraries/"
copy_files "external/Chipmunk/objectivec/include" "$LIBS_DIR/Chipmunk/objectivec"
copy_files "external/Chipmunk/objectivec/src" "$LIBS_DIR/Chipmunk/objectivec"
copy_files "external/Chipmunk/include" "$LIBS_DIR/Chipmunk/chipmunk"
copy_files "external/Chipmunk/src" "$LIBS_DIR/Chipmunk/chipmunk"
check_status
status_ok
}
# ----------------------------------------------------
install_objectal()
{
echo -n "Installing ObjectAL Libraries"
LIBS_DIR="$TEMPLATE_FOLDER/Support/Libraries/objectal.xctemplate/Libraries/ObjectAL"
copy_files "external/ObjectAL/ObjectAL/ObjectAL (iOS)/" "$LIBS_DIR"
check_status
status_ok
}
# ----------------------------------------------------
install_templates()
{
echo -n "Installing Xcode Templates"
copy_files "templates/" "$TEMPLATE_FOLDER"
check_status
if [[ ! -d "$HOME/Library/Developer/Xcode/Templates/File Templates/$TEMPLATE_NAME" ]]; then
mkdir "$HOME/Library/Developer/Xcode/Templates/File Templates/$TEMPLATE_NAME" 1>/dev/null 2>>"${LOG_FILE}"
check_status
fi
TEMPLATE_FOLDER="$HOME/Library/Developer/Xcode/Templates/File Templates/$TEMPLATE_NAME"
OLD_DIR="$HOME/Library/Developer/Xcode/Templates/$TEMPLATE_NAME/"
mv -f "$OLD_DIR/CCNode class.xctemplate" "$TEMPLATE_FOLDER/CCNode class.xctemplate" 1>/dev/null 2>>"${LOG_FILE}"
check_status
status_ok
}
# ----------------------------------------------------
delete_libraries()
{
echo -n "Deleting Libraries"
rm -rf "$TEMPLATE_FOLDER"
check_status
status_ok
}
# ----------------------------------------------------
delete_templates()
{
echo -n "Deleting Templates"
rm -rf "$HOME/Library/Developer/Xcode/Templates/File Templates/$TEMPLATE_NAME/"
check_status
status_ok
}
# ----------------------------------------------------
# Script start
# ----------------------------------------------------
# Header
echo ""
echo "Cocos2D Installer (${VERSION})"
echo "--------------------------------------"
echo ""
# Root exectuion
if [[ "$(id -u)" == "0" ]]; then
log_error 3
fi
mkdir -p "${LOG_FOLDER}"
# Check for arguments
if [[ "${1}" = "-i" ]]; then
# ----------------------------------------------------
# Install
# ----------------------------------------------------
if [[ -d $TEMPLATE_FOLDER ]]; then
log_error 2
fi
check_folders
download_chipmunk
download_objectal
install_cocos2d
install_chipmunk
install_objectal
install_templates
echo ""
echo "Cocos2D was successfully installed"
echo ""
elif [[ "${1}" = "-u" ]]; then
# ----------------------------------------------------
# Update
# ----------------------------------------------------
delete_libraries
delete_templates
check_folders
download_chipmunk
download_objectal
install_cocos2d
install_chipmunk
install_objectal
install_templates
echo ""
echo "Cocos2D was successfully updated"
echo ""
elif [[ "${1}" = "-d" ]]; then
# ----------------------------------------------------
# Delete
# ----------------------------------------------------
delete_libraries
delete_templates
echo ""
echo "Cocos2D was successfully deleted"
echo ""
else
# ----------------------------------------------------
# Unknown
# ----------------------------------------------------
log_error 1
fi
rm -rf "${LOG_FOLDER}" 1>/dev/null 2>/dev/null