mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-04 22:01:26 +01:00
3.6 KiB
3.6 KiB
The install-calibre-server.ps1 Script
This PowerShell script installs and starts a local Calibre server as background process.
Parameters
/home/markus/Repos/PowerShell/scripts/install-calibre-server.ps1 [[-port] <Int32>] [[-mediaFolder] <String>] [[-userDB] <String>] [[-logfile] <String>] [<CommonParameters>]
-port <Int32>
Specifies the Web port number (8099 by default)
Required? false
Position? 1
Default value 8099
Accept pipeline input? false
Accept wildcard characters? false
-mediaFolder <String>
Required? false
Position? 2
Default value "$HOME/Calibre Library"
Accept pipeline input? false
Accept wildcard characters? false
-userDB <String>
Required? false
Position? 3
Default value "$HOME/CalibreUsers.sqlite"
Accept pipeline input? false
Accept wildcard characters? false
-logfile <String>
Required? false
Position? 4
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.
Example
PS> ./install-calibre-server.ps1
⏳ (1/5) Updating package infos...
...
Notes
Author: Markus Fleschutz | License: CC0
Related Links
https://github.com/fleschutz/PowerShell
Script Content
<#
.SYNOPSIS
Installs the Calibre server (needs admin rights)
.DESCRIPTION
This PowerShell script installs and starts a local Calibre server as background process.
.PARAMETER port
Specifies the Web port number (8099 by default)
.EXAMPLE
PS> ./install-calibre-server.ps1
⏳ (1/5) Updating package infos...
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#Requires -RunAsAdministrator
param([int]$port = 8099, [string]$mediaFolder = "$HOME/Calibre Library", [string]$userDB = "$HOME/CalibreUsers.sqlite", [string]$logfile = "$HOME/CalibreServer.log")
try {
if (-not $IsLinux) { throw "Sorry, currently only supported on Linux" }
$stopWatch = [system.diagnostics.stopwatch]::startNew()
"⏳ (1/5) Updating package infos..."
& sudo apt update -y
if ($lastExitCode -ne "0") { throw "'apt update' failed" }
"⏳ (2/5) Installing Calibre package..."
& sudo apt install calibre -y
if ($lastExitCode -ne "0") { throw "'apt install calibre' failed" }
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" }
"⏳ (4/5) Creating media folder at: $mediaFolder ... (if non-existent)"
mkdir $mediaFolder
"⏳ (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
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:54)