View Single Post
Old 05-18-2025, 03:53 PM   #11
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 908
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
I've created a script to install Calibre if there's a Linux update, but it needs to tell me when I have the latest version installed. I'm posting it in case it's useful to anyone. I'll translate it to English.


Code:
#!/bin/bash

echo "�� Checking installed version of calibre..."
installed_version_full=$(calibre --version 2>/dev/null | grep -oP '\d+\.\d+(\.\d+)?')

if [ -z "$installed_version_full" ]; then
    echo "❌ calibre is not installed or the version could not be detected."
    notify-send "⚠️ calibre is not installed or the version could not be detected."
    exit 1
fi

# If the installed version has only 2 numbers, add .0 for proper comparison
if [[ "$installed_version_full" =~ ^[0-9]+\.[0-9]+$ ]]; then
    installed_version_full="${installed_version_full}.0"
fi

echo "�� Installed version: $installed_version_full"

echo "�� Checking latest available version..."
new_version=$(curl -s https://code.calibre-ebook.com/latest | jq -r '.tag_name')

if [ -z "$new_version" ]; then
    echo "❌ Could not retrieve the latest version."
    notify-send "⚠️ Could not retrieve the latest version of calibre."
    exit 1
fi

echo "�� Latest available version: $new_version"

# Compare versions
if [ "$installed_version_full" = "$new_version" ]; then
    echo "✅ calibre is up to date ($installed_version_full)."
    notify-send "✅ calibre is up to date ($installed_version_full)."
    exit 0
else
    echo "⬇️ New version available: $new_version. Starting update..."
    notify-send "⬇️ New version available: $new_version. Starting update..."
fi

# Download installer
installer_url="https://download.calibre-ebook.com/${new_version}/calibre-linux-installer.sh"
echo "�� Downloading from: $installer_url"
wget -q --show-progress -O calibre_installer.sh "$installer_url"

# Check if an HTML page was downloaded by mistake
if grep -q "<!DOCTYPE html>" calibre_installer.sh; then
    echo "❌ Error: the installer was not downloaded correctly."
    notify-send "⚠️ Error downloading calibre installer."
    rm -f calibre_installer.sh
    exit 1
fi

chmod +x calibre_installer.sh

# Run the installer
echo "�� Starting installation..."
sudo ./calibre_installer.sh

# Check installed version after installation
new_installed=$(calibre --version 2>/dev/null | grep -oP '\d+\.\d+(\.\d+)?')
if [[ "$new_installed" =~ ^[0-9]+\.[0-9]+$ ]]; then
    new_installed="${new_installed}.0"
fi

if [ "$new_installed" = "$new_version" ]; then
    echo "✅ calibre updated to $new_installed."
    notify-send "✅ calibre updated to $new_installed."
else
    echo "⚠️ The update did not complete successfully."
    notify-send "⚠️ The update did not complete successfully."
fi

rm -f calibre_installer.sh
Attached Thumbnails
Click image for larger version

Name:	1.png
Views:	73
Size:	83.8 KB
ID:	215755  
Attached Files
File Type: zip calibre_installer.zip (391 Bytes, 63 views)

Last edited by dunhill; 05-18-2025 at 04:00 PM.
dunhill is offline   Reply With Quote