-
Notifications
You must be signed in to change notification settings - Fork 257
/
configure.sh
executable file
·332 lines (290 loc) · 13 KB
/
configure.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
#!/bin/sh
#
# Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
#
# You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
# copy, modify, and distribute this software in source code or binary form for use
# in connection with the web services and APIs provided by Facebook.
#
# As with any software that integrates with the Facebook platform, your use of
# this software is subject to the Facebook Developer Principles and Policies
# [http://developers.facebook.com/policy/]. This copyright notice shall be
# included in all copies or substantial portions of the software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# This file performs the custom build logic to setup the Plugins
# in the unity project
# shellcheck disable=SC2039
TARGET_OS=NONE
TARGET_VERSION=NONE
SELECTED_VERSION=-1
copyright()
{
cat <<EOT
Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
EOT
}
help()
{
copyright
cat <<EOT
This script adjusts external references to Unity 3D for each of the Facebook SDK for Unity projects.
Usage:
./configure.sh
or
./configure.sh [Unity version]
Unity version: Exactly full definition as it appears. Ex: 2017.4.40f1, 2018.4.36f1, 2021.1.17f1
Examples:
./configure.sh <- Interactive
./configure.sh 2021.1.17f1 <- Use 2021.1.17f1 version
./configure.sh 2018.4.36f1 <- Use 2018.4.36f1 version
EOT
}
os_not_supported()
{
copyright
cat <<EOT
At this time this script does not support the operating system it is running on.
You will need to set the references to Unity by hand.
We are working to support this system, sorry for the inconvenience.
EOT
}
# Cheking working dir
if [ ! -f Facebook.sln ]; then
echo "Please, execute configure.sh script from root project directory"
exit 1
fi
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*)
os_not_supported
exit 1
;;
Darwin*)
TARGET_OS=MAC
;;
CYGWIN*)
os_not_supported
exit 1
;;
MINGW*)
os_not_supported
exit 1
;;
*)
os_not_supported
exit 1
esac
if [[ -z "$1" ]]
then
declare -a unity_versions
# Interactive process try to find versions
help
echo "Interactive mode, the following versions of unity have been found on your system."
# Old version
if [ -d "/Applications/Unity/Unity.app" ]; then
# We assume 2017 version
unity_versions+=("2017.x.x")
fi
# New versions Unity Hub
files=($(ls /Applications/Unity/Hub/Editor | tr '\n' '\0' | xargs -0 -n 1 basename))
for file in "${files[@]}"; do
if [[ $file == *"2017"* || $file == *"2018"* || $file == *"2019"* || $file == *"2020"* || $file == *"2021"* ]]; then
unity_versions+=("$file")
fi
done
while [[ $SELECTED_VERSION == -1 ]]
do
option=1
for version in "${unity_versions[@]}"; do
echo "$option- $version"
((option = option + 1))
done
read -r -p "Select unity version (Ctrl+C to cancel): " SELECTED_VERSION
if ! [[ $SELECTED_VERSION =~ ^[0-9]+$ ]] ; then
echo "Wrong input"
SELECTED_VERSION=-1
fi
if [[ "$SELECTED_VERSION" -ge "$option" ]] ; then
echo "Wrong option"
SELECTED_VERSION=-1
fi
done
((SELECTED_VERSION = SELECTED_VERSION - 1))
echo "You have selected ${unity_versions[SELECTED_VERSION]} version"
IFS='.' read -ra INPUT_VERSION <<< "${unity_versions[SELECTED_VERSION]}"
TARGET_VERSION=${INPUT_VERSION[0]}
FULL_VERSION=${unity_versions[SELECTED_VERSION]}
else
# No interactive process
IFS='.' read -ra INPUT_VERSION <<< "$1"
TARGET_VERSION=${INPUT_VERSION[0]}
FULL_VERSION=$1
case "$TARGET_VERSION" in
'2017'|'2018'|'2019'|'2020'|'2021')
echo "Full version name $FULL_VERSION selected."
echo "Family version $TARGET_VERSION selected."
;;
*)
echo "!Incorrect family version $TARGET_VERSION or not supported."
help
exit 1
;;
esac
fi
if [ $TARGET_OS = "NONE" ];
then
printf "!Target OS not selected.\n"
help
exit 1
fi
if [[ $TARGET_VERSION = "NONE" ]];
then
printf "!Unity family version not selected.\n"
help
exit 1
fi
TEMP_FILE=$(mktemp)
TEMP_FILE2=$(mktemp)
printf "\n"
#define full paths for unity version
case "$TARGET_VERSION" in
2017)
UNITY_MANAGED_DIR="/Applications/Unity/Unity.app/Contents/Managed/"
UNITY_UI_DIR="/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/"
UNITY_ENGINE_DIR="/Applications/Unity/Unity.app/Contents/Managed/"
UNITY_EXTENSIONS_DIR="/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/"
UNITY_NETWORKING_DIR="NONE"
;;
2018)
UNITY_MANAGED_DIR="/Applications/Unity/hub/Editor/$FULL_VERSION/Unity.app/Contents/Managed/"
UNITY_UI_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/UnityExtensions/Unity/GUISystem/"
UNITY_ENGINE_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Managed/UnityEngine/"
UNITY_EXTENSIONS_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/UnityExtensions/Unity/"
UNITY_NETWORKING_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/UnityExtensions/Unity/Networking/"
;;
2019)
#fix find template version
PRJ_TEMPLATE="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/"
TEMPLATE_VERSION=$(ls "$PRJ_TEMPLATE" | tr '\n' '\0' | xargs -0 -n 1 basename | grep universal)
UNITY_MANAGED_DIR="/Applications/Unity/hub/Editor/$FULL_VERSION/Unity.app/Contents/Managed/"
UNITY_UI_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/$TEMPLATE_VERSION/ScriptAssemblies/"
UNITY_ENGINE_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Managed/UnityEngine/"
UNITY_EXTENSIONS_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/UnityExtensions/Unity/"
UNITY_NETWORKING_DIR="NONE"
;;
2020)
#fix find template version
PRJ_TEMPLATE="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/"
TEMPLATE_VERSION=$(ls "$PRJ_TEMPLATE" | tr '\n' '\0' | xargs -0 -n 1 basename | grep universal)
UNITY_MANAGED_DIR="/Applications/Unity/hub/Editor/$FULL_VERSION/Unity.app/Contents/Managed/"
UNITY_UI_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/$TEMPLATE_VERSION/ScriptAssemblies/"
UNITY_ENGINE_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Managed/UnityEngine/"
UNITY_EXTENSIONS_DIR="NONE"
UNITY_NETWORKING_DIR="NONE"
;;
2021)
#fix find template version
PRJ_TEMPLATE="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/"
TEMPLATE_VERSION=$(ls "$PRJ_TEMPLATE" | tr '\n' '\0' | xargs -0 -n 1 basename | grep universal)
UNITY_MANAGED_DIR="/Applications/Unity/hub/Editor/$FULL_VERSION/Unity.app/Contents/Managed/"
UNITY_UI_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/$TEMPLATE_VERSION/ScriptAssemblies/"
UNITY_ENGINE_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/Managed/UnityEngine/"
UNITY_EXTENSIONS_DIR="NONE"
UNITY_NETWORKING_DIR="/Applications/Unity/Hub/Editor/$FULL_VERSION/Unity.app/Contents/NetStandard/"
;;
*)
printf "!Unknown version.\n"
exit 1
esac
# Set unity version for projects
sed -n "/\<PropertyGroup Condition=\"\'\$(UNITY_VERSION)\' == \'$TARGET_VERSION\'\"\>/,/<\/PropertyGroup>/p" UnityReferences.xml | grep -v PropertyGroup > "$TEMP_FILE"
# Set full paths for unity version
sed "s/\<UNITY_MANAGED_DIR\>.*\<\/UNITY_MANAGED_DIR\>/\<UNITY_MANAGED_DIR\>${UNITY_MANAGED_DIR//\//\\/}<\/UNITY_MANAGED_DIR\>/g" "$TEMP_FILE" > "$TEMP_FILE2"
sed "s/\<UNITY_UI_DIR\>.*\<\/UNITY_UI_DIR\>/\<UNITY_UI_DIR\>${UNITY_UI_DIR//\//\\/}<\/UNITY_UI_DIR\>/g" "$TEMP_FILE2" > "$TEMP_FILE"
sed "s/\<UNITY_ENGINE_DIR\>.*\<\/UNITY_ENGINE_DIR\>/\<UNITY_ENGINE_DIR\>${UNITY_ENGINE_DIR//\//\\/}<\/UNITY_ENGINE_DIR\>/g" "$TEMP_FILE" > "$TEMP_FILE2"
sed "s/\<UNITY_EXTENSIONS_DIR\>.*\<\/UNITY_EXTENSIONS_DIR\>/\<UNITY_EXTENSIONS_DIR\>${UNITY_EXTENSIONS_DIR//\//\\/}<\/UNITY_EXTENSIONS_DIR\>/g" "$TEMP_FILE2" > "$TEMP_FILE"
sed "s/\<UNITY_NETWORKING_DIR\>.*\<\/UNITY_NETWORKING_DIR\>/\<UNITY_NETWORKING_DIR\>${UNITY_NETWORKING_DIR//\//\\/}<\/UNITY_NETWORKING_DIR\>/g" "$TEMP_FILE" > "$TEMP_FILE2"
# Temp fix because the final result must to be in $TEMP_FILE
cat "$TEMP_FILE2" > "$TEMP_FILE"
cat "$TEMP_FILE"
# Checking paths
printf "\n"
directories=("UNITY_MANAGED_DIR" "UNITY_UI_DIR" "UNITY_ENGINE_DIR" "UNITY_EXTENSIONS_DIR" "UNITY_NETWORKING_DIR")
for TAG in "${directories[@]}"
do
echo $TAG
DIRECTORY_ARRAY=($(awk "/\<$TAG\>/, /\<\/$TAG\>/" "$TEMP_FILE" | sed -e "s/\<$TAG\>\(.*\)\<\/$TAG\>/\1/" | xargs))
DIRECTORY="${DIRECTORY_ARRAY[0]}"
if [ "$DIRECTORY" != 'NONE' ]; then
if [ ! -d "$DIRECTORY" ]; then
echo "Path $DIRECTORY not found."
exit 1
else
echo "Check $DIRECTORY Ok!"
fi
fi
done
line_add_from=$(grep -n '<PropertyGroup Condition="'\''$(UNITY_VERSION)'\'' == '\'''"$TARGET_VERSION"''\''">' UnityReferences.xml | awk '{print $1}' FS=":")
line_add_to_array=($(grep -n '<\/PropertyGroup>' UnityReferences.xml | awk '{print $1}' FS=":"))
#find next close
for close_tag_position in "${line_add_to_array[@]}"; do
if [[ "$close_tag_position" -ge "$line_add_from" ]] ; then
line_add_to=$close_tag_position
break
fi
done
line_add_from=$((line_add_from + 1))
line_add_to=$((line_add_to - 1))
if [ "$line_add_to" -ge "$line_add_from" ];
then
sed "$line_add_from,$line_add_to d" UnityReferences.xml > "$TEMP_FILE2"
mv "$TEMP_FILE2" UnityReferences.xml
fi
awk -v line_add_from=$line_add_from 'FNR==line_add_from{system("cat '"$TEMP_FILE"'")} 1' UnityReferences.xml > "$TEMP_FILE2"
awk '{ gsub(/\xef\xbb\xbf/,""); print }' "$TEMP_FILE2" > "$TEMP_FILE"
mv "$TEMP_FILE" UnityReferences.xml
echo " -> UnityReferences.xml Updated!"
# Set version
sed "s/\<UNITY_VERSION\>.*\<\/UNITY_VERSION\>/\<UNITY_VERSION\>$TARGET_VERSION<\/UNITY_VERSION\>/g" UnityReferences.xml > "$TEMP_FILE"
mv "$TEMP_FILE" UnityReferences.xml
# Only for Unity 2021: remove old System includes
if [[ $TARGET_VERSION = "2021" ]];
then
sed -i '' 's/<Reference Include="System.Xml.Linq" \/>//g' "UnitySDK/Assembly-CSharp.csproj"
sed -i '' 's/<Reference Include="System.Runtime.Serialization" \/>//g' "UnitySDK/Assembly-CSharp.csproj"
sed -i '' 's/<Reference Include="System.Core" \/>//g' "UnitySDK/Assembly-CSharp.csproj"
sed -i '' 's/<Reference Include="System.XML" \/>//g' "UnitySDK/Assembly-CSharp.csproj"
sed -i '' 's/<Reference Include="System" \/>//g' "UnitySDK/Assembly-CSharp.csproj"
fi
# Fix projects files
printf "\n"
projects=("Facebook.Unity" "Facebook.Unity.Settings" "Facebook.Unity.Android" "Facebook.Unity.Canvas" "Facebook.Unity.Editor" "Facebook.Unity.Tests" "UnitySDK" "Facebook.Unity.Windows")
for PROJECT in "${projects[@]}"
do
printf "Project: %s \n" "$PROJECT"
if [[ $PROJECT = "UnitySDK" ]];
then
PROJECT_FILE_NAME="Assembly-CSharp"
else
PROJECT_FILE_NAME=$PROJECT
fi
line_add_from=$(grep -n '<!-- BEGIN_UNITY_REFERENCES -->' "$PROJECT"/"$PROJECT_FILE_NAME".csproj | awk '{print $1}' FS=":")
line_add_to=$(grep -n '<!-- END_UNITY_REFERENCES -->' "$PROJECT"/"$PROJECT_FILE_NAME".csproj | awk '{print $1}' FS=":")
line_add_from=$((line_add_from + 1))
line_add_to=$((line_add_to - 1))
if [ "$line_add_to" -ge "$line_add_from" ];
then
sed "$line_add_from,$line_add_to d" "$PROJECT"/"$PROJECT_FILE_NAME".csproj > "$TEMP_FILE"
mv "$TEMP_FILE" "$PROJECT"/"$PROJECT_FILE_NAME".csproj
fi
awk -v line_add_from=$line_add_from 'FNR==line_add_from{system("cat '"$PROJECT"'/UnityReferences/'"$TARGET_VERSION"'.xml")} 1' "$PROJECT"/"$PROJECT_FILE_NAME".csproj > "$TEMP_FILE"
mv "$TEMP_FILE" "$PROJECT"/"$PROJECT_FILE_NAME".csproj
echo " -> $PROJECT/$PROJECT_FILE_NAME.csproj Updated!"
done
printf "\nThe script finished successfully."
exit 0