forked from prime31/FNA-VSCode-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFNA-linux.sh
executable file
·170 lines (142 loc) · 4.52 KB
/
getFNA-linux.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
#!/bin/bash
# Program: getFNA
# Author: Caleb Cornett
# Usage: ./getFNA.sh
# Description: Quick and easy way to install a local copy of FNA and its native libraries.
# 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 >&2 "ERROR: Git is not installed. Please install git to download FNA."
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 "Finished downloading!"
else
echo >&2 "ERROR: Unable to download successfully. Maybe try again later?"
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"
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 xjf $MY_DIR/fnalibs.tar.bz2 -C $MY_DIR/fnalibs
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
read -p "Download FNA (y/n)? " shouldDownload
else
read -p "Update FNA (y/n)? " shouldUpdate
fi
if [ ! -d "$MY_DIR/fnalibs" ]; then
read -p "Download fnalibs (y/n)? " shouldDownloadLibs
else
read -p "Redownload fnalibs (y/n)? " 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_name" ]; then
# old project_name folder already renamed so we are all done here
exit 1
fi
read -p "Enter the project name to use for your folder and csproj file or 'exit' to quit: " newProjectName
if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then
exit 1
fi
# any files that need to have project_name replaced with the new project name should be here
files=(project_name.sln .gitignore project_name/project_name.csproj project_name/Game1.cs project_name/DemoComponent.cs project_name/DefaultScene.cs project_name/Program.cs .vscode/tasks.json .vscode/settings.json .vscode/launch.json .vscode/buildEffects.sh .vscode/processT4Templates.sh)
for file in "${files[@]}"; do
sed -i "s/project_name/$newProjectName/g" $file
done
mv project_name.sln "$newProjectName.sln"
mv project_name/project_name.csproj "project_name/$newProjectName.csproj"
mv project_name/project_name.csproj.user "project_name/$newProjectName.csproj.user"
mv project_name "$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
printf "\n\nManually run the following command:\n\nnuget restore Nez/Nez.sln && msbuild Nez/Nez.sln && msbuild /t:restore $newProjectName && msbuild $newProjectName.sln\n\n"
else
echo "nuget restore Nez/Nez.sln && msbuild Nez/Nez.sln && msbuild /t:restore $newProjectName && msbuild $newProjectName.sln" | pbcopy
echo ""
echo "A build command was copied to your clipboard. Paste and run it now."
echo ""
fi