Last active
March 5, 2018 03:26
-
-
Save zaki/6589335d8743bfb63fbcee80b6151544 to your computer and use it in GitHub Desktop.
Unity installer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Check-Version() | |
{ | |
$file = $args[0] | |
$lines = Get-Content "$file" -TotalCount 2 | |
return $lines[0].Trim(), $lines[1].Trim() | |
} | |
function Install-Component() | |
{ | |
$PATH = $args[0] | |
$FILE = [System.IO.Path]::GetFileNameWithoutExtension($PATH) | |
$exists = Test-Path "cache/$UNITY_VERSION/$FILE.exe" | |
if (-Not $exists) | |
{ | |
Write-Host "Downloading $FILE.exe" | |
New-Item "cache/$UNITY_VERSION/" -type directory -force | |
$client = New-Object System.Net.WebClient | |
$client.DownloadFile("http://download.unity3d.com/download_unity/$UNITY_CHANGESET/$PATH", "cache/$UNITY_VERSION/$FILE.exe") | |
} | |
else | |
{ | |
Write-Host "$FILE.exe already downloaded" | |
} | |
Start-Process -FilePath "./cache/$UNITY_VERSION/$FILE.exe" -ArgumentList '/S','/D=.\unity\' -Wait | |
} | |
function Is-Up-To-Date() | |
{ | |
$is_installed = Test-Path "unity/version.txt" | |
if ($is_installed) | |
{ | |
$installed = Check-Version(".\unity\version.txt") | |
$changeset = $installed[0] | |
$version = $installed[1] | |
if (($UNITY_CHANGESET -eq $changeset) -and ($UNITY_VERSION -eq $version)) | |
{ | |
Write-Host "Requested version $UNITY_VERSION is already installed" | |
return 1 | |
} | |
else | |
{ | |
Write-Host "Requested version /$UNITY_VERSION/ does not match installed version /$version/" | |
return 0 | |
} | |
} | |
Write-Host "No local unity installation found" | |
return 0 | |
} | |
$UNITY = Check-Version("./current.txt") | |
$UNITY_CHANGESET = $UNITY[0] | |
$UNITY_VERSION = $UNITY[1] | |
if (Is-Up-To-Date) | |
{ | |
Exit 0 | |
} | |
Install-Component "Windows64EditorInstaller/UnitySetup64.exe" | |
Install-Component "WindowsDocumentationInstaller/UnityDocumentationSetup.exe" | |
Install-Component "WindowsStandardAssetsInstaller/UnityStandardAssetsSetup.exe" | |
Install-Component "TargetSupportInstaller/UnitySetup-Windows-Support-for-Editor-$UNITY_VERSION.exe" | |
Install-Component "TargetSupportInstaller/UnitySetup-Android-Support-for-Editor-$UNITY_VERSION.exe" | |
Install-Component "TargetSupportInstaller/UnitySetup-iOS-Support-for-Editor-$UNITY_VERSION.exe" | |
Out-File -FilePath .\unity\version.txt -InputObject "$UNITY_CHANGESET`r`n$UNITY_VERSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UNITY_CHANGESET=$(sed -n '1p' ./current.txt) | |
UNITY_VERSION=$(sed -n '2p' ./current.txt) | |
function check_version() { | |
if [[ ! -f ./unity/version.txt ]] | |
then | |
return 1 | |
fi | |
changeset=$(sed -n '1p' ./unity/version.txt) | |
version=$(sed -n '2p' ./unity/version.txt) | |
if [[ $changeset == $UNITY_CHANGESET ]] && [[ $version == $UNITY_VERSION ]] | |
then | |
echo "Already up to date" | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
function install() { | |
path=$1 | |
file="cache/${UNITY_VERSION}/$(basename $path)" | |
mkdir -p "cache/${UNITY_VERSION}" | |
curl "http://download.unity3d.com/download_unity/${UNITY_CHANGESET}/${path}" > "${file}" | |
sudo installer -package "${file}" -target / | |
} | |
if check_version | |
then | |
exit 0 | |
fi | |
install "MacEditorInstaller/Unity.pkg" | |
install "MacDocumentationInstaller/Documentation.pkg" | |
install "MacExampleProjectInstaller/Examples.pkg" | |
install "MacStandardAssetsInstaller/StandardAssets.pkg" | |
install "MacEditorTargetInstaller/UnitySetup-Android-Support-for-Editor-${UNITY_VERSION}.pkg" | |
install "MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-${UNITY_VERSION}.pkg" | |
install "MacEditorTargetInstaller/UnitySetup-Windows-Support-for-Editor-${UNITY_VERSION}.pkg" | |
echo $UNITY_CHANGESET > unity/version.txt | |
echo -n $UNITY_VERSION >> unity/version.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment