PowerShell/Scripts/start-calibre-server.ps1

33 lines
1.0 KiB
PowerShell
Raw Normal View History

2021-08-26 10:46:12 +02:00
<#
2021-07-16 16:49:42 +02:00
.SYNOPSIS
2021-09-20 12:29:49 +02:00
start-calibre-server.ps1 [<port>]
2021-07-16 16:49:42 +02:00
.DESCRIPTION
2021-09-20 12:29:49 +02:00
Starts a local Calibre server as background process (Web port number is 8099 by default).
2021-07-16 16:49:42 +02:00
.EXAMPLE
PS> .\start-calibre-server.ps1
2021-08-29 17:50:03 +02:00
.NOTES
Author: Markus Fleschutz · License: CC0
2021-07-16 16:49:42 +02:00
.LINK
https://github.com/fleschutz/PowerShell
#>
2021-09-20 12:32:24 +02:00
param([int]$port = 8099)
2021-09-20 12:29:49 +02:00
2021-07-16 16:49:42 +02:00
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
2021-09-20 12:29:49 +02:00
"Step 1/2: Searching for Calibre Server executable..."
& calibre-server --version
2021-07-16 16:49:42 +02:00
if ($lastExitCode -ne "0") { throw "Can't execute 'calibre-server' - make sure Calibre is installed and available" }
2021-09-20 12:29:49 +02:00
"Step 2/2: Starting Calibre Server as background process..."
& calibre-server --port $port --num-per-page 100 --userdb $HOME/CalibreUsers.sqlite --log $HOME/CalibreServer.log --daemonize $HOME/'Calibre Library'
2021-07-16 16:49:42 +02:00
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2021-09-20 12:29:49 +02:00
"✔️ started Calibre Server with port $port in $Elapsed sec"
2021-07-16 16:49:42 +02:00
exit 0
} catch {
2021-09-16 20:19:10 +02:00
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
2021-07-16 16:49:42 +02:00
exit 1
}