build-jellyfin.ps1 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. [switch]$InstallTrayApp,
  12. [ValidateSet('Debug','Release')][string]$BuildType = 'Release',
  13. [ValidateSet('Quiet','Minimal', 'Normal')][string]$DotNetVerbosity = 'Minimal',
  14. [ValidateSet('win','win7', 'win8','win81','win10')][string]$WindowsVersion = 'win',
  15. [ValidateSet('x64','x86', 'arm', 'arm64')][string]$Architecture = 'x64'
  16. )
  17. $ProgressPreference = 'SilentlyContinue' # Speedup all downloads by hiding progress bars.
  18. #PowershellCore and *nix check to make determine which temp dir to use.
  19. if(($PSVersionTable.PSEdition -eq 'Core') -and (-not $IsWindows)){
  20. $TempDir = mktemp -d
  21. }else{
  22. $TempDir = $env:Temp
  23. }
  24. #Create staging dir
  25. New-Item -ItemType Directory -Force -Path $InstallLocation
  26. $ResolvedInstallLocation = Resolve-Path $InstallLocation
  27. $ResolvedUXLocation = Resolve-Path $UXLocation
  28. function Build-JellyFin {
  29. if(($Architecture -eq 'arm64') -and ($WindowsVersion -ne 'win10')){
  30. Write-Error "arm64 only supported with Windows10 Version"
  31. exit
  32. }
  33. if(($Architecture -eq 'arm') -and ($WindowsVersion -notin @('win10','win81','win8'))){
  34. Write-Error "arm only supported with Windows 8 or higher"
  35. exit
  36. }
  37. Write-Verbose "windowsversion-Architecture: $windowsversion-$Architecture"
  38. Write-Verbose "InstallLocation: $ResolvedInstallLocation"
  39. Write-Verbose "DotNetVerbosity: $DotNetVerbosity"
  40. dotnet publish --self-contained -c $BuildType --output $ResolvedInstallLocation -v $DotNetVerbosity -p:GenerateDocumentationFile=false -p:DebugSymbols=false -p:DebugType=none --runtime `"$windowsversion-$Architecture`" Jellyfin.Server
  41. }
  42. function Install-FFMPEG {
  43. param(
  44. [string]$ResolvedInstallLocation,
  45. [string]$Architecture,
  46. [string]$FFMPEGVersionX86 = "ffmpeg-4.3-win32-shared"
  47. )
  48. Write-Verbose "Checking Architecture"
  49. if($Architecture -notin @('x86','x64')){
  50. Write-Warning "No builds available for your selected architecture of $Architecture"
  51. Write-Warning "FFMPEG will not be installed"
  52. }elseif($Architecture -eq 'x64'){
  53. Write-Verbose "Downloading 64 bit FFMPEG"
  54. Invoke-WebRequest -Uri https://repo.jellyfin.org/releases/server/windows/ffmpeg/jellyfin-ffmpeg.zip -UseBasicParsing -OutFile "$tempdir/ffmpeg.zip" | Write-Verbose
  55. }else{
  56. Write-Verbose "Downloading 32 bit FFMPEG"
  57. Invoke-WebRequest -Uri https://ffmpeg.zeranoe.com/builds/win32/shared/$FFMPEGVersionX86.zip -UseBasicParsing -OutFile "$tempdir/ffmpeg.zip" | Write-Verbose
  58. }
  59. Expand-Archive "$tempdir/ffmpeg.zip" -DestinationPath "$tempdir/ffmpeg/" -Force | Write-Verbose
  60. if($Architecture -eq 'x64'){
  61. Write-Verbose "Copying Binaries to Jellyfin location"
  62. Get-ChildItem "$tempdir/ffmpeg" | ForEach-Object {
  63. Copy-Item $_.FullName -Destination $installLocation | Write-Verbose
  64. }
  65. }else{
  66. Write-Verbose "Copying Binaries to Jellyfin location"
  67. Get-ChildItem "$tempdir/ffmpeg/$FFMPEGVersionX86/bin" | ForEach-Object {
  68. Copy-Item $_.FullName -Destination $installLocation | Write-Verbose
  69. }
  70. }
  71. Remove-Item "$tempdir/ffmpeg/" -Recurse -Force -ErrorAction Continue | Write-Verbose
  72. Remove-Item "$tempdir/ffmpeg.zip" -Force -ErrorAction Continue | Write-Verbose
  73. }
  74. function Install-NSSM {
  75. param(
  76. [string]$ResolvedInstallLocation,
  77. [string]$Architecture
  78. )
  79. Write-Verbose "Checking Architecture"
  80. if($Architecture -notin @('x86','x64')){
  81. Write-Warning "No builds available for your selected architecture of $Architecture"
  82. Write-Warning "NSSM will not be installed"
  83. }else{
  84. Write-Verbose "Downloading NSSM"
  85. # [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  86. # Temporary workaround, file is hosted in an azure blob with a custom domain in front for brevity
  87. Invoke-WebRequest -Uri http://files.evilt.win/nssm/nssm-2.24-101-g897c7ad.zip -UseBasicParsing -OutFile "$tempdir/nssm.zip" | Write-Verbose
  88. }
  89. Expand-Archive "$tempdir/nssm.zip" -DestinationPath "$tempdir/nssm/" -Force | Write-Verbose
  90. if($Architecture -eq 'x64'){
  91. Write-Verbose "Copying Binaries to Jellyfin location"
  92. Get-ChildItem "$tempdir/nssm/nssm-2.24-101-g897c7ad/win64" | ForEach-Object {
  93. Copy-Item $_.FullName -Destination $installLocation | Write-Verbose
  94. }
  95. }else{
  96. Write-Verbose "Copying Binaries to Jellyfin location"
  97. Get-ChildItem "$tempdir/nssm/nssm-2.24-101-g897c7ad/win32" | ForEach-Object {
  98. Copy-Item $_.FullName -Destination $installLocation | Write-Verbose
  99. }
  100. }
  101. Remove-Item "$tempdir/nssm/" -Recurse -Force -ErrorAction Continue | Write-Verbose
  102. Remove-Item "$tempdir/nssm.zip" -Force -ErrorAction Continue | Write-Verbose
  103. }
  104. function Make-NSIS {
  105. param(
  106. [string]$ResolvedInstallLocation
  107. )
  108. $env:InstallLocation = $ResolvedInstallLocation
  109. if($InstallNSIS.IsPresent -or ($InstallNSIS -eq $true)){
  110. & "$tempdir/nsis/nsis-3.04/makensis.exe" /D$Architecture /DUXPATH=$ResolvedUXLocation ".\deployment\windows\jellyfin.nsi"
  111. } else {
  112. & "makensis" /D$Architecture /DUXPATH=$ResolvedUXLocation ".\deployment\windows\jellyfin.nsi"
  113. }
  114. Copy-Item .\deployment\windows\jellyfin_*.exe $ResolvedInstallLocation\..\
  115. }
  116. function Install-NSIS {
  117. Write-Verbose "Downloading NSIS"
  118. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  119. 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
  120. Expand-Archive "$tempdir/nsis.zip" -DestinationPath "$tempdir/nsis/" -Force | Write-Verbose
  121. }
  122. function Cleanup-NSIS {
  123. Remove-Item "$tempdir/nsis/" -Recurse -Force -ErrorAction Continue | Write-Verbose
  124. Remove-Item "$tempdir/nsis.zip" -Force -ErrorAction Continue | Write-Verbose
  125. }
  126. function Install-TrayApp {
  127. param(
  128. [string]$ResolvedInstallLocation,
  129. [string]$Architecture
  130. )
  131. Write-Verbose "Checking Architecture"
  132. if($Architecture -ne 'x64'){
  133. Write-Warning "No builds available for your selected architecture of $Architecture"
  134. Write-Warning "The tray app will not be available."
  135. }else{
  136. Write-Verbose "Downloading Tray App and copying to Jellyfin location"
  137. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  138. Invoke-WebRequest -Uri https://github.com/jellyfin/jellyfin-windows-tray/releases/latest/download/JellyfinTray.exe -UseBasicParsing -OutFile "$installLocation/JellyfinTray.exe" | Write-Verbose
  139. }
  140. }
  141. if(-not $SkipJellyfinBuild.IsPresent -and -not ($InstallNSIS -eq $true)){
  142. Write-Verbose "Starting Build Process: Selected Environment is $WindowsVersion-$Architecture"
  143. Build-JellyFin
  144. }
  145. if($InstallFFMPEG.IsPresent -or ($InstallFFMPEG -eq $true)){
  146. Write-Verbose "Starting FFMPEG Install"
  147. Install-FFMPEG $ResolvedInstallLocation $Architecture
  148. }
  149. if($InstallNSSM.IsPresent -or ($InstallNSSM -eq $true)){
  150. Write-Verbose "Starting NSSM Install"
  151. Install-NSSM $ResolvedInstallLocation $Architecture
  152. }
  153. if($InstallTrayApp.IsPresent -or ($InstallTrayApp -eq $true)){
  154. Write-Verbose "Downloading Windows Tray App"
  155. Install-TrayApp $ResolvedInstallLocation $Architecture
  156. }
  157. #Copy-Item .\deployment\windows\install-jellyfin.ps1 $ResolvedInstallLocation\install-jellyfin.ps1
  158. #Copy-Item .\deployment\windows\install.bat $ResolvedInstallLocation\install.bat
  159. Copy-Item .\LICENSE $ResolvedInstallLocation\LICENSE
  160. if($InstallNSIS.IsPresent -or ($InstallNSIS -eq $true)){
  161. Write-Verbose "Installing NSIS"
  162. Install-NSIS
  163. }
  164. if($MakeNSIS.IsPresent -or ($MakeNSIS -eq $true)){
  165. Write-Verbose "Starting NSIS Package creation"
  166. Make-NSIS $ResolvedInstallLocation
  167. }
  168. if($InstallNSIS.IsPresent -or ($InstallNSIS -eq $true)){
  169. Write-Verbose "Cleanup NSIS"
  170. Cleanup-NSIS
  171. }
  172. if($GenerateZip.IsPresent -or ($GenerateZip -eq $true)){
  173. Compress-Archive -Path $ResolvedInstallLocation -DestinationPath "$ResolvedInstallLocation/jellyfin.zip" -Force
  174. }
  175. Write-Verbose "Finished"