build-jellyfin.ps1 8.0 KB

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