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