PowerShell/Scripts/start-calibre-server.ps1

36 lines
1.2 KiB
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-16 16:49:42 +02:00
.SYNOPSIS
2022-05-02 11:15:52 +02:00
Starts a Calibre server
2021-07-16 16:49:42 +02:00
.DESCRIPTION
2022-05-02 11:15:52 +02:00
This PowerShell script starts a local Calibre server as background process (using Web port 8099 by default).
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
2021-09-27 08:35:45 +02:00
PS> ./start-calibre-server
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
#>
2022-05-02 11:15:52 +02:00
param([int]$Port = 8099, [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 {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
2022-08-29 15:43:51 +02:00
"⏳ Step 1/2 - Searching for Calibre server executable..."
2021-09-20 12:29:49 +02:00
& calibre-server --version
2021-09-20 13:08:17 +02:00
if ($lastExitCode -ne "0") { throw "Can't execute 'calibre-server' - make sure Calibre server is installed and available" }
2021-07-16 16:49:42 +02:00
2022-08-29 15:43:51 +02:00
"⏳ Step 2/2 - Starting Calibre server as background process..."
" (Web port $Port, user DB at $UserDB, log file at $Logfile)"
2022-05-02 11:15:52 +02:00
& calibre-server --port $Port --num-per-page 100 --userdb $UserDB --log $Logfile --daemonize $HOME/'Calibre Library'
2021-07-16 16:49:42 +02:00
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2022-08-29 15:43:51 +02:00
"✔️ started Calibre server in $Elapsed sec"
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-07-16 16:49:42 +02:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-07-16 16:49:42 +02:00
exit 1
}