PowerShell/docs/install-calibre-server.md

123 lines
3.6 KiB
Markdown
Raw Normal View History

2024-11-08 12:38:20 +01:00
The *install-calibre-server.ps1* Script
===========================
2023-05-26 12:20:18 +02:00
2023-12-07 20:24:45 +01:00
This PowerShell script installs and starts a local Calibre server as background process.
2023-05-26 12:20:18 +02:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2023-05-26 12:20:18 +02:00
```powershell
2024-11-08 12:35:11 +01:00
/home/markus/Repos/PowerShell/scripts/install-calibre-server.ps1 [[-port] <Int32>] [[-mediaFolder] <String>] [[-userDB] <String>] [[-logfile] <String>] [<CommonParameters>]
2023-05-26 12:20:18 +02:00
2023-12-07 20:24:45 +01:00
-port <Int32>
2023-05-26 12:20:18 +02:00
Specifies the Web port number (8099 by default)
Required? false
Position? 1
Default value 8099
Accept pipeline input? false
Accept wildcard characters? false
2023-12-07 20:24:45 +01:00
-mediaFolder <String>
2023-05-26 12:20:18 +02:00
Required? false
Position? 2
2023-12-07 20:24:45 +01:00
Default value "$HOME/Calibre Library"
2023-05-26 12:20:18 +02:00
Accept pipeline input? false
Accept wildcard characters? false
2023-12-07 20:24:45 +01:00
-userDB <String>
2023-05-26 12:20:18 +02:00
Required? false
Position? 3
2023-12-07 20:24:45 +01:00
Default value "$HOME/CalibreUsers.sqlite"
Accept pipeline input? false
Accept wildcard characters? false
-logfile <String>
Required? false
Position? 4
2023-05-26 12:20:18 +02:00
Default value "$HOME/CalibreServer.log"
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Example
-------
2023-05-26 12:20:18 +02:00
```powershell
2023-08-06 21:36:33 +02:00
PS> ./install-calibre-server.ps1
2023-12-07 20:24:45 +01:00
⏳ (1/5) Updating package infos...
...
2023-05-26 12:20:18 +02:00
```
2023-07-29 10:04:38 +02:00
Notes
-----
2023-05-26 12:20:18 +02:00
Author: Markus Fleschutz | License: CC0
2023-07-29 10:04:38 +02:00
Related Links
-------------
2023-05-26 12:20:18 +02:00
https://github.com/fleschutz/PowerShell
2023-07-29 10:04:38 +02:00
Script Content
--------------
2023-05-26 12:20:18 +02:00
```powershell
<#
.SYNOPSIS
2023-12-07 20:24:45 +01:00
Installs the Calibre server (needs admin rights)
2023-05-26 12:20:18 +02:00
.DESCRIPTION
2023-12-07 20:24:45 +01:00
This PowerShell script installs and starts a local Calibre server as background process.
2023-05-26 12:20:18 +02:00
.PARAMETER port
Specifies the Web port number (8099 by default)
.EXAMPLE
2023-08-06 21:36:33 +02:00
PS> ./install-calibre-server.ps1
2023-12-07 20:24:45 +01:00
⏳ (1/5) Updating package infos...
...
2023-05-26 12:20:18 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#Requires -RunAsAdministrator
2023-12-07 20:24:45 +01:00
param([int]$port = 8099, [string]$mediaFolder = "$HOME/Calibre Library", [string]$userDB = "$HOME/CalibreUsers.sqlite", [string]$logfile = "$HOME/CalibreServer.log")
2023-05-26 12:20:18 +02:00
try {
2024-05-19 10:25:56 +02:00
if (-not $IsLinux) { throw "Sorry, currently only supported on Linux" }
2023-05-26 12:20:18 +02:00
2024-05-19 10:25:56 +02:00
$stopWatch = [system.diagnostics.stopwatch]::startNew()
2023-05-26 12:20:18 +02:00
2024-05-19 10:25:56 +02:00
"⏳ (1/5) Updating package infos..."
& sudo apt update -y
if ($lastExitCode -ne "0") { throw "'apt update' failed" }
2023-05-26 12:20:18 +02:00
2024-05-19 10:25:56 +02:00
"⏳ (2/5) Installing Calibre package..."
& sudo apt install calibre -y
if ($lastExitCode -ne "0") { throw "'apt install calibre' failed" }
2023-05-26 12:20:18 +02:00
2024-05-19 10:25:56 +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-05-26 12:20:18 +02:00
2024-05-19 10:25:56 +02:00
"⏳ (4/5) Creating media folder at: $mediaFolder ... (if non-existent)"
mkdir $mediaFolder
2023-05-26 12:20:18 +02:00
2024-05-19 10:25:56 +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
2024-11-08 12:35:11 +01:00
"✅ Installed Calibre server on port $port in $($elapsed)s (media at: $mediaFolder, user DB: $userDB, log to: $logfile)"
2024-05-19 10:25:56 +02:00
exit 0 # success
2023-05-26 12:20:18 +02:00
} catch {
2024-05-19 10:25:56 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
2023-05-26 12:20:18 +02:00
}
```
2024-11-20 11:52:20 +01:00
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:54)*