-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunitydownload.sh
executable file
·76 lines (61 loc) · 1.98 KB
/
unitydownload.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
#!/bin/bash
html=$(curl "https://unity3d.com/get-unity/download/archive" | grep -Po 'unityhub:.+?(?=\")')
resultNum="0"
TMPNAME=unitytmp
while [ "$resultNum" == "0" ]
do
echo "------------"
echo Enter your desired Unity version \(e.g. 20XX.X.XXfX\), or \'exit\' to quit:
read uinput
# If user types in exit, exit the application
if [[ ${uinput,,} = exit ]]; then
break
fi
# Stores the entire version string with the hash internally
search=$(echo "$html" | grep -Po "\Q${uinput}\E.+")
# Greps for search keyword inside each result's version name
displaySearch=$(echo "$html" | grep -P "\Q${uinput}\E.*?(?=\/)")
# Displays whole version name scoped out from the keyword
# so searching '17' gives you '2017.X.Y' and not '17.X.Y'
displaySearch=$(echo "$displaySearch" | grep -Po "(?<=\Q//\E).+?(?=\/)")
# Get search result count
resultNum=$(echo -n "$displaySearch" | grep -c '^')
echo ""
if [ "$resultNum" = "0" ]; then
echo "No results found."
resultNum="0"
elif [ "$resultNum" = "1" ]; then
echo "Version found:"
echo "$displaySearch"
download="-"
while [ "$download" = "-" ]; do
echo "Would you like to download it? (y/n)"
read download
if [[ ${download,,} = y ]] || [[ ${download,,} = yes ]]; then
echo "Downloading.."
# Get *only* the version hash
versionHash=$(echo "$search" | grep -Po "\/.+")
link="http://beta.unity3d.com/download${versionHash}/UnitySetup"
echo "$link"
exitcode=$(wget "$link" -O "$TMPNAME")
if [ $? -ne 0 ]; then
echo "An error occurred while attempting to download $displaySearch"
resultNum="0"
fi
chmod +x "$TMPNAME"
filename="UnitySetup-${displaySearch//./_}"
mv "$TMPNAME" "${filename}"
echo "------------"
echo "Unity Setup installer file '${filename}' downloaded"
elif [[ ${download,,} = n ]] || [[ ${download,,} = no ]]; then
resultNum="0"
else
download="-"
fi
done
else
echo "$resultNum results found:"
echo "$displaySearch"
resultNum="0"
fi
done