-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunify.sh
More file actions
executable file
·62 lines (54 loc) · 2.47 KB
/
unify.sh
File metadata and controls
executable file
·62 lines (54 loc) · 2.47 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
#!/bin/bash
UNITY_REPO="${UNITY_REPO:-"$HOME/Unity/Hub/Editor"}"
UNITY_VARIANTS=(${UNITY_VARIANTS:-linux64_player_nondevelopment_mono linux64_withgfx_nondevelopment_mono})
UNITY_ENGINE_PREFIX="${UNITY_ENGINE_PREFIX:-Editor/Data/PlaybackEngines/LinuxStandaloneSupport/Variations}"
die() {
CODE=$1
shift
>&2 echo $*
exit $CODE
}
echo $1
# Determine Unity engine version
res=`find "$1" -name level0`
[ -z "$res" ] && die 1 Cannot find level0 file
version=`strings "$res" | head -n 1`
echo "Found Unity version: $version"
DATA_DIR=`dirname "$res"`
# Check Unity Engine
UNITY_PATH="$UNITY_REPO/$version"
if [ ! -f "$UNITY_PATH/Unity.tar.xz" ]; then
echo "Unity version not found locally"
echo "Fetching Unity archive ..."
mkdir -p "$UNITY_REPO"
curl --silent -X POST -H "Content-Type: application/json" -d '{"operationName":"GetRelease","variables":{"version":"'$version'","limit":300},"query":"query GetRelease($limit: Int, $skip: Int, $version: String!, $stream: [UnityReleaseStream!]) {\n getUnityReleases(\nlimit: $limit\nskip: $skip\nstream: $stream\nversion: $version\nentitlements: [XLTS]\n ) {\ntotalCount\nedges {\n node {\n version\n entitlements\n releaseDate\n unityHubDeepLink\n stream\n __typename\n }\n __typename\n}\n__typename\n }\n}"}' \
https://services.unity.com/graphql -o archive || die 3 Could not fetch Unity archive
HASH=`grep -oE "unityhub://$version/\w+" archive` || die 4 Unity version not found in archive
HASH=`echo $HASH | cut -d/ -f4`
URL="https://download.unity3d.com/download_unity/$HASH/LinuxEditorInstaller/Unity.tar.xz"
mkdir "$UNITY_REPO/$version"
echo "Downloading Unity from $URL ..."
curl $URL -o "$UNITY_PATH/Unity.tar.xz" || die 5 Could not fetch Unity engine archive
fi
EXTRACT=true
for UNITY_VARIANT in "${UNITY_VARIANTS[@]}"
do
if [ -d "$UNITY_PATH/$UNITY_ENGINE_PREFIX/$UNITY_VARIANT" ]; then
EXTRACT=false
break
fi
done
if [ "$EXTRACT" = true ]; then
echo "Extracting ${UNITY_VARIANTS[@]} from Unity.tar.xz"
# Ignoring error messages, as only one variant is probably in the archive
tar -xf "$UNITY_PATH/Unity.tar.xz" -C "$UNITY_PATH" "${UNITY_VARIANTS[@]/#/$UNITY_ENGINE_PREFIX/}" > /dev/null 2>&1
fi
for UNITY_VARIANT in "${UNITY_VARIANTS[@]}"
do
if [ -d "$UNITY_PATH/$UNITY_ENGINE_PREFIX/$UNITY_VARIANT" ]; then
cp -r "$UNITY_PATH/$UNITY_ENGINE_PREFIX/$UNITY_VARIANT"/* "$DATA_DIR/../" || die 6 Could not copy Unity Engine files
echo "Unity engine files copied."
exit 0
fi
done
die 7 None of the UNITY_VARIANTS found in the Unity engine archive