build-jellyfin.ps1 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. [CmdletBinding()]
  2. param(
  3. [switch]$MakeNSIS,
  4. [switch]$InstallNSIS,
  5. [switch]$InstallFFMPEG,
  6. [switch]$InstallNSSM,
  7. [switch]$SkipJellyfinBuild,
  8. [switch]$GenerateZip,
  9. [string]$InstallLocation = "./dist/jellyfin-win-nsis",
  10. [string]$UXLocation = "../jellyfin-ux",
  11. [ValidateSet('Debug','Release')][string]$BuildType = 'Release',
  12. [ValidateSet('Quiet','Minimal', 'Normal')][string]$DotNetVerbosity = 'Minimal',
  13. [ValidateSet('win','win7', 'win8','win81','win10')][string]$WindowsVersion = 'win',
  14. [ValidateSet('x64','x86', 'arm', 'arm64')][string]$Architecture = 'x64'
  15. )
  16. #PowershellCore and *nix check to make determine which temp dir to use.
  17. if(($PSVersionTable.PSEdition -eq 'Core') -and (-not $IsWindows)){
  18. $TempDir = mktemp -d
  19. }else{
  20. $TempDir = $env:Temp
  21. }
  22. #Create staging dir
  23. New-Item -ItemType Directory -Force -Path $InstallLocation
  24. $ResolvedInstallLocation = Resolve-Path $InstallLocation
  25. $ResolvedUXLocation = Resolve-Path $UXLocation
  26. function Build-JellyFin {
  27. if(($Architecture -eq 'arm64') -and ($WindowsVersion -ne 'win10')){
  28. Write-Error "arm64 only supported with Windows10 Version"
  29. exit
  30. }
  31. if(($Architecture -eq 'arm') -and ($WindowsVersion -notin @('win10','win81','win8'))){
  32. Write-Error "arm only supported with Windows 8 or higher"
  33. exit
  34. }
  35. Write-Verbose "windowsversion-Architecture: $windowsversion-$Architecture"
  36. Write-Verbose "InstallLocation: $ResolvedInstallLocation"
  37. Write-Verbose "DotNetVerbosity: $DotNetVerbosity"
  38. dotnet publish --self-contained -c $BuildType --output $ResolvedInstallLocation -v $DotNetVerbosity -p:GenerateDocumentationFile=false -p:DebugSymbols=false -p:DebugType=none --runtime `"$windowsversion-$Architecture`" Jellyfin.Server
  39. }
  40. function Install-FFMPEG {
  41. param(
  42. [string]$ResolvedInstallLocation,
  43. [string]$Architecture
  44. )
  45. Write-Verbose "Checking Architecture"
  46. if($Architecture -notin @('x86','x64')){
  47. Write-Warning "No builds available for your selected architecture of $Architecture"
  48. Write-Warning "FFMPEG will not be installed"
  49. }elseif($Architecture -eq 'x64'){
  50. Write-Verbose "Downloading 64 bit FFMPEG"
  51. Invoke-WebRequest -Uri https://repo.jellyfin.org/releases/server/windows/ffmpeg/jellyfin-ffmpeg.zip -UseBasicParsing -OutFile "$tempdir/ffmpeg.zip" | Write-Verbose
  52. }else{
  53. Write-Verbose "Downloading 32 bit FFMPEG"
  54. Invoke-WebRequest -Uri https://ffmpeg.zeranoe.com/builds/win32/shared/ffmpeg-4.0.2-win32-shared.zip -UseBasicParsing -OutFile "$tempdir/ffmpeg.zip" | Write-Verbose
  55. }
  56. Expand-Archive "$tempdir/ffmpeg.zip" -DestinationPath "$tempdir/ffmpeg/" -Force | Write-Verbose
  57. if($Architecture -eq 'x64'){
  58. Write-Verbose "Copying Binaries to Jellyfin location"
  59. Get-ChildItem "$tempdir/ffmpeg" | ForEach-Object {
  60. Copy-Item $_.FullName -Destination $installLocation | Write-Verbose
  61. }
  62. }else{
  63. Write-Verbose "Copying Binaries to Jellyfin location"
  64. Get-ChildItem "$tempdir/ffmpeg/ffmpeg-4.0.2-win32-shared/bin" | ForEach-Object {
  65. Copy-Item $_.FullName -Destination $installLocation | Write-Verbose
  66. }
  67. }
  68. Remove-Item "$tempdir/ffmpeg/" -Recurse -Force -ErrorAction Continue | Write-Verbose
  69. Remove-Item "$tempdir/ffmpeg.zip" -Force -ErrorAction Continue | Write-Verbose
  70. }
  71. function Install-NSSM {
  72. param(
  73. [string]$ResolvedInstallLocation,
  74. [string]$Architecture
  75. )
  76. Write-Verbose "Checking Architecture"
  77. if($Architecture -notin @('x86','x64')){
  78. Write-Warning "No builds available for your selected architecture of $Architecture"
  79. Write-Warning "NSSM will not be installed"
  80. }else{
  81. Write-Verbose "Downloading NSSM"
  82. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  83. Invoke-WebRequest -Uri https://nssm.cc/ci/nssm-2.24-101-g897c7ad.zip -UseBasicParsing -OutFile "$tempdir/nssm.zip" | Write-Verbose
  84. }
  85. Expand-Archive "$tempdir/nssm.zip" -DestinationPath "$tempdir/nssm/" -Force | Write-Verbose
  86. if($Architecture -eq 'x64'){
  87. Write-Verbose "Copying Binaries to Jellyfin location"
  88. Get-ChildItem "$tempdir/nssm/nssm-2.24-101-g897c7ad/win64" | ForEach-Object {
  89. Copy-Item $_.FullName -Destination $installLocation | Write-Verbose
  90. }
  91. }else{
  92. Write-Verbose "Copying Binaries to Jellyfin location"
  93. Get-ChildItem "$tempdir/nssm/nssm-2.24-101-g897c7ad/win32" | ForEach-Object {
  94. Copy-Item $_.FullName -Destination $installLocation | Write-Verbose
  95. }
  96. }
  97. Remove-Item "$tempdir/nssm/" -Recurse -Force -ErrorAction Continue | Write-Verbose
  98. Remove-Item "$tempdir/nssm.zip" -Force -ErrorAction Continue | Write-Verbose
  99. }
  100. function Make-NSIS {
  101. param(
  102. [string]$ResolvedInstallLocation
  103. )
  104. $env:InstallLocation = $ResolvedInstallLocation
  105. if($InstallNSIS.IsPresent -or ($InstallNSIS -eq $true)){
  106. & "$tempdir/nsis/nsis-3.04/makensis.exe" /D$Architecture /DUXPATH=$ResolvedUXLocation ".\deployment\windows\jellyfin.nsi"
  107. } else {
  108. & "makensis" /D$Architecture /DUXPATH=$ResolvedUXLocation ".\deployment\windows\jellyfin.nsi"
  109. }
  110. Copy-Item .\deployment\windows\jellyfin_*.exe $ResolvedInstallLocation\..\
  111. }
  112. function Install-NSIS {
  113. Write-Verbose "Downloading NSIS"
  114. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  115. Invoke-WebRequest -Uri https://nchc.dl.sourceforge.net/project/nsis/NSIS%203/3.04/nsis-3.04.zip -UseBasicParsing -OutFile "$tempdir/nsis.zip" | Write-Verbose
  116. Expand-Archive "$tempdir/nsis.zip" -DestinationPath "$tempdir/nsis/" -Force | Write-Verbose
  117. }
  118. function Cleanup-NSIS {
  119. Remove-Item "$tempdir/nsis/" -Recurse -Force -ErrorAction Continue | Write-Verbose
  120. Remove-Item "$tempdir/nsis.zip" -Force -ErrorAction Continue | Write-Verbose
  121. }
  122. if(-not $SkipJellyfinBuild.IsPresent -and -not ($InstallNSIS -eq $true)){
  123. Write-Verbose "Starting Build Process: Selected Environment is $WindowsVersion-$Architecture"
  124. Build-JellyFin
  125. }
  126. if($InstallFFMPEG.IsPresent -or ($InstallFFMPEG -eq $true)){
  127. Write-Verbose "Starting FFMPEG Install"
  128. Install-FFMPEG $ResolvedInstallLocation $Architecture
  129. }
  130. if($InstallNSSM.IsPresent -or ($InstallNSSM -eq $true)){
  131. Write-Verbose "Starting NSSM Install"
  132. Install-NSSM $ResolvedInstallLocation $Architecture
  133. }
  134. #Copy-Item .\deployment\windows\install-jellyfin.ps1 $ResolvedInstallLocation\install-jellyfin.ps1
  135. #Copy-Item .\deployment\windows\install.bat $ResolvedInstallLocation\install.bat
  136. Copy-Item .\LICENSE $ResolvedInstallLocation\LICENSE
  137. if($InstallNSIS.IsPresent -or ($InstallNSIS -eq $true)){
  138. Write-Verbose "Installing NSIS"
  139. Install-NSIS
  140. }
  141. if($MakeNSIS.IsPresent -or ($MakeNSIS -eq $true)){
  142. Write-Verbose "Starting NSIS Package creation"
  143. Make-NSIS $ResolvedInstallLocation
  144. }
  145. if($InstallNSIS.IsPresent -or ($InstallNSIS -eq $true)){
  146. Write-Verbose "Cleanup NSIS"
  147. Cleanup-NSIS
  148. }
  149. if($GenerateZip.IsPresent -or ($GenerateZip -eq $true)){
  150. Compress-Archive -Path $ResolvedInstallLocation -DestinationPath "$ResolvedInstallLocation/jellyfin.zip" -Force
  151. }
  152. Write-Verbose "Finished"