2023-10-31 12:20:46 +01:00
|
|
|
|
<#
|
2021-07-16 16:49:42 +02:00
|
|
|
|
.SYNOPSIS
|
2023-11-24 13:53:56 +01:00
|
|
|
|
Installs the Calibre server (needs admin rights)
|
2021-07-16 16:49:42 +02:00
|
|
|
|
.DESCRIPTION
|
2023-11-24 13:53:56 +01:00
|
|
|
|
This PowerShell script installs and starts a local Calibre server as background process.
|
2021-10-16 16:50:10 +02:00
|
|
|
|
.PARAMETER port
|
|
|
|
|
Specifies the Web port number (8099 by default)
|
2021-07-16 16:49:42 +02:00
|
|
|
|
.EXAMPLE
|
2023-08-06 21:35:36 +02:00
|
|
|
|
PS> ./install-calibre-server.ps1
|
2023-11-24 13:53:56 +01:00
|
|
|
|
⏳ (1/5) Updating package infos...
|
|
|
|
|
...
|
2021-07-16 16:49:42 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-01-30 10:49:30 +01:00
|
|
|
|
.NOTES
|
2022-05-02 11:15:52 +02:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-07-16 16:49:42 +02:00
|
|
|
|
#>
|
|
|
|
|
|
2023-04-06 09:04:27 +02:00
|
|
|
|
#Requires -RunAsAdministrator
|
|
|
|
|
|
2023-11-24 13:53:56 +01:00
|
|
|
|
param([int]$port = 8099, [string]$mediaFolder = "$HOME/Calibre Library", [string]$userDB = "$HOME/CalibreUsers.sqlite", [string]$logfile = "$HOME/CalibreServer.log")
|
2021-09-20 12:29:49 +02:00
|
|
|
|
|
2021-07-16 16:49:42 +02:00
|
|
|
|
try {
|
2024-05-12 12:54:50 +02:00
|
|
|
|
if (-not $IsLinux) { throw "Sorry, currently only supported on Linux" }
|
2021-07-16 16:49:42 +02:00
|
|
|
|
|
2024-05-12 12:54:50 +02:00
|
|
|
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
2023-04-06 09:04:27 +02:00
|
|
|
|
|
2024-05-12 12:54:50 +02:00
|
|
|
|
"⏳ (1/5) Updating package infos..."
|
|
|
|
|
& sudo apt update -y
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "'apt update' failed" }
|
2023-04-06 09:04:27 +02:00
|
|
|
|
|
2024-05-12 12:54:50 +02:00
|
|
|
|
"⏳ (2/5) Installing Calibre package..."
|
|
|
|
|
& sudo apt install calibre -y
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "'apt install calibre' failed" }
|
2021-07-16 16:49:42 +02:00
|
|
|
|
|
2024-05-12 12:54:50 +02:00
|
|
|
|
Write-Host "⏳ (3/5) Searching for Calibre server executable... " -noNewline
|
|
|
|
|
& calibre-server --version
|
|
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'calibre-server' - make sure Calibre server is installed and available" }
|
2023-04-06 09:24:32 +02:00
|
|
|
|
|
2024-05-12 12:54:50 +02:00
|
|
|
|
"⏳ (4/5) Creating media folder at: $mediaFolder ... (if non-existent)"
|
|
|
|
|
mkdir $mediaFolder
|
2021-07-16 16:49:42 +02:00
|
|
|
|
|
2024-05-12 12:54:50 +02:00
|
|
|
|
"⏳ (5/5) Starting Calibre server as background process..."
|
|
|
|
|
& calibre-server --port $port --num-per-page 100 --userdb $userDB --log $logfile --daemonize $HOME/'Calibre Library'
|
|
|
|
|
|
|
|
|
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
|
|
|
|
"✔️ Installed Calibre server on port $port in $($elapsed)s (media at: $mediaFolder, user DB: $userDB, log to: $logfile)"
|
|
|
|
|
exit 0 # success
|
2021-07-16 16:49:42 +02:00
|
|
|
|
} catch {
|
2024-05-12 12:54:50 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
2021-07-16 16:49:42 +02:00
|
|
|
|
}
|