-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateProject.sh
More file actions
executable file
·336 lines (286 loc) · 9.15 KB
/
Copy pathCreateProject.sh
File metadata and controls
executable file
·336 lines (286 loc) · 9.15 KB
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
336
#!/bin/bash
# An improved version of getFNA from Caleb Cornett.
rm -rf .git # Remove the Template git directory. Was causing "fatal: unknown index entry format 0x63740000"
# Checks if dotnet is installed
function checkDotnet()
{
# || { echo >&2 "ERROR: dotnet is not installed. Please install dotnet to download the t4 tool."; exit 1; }
command -v dotnet > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo >&2 "ERROR: dotnet is not installed. Please install dotnet to download the t4 tool."
exit 1
fi
}
# Checks if t4 is installed and installs it if it isnt
function installT4()
{
checkDotnet
command -v t4 > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
dotnet tool install -g dotnet-t4
fi
}
# Checks if git is installed
function checkGit()
{
git --version > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo -e >&2 "\033[1;31mERROR:\033[0;31m Git is not installed. Please install git to download FNA.\033[0m"
exit 1
fi
}
# Clones FNA from the git master branch
function downloadFNA()
{
checkGit
echo "Downloading FNA..."
git -C $MY_DIR clone https://github.com/FNA-XNA/FNA.git --depth 1 --recursive
if [ $? -eq 0 ]; then
echo -e "\033[32mFinished downloading! \033[0m"
else
echo -e >&2 "\033[1;31mERROR:\033[0;31m Unable to download successfully. Maybe try again later?\033[0m"
fi
}
# Pulls FNA from the git master branch
function updateFNA()
{
checkGit
echo "Updating to the latest git version of FNA..."
git -C "$MY_DIR/FNA" pull --recurse-submodules
if [ $? -eq 0 ]; then
echo "Finished updating!"
else
echo >&2 "ERROR: Unable to update."
exit 1
fi
}
# Downloads and extracts prepackaged archive of native libraries ("fnalibs")
function getLibs()
{
# Downloading
echo "Downloading latest fnalibs..."
curl https://fna.flibitijibibo.com/archive/fnalibs.tar.bz2 > "$MY_DIR/fnalibs.tar.bz2" # http doesnt work anymore in flibitijibibo.com. So use https instead
if [ $? -eq 0 ]; then
echo "Finished downloading!"
else
>&2 echo "ERROR: Unable to download successfully."
exit 1
fi
# Decompressing
echo "Decompressing fnalibs..."
mkdir -p $MY_DIR/fnalibs
tar xjC $MY_DIR/fnalibs -f $MY_DIR/fnalibs.tar.bz2
if [ $? -eq 0 ]; then
echo "Finished decompressing!"
echo ""
rm $MY_DIR/fnalibs.tar.bz2
else
>&2 echo "ERROR: Unable to decompress successfully."
exit 1
fi
}
# Get the directory of this script
MY_DIR=$(dirname "$BASH_SOURCE")
# gather input
# FNA
if [ ! -d "$MY_DIR/FNA" ]; then
echo -e "\033[36mDownload FNA \033[36;1m(y/n)\033[0;36m? \033[0m"
read shouldDownload
else
echo -e "\033[36mUpdate FNA \033[36;1m(y/n)\033[0;36m? \033[0m"
read shouldUpdate
fi
if [ ! -d "$MY_DIR/fnalibs" ]; then
echo -e "\033[36mDownload fnalibs \033[36;1m(y/n)\033[0;36m? \033[0m"
read shouldDownloadLibs
else
echo -e "\033[36mRedownload fnalibs \033[36;1m(y/n)\033[0;36m? \033[0m"
read shouldDownloadLibs
fi
# act on the input#!/bin/bash
# An improved version of getFNA from Caleb Cornett.
# Checks if dotnet is installed
function checkDotnet()
{
# || { echo >&2 "ERROR: dotnet is not installed. Please install dotnet to download the t4 tool."; exit 1; }
command -v dotnet > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo >&2 "ERROR: dotnet is not installed. Please install dotnet to download the t4 tool."
exit 1
fi
}
# Checks if t4 is installed and installs it if it isnt
function installT4()
{
checkDotnet
command -v t4 > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
dotnet tool install -g dotnet-t4
fi
}
# Checks if git is installed
function checkGit()
{
git --version > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo -e >&2 "\033[1;31mERROR:\033[0;31m Git is not installed. Please install git to download FNA.\033[0m"
exit 1
fi
}
# Clones FNA from the git master branch
function downloadFNA()
{
checkGit
echo "Downloading FNA..."
git -C $MY_DIR clone https://github.com/FNA-XNA/FNA.git --depth 1 --recursive
if [ $? -eq 0 ]; then
echo -e "\033[32mFinished downloading! \033[0m"
else
echo -e >&2 "\033[1;31mERROR:\033[0;31m Unable to download successfully. Maybe try again later?\033[0m"
fi
}
# Pulls FNA from the git master branch
function updateFNA()
{
checkGit
echo "Updating to the latest git version of FNA..."
git -C "$MY_DIR/FNA" pull --recurse-submodules
if [ $? -eq 0 ]; then
echo "Finished updating!"
else
echo >&2 "ERROR: Unable to update."
exit 1
fi
}
# Downloads and extracts prepackaged archive of native libraries ("fnalibs")
function getLibs()
{
# Downloading
echo "Downloading latest fnalibs..."
curl https://fna.flibitijibibo.com/archive/fnalibs.tar.bz2 > "$MY_DIR/fnalibs.tar.bz2" # http doesnt work anymore in flibitijibibo.com. So use https instead
if [ $? -eq 0 ]; then
echo "Finished downloading!"
else
>&2 echo "ERROR: Unable to download successfully."
exit 1
fi
# Decompressing
echo "Decompressing fnalibs..."
mkdir -p $MY_DIR/fnalibs
tar xjC $MY_DIR/fnalibs -f $MY_DIR/fnalibs.tar.bz2
if [ $? -eq 0 ]; then
echo "Finished decompressing!"
echo ""
rm $MY_DIR/fnalibs.tar.bz2
else
>&2 echo "ERROR: Unable to decompress successfully."
exit 1
fi
}
# Get the directory of this script
MY_DIR=$(dirname "$BASH_SOURCE")
# gather input
# FNA
if [ ! -d "$MY_DIR/FNA" ]; then
echo -e "\033[36mDownload FNA \033[36;1m(y/n)\033[0;36m? \033[0m"
read shouldDownload
else
echo -e "\033[36mUpdate FNA \033[36;1m(y/n)\033[0;36m? \033[0m"
read shouldUpdate
fi
if [ ! -d "$MY_DIR/fnalibs" ]; then
echo -e "\033[36mDownload fnalibs \033[36;1m(y/n)\033[0;36m? \033[0m"
read shouldDownloadLibs
else
echo -e "\033[36mRedownload fnalibs \033[36;1m(y/n)\033[0;36m? \033[0m"
read shouldDownloadLibs
fi
# act on the input
# FNA
if [[ $shouldDownload =~ ^[Yy]$ ]]; then
downloadFNA
elif [[ $shouldUpdate =~ ^[Yy]$ ]]; then
updateFNA
fi
# FNALIBS
if [[ $shouldDownloadLibs =~ ^[Yy]$ ]]; then
getLibs
fi
# install t4 engine
installT4
# Only proceed from here if we have not yet renamed the project
if [ ! -d "$MY_DIR/#project#" ]; then
# old project_name folder already renamed so we are all done here
exit 1
fi
echo -e "\033[32mEnter the project name to use for your folder and csproj file or 'exit' to quit:\033[0m "
read newProjectName
if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then
exit 1
fi
files=$(grep -rl "#project#" $MY_DIR)
for file in "${files[@]}"; do
sed -i "s/#project#/$newProjectName/g" $file
done
mv "#project#.sln" "$newProjectName.sln"
mv "#project#/#project#.sln" "#project#/$newProjectName.sln"
mv "#project#/#project#.csproj" "#project#/$newProjectName.csproj"
mv "#project#/#project#.csproj.user" "#project#/$newProjectName.csproj.user"
mv "#project#" "$newProjectName"
git init
git submodule add --depth 1 https://github.com/prime31/Nez.git
cd Nez
git submodule init
git submodule update --depth 1
command -v pbcopy > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo -e "\n\n\033[35;1mManually run the following command:\033[0m\n\n\033[1m\tnuget restore Nez/Nez.sln && msbuild Nez/Nez.sln && msbuild /t:restore $newProjectName && msbuild $newProjectName.sln\033[0m\n\n"
else
echo -e "\033[1mnuget restore Nez/Nez.sln && msbuild Nez/Nez.sln && msbuild /t:restore $newProjectName && msbuild $newProjectName.sln\033[0m" | pbcopy
echo ""
echo -e "\033[1mA build command was copied to your clipboard. Paste and run it now.\033[0m\n\n"
fi
# FNA
if [[ $shouldDownload =~ ^[Yy]$ ]]; then
downloadFNA
elif [[ $shouldUpdate =~ ^[Yy]$ ]]; then
updateFNA
fi
# FNALIBS
if [[ $shouldDownloadLibs =~ ^[Yy]$ ]]; then
getLibs
fi
# install t4 engine
installT4
# Only proceed from here if we have not yet renamed the project
if [ ! -d "$MY_DIR/#project#" ]; then
# old project_name folder already renamed so we are all done here
exit 1
fi
echo -e "\033[32mEnter the project name to use for your folder and csproj file or 'exit' to quit:\033[0m "
read newProjectName
if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then
exit 1
fi
files=$(grep -rl "#project#" $MY_DIR)
for file in "${files[@]}"; do
sed -i "s/#project#/$newProjectName/g" $file
done
mv "#project#.sln" "$newProjectName.sln"
mv "#project#/#project#.sln" "#project#/$newProjectName.sln"
mv "#project#/#project#.csproj" "#project#/$newProjectName.csproj"
mv "#project#/#project#.csproj.user" "#project#/$newProjectName.csproj.user"
mv "#project#" "$newProjectName"
git init
git submodule add --depth 1 https://github.com/prime31/Nez.git
cd Nez
git submodule init
git submodule update --depth 1
command -v pbcopy > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo -e "\n\n\033[35;1mManually run the following command:\033[0m\n\n\033[1m\tnuget restore Nez/Nez.sln && msbuild Nez/Nez.sln && msbuild /t:restore $newProjectName && msbuild $newProjectName.sln\033[0m\n\n"
else
echo -e "\033[1mnuget restore Nez/Nez.sln && msbuild Nez/Nez.sln && msbuild /t:restore $newProjectName && msbuild $newProjectName.sln\033[0m" | pbcopy
echo ""
echo -e "\033[1mA build command was copied to your clipboard. Paste and run it now.\033[0m\n\n"
fi