Skip to content

Instantly share code, notes, and snippets.

@giuseppe998e
Last active September 23, 2024 08:08
Show Gist options
  • Save giuseppe998e/2e3a8de4e9aaab0805599b8e13252b4e to your computer and use it in GitHub Desktop.
Save giuseppe998e/2e3a8de4e9aaab0805599b8e13252b4e to your computer and use it in GitHub Desktop.
Calibre AppImage - Launcher with updater

Calibre AppImage Auto-Update Launcher

This README provides instructions on how to install the launch.sh script for automatically updating and launching Calibre in AppImage format.

Installation Steps

  1. Create the Directory: Open a terminal and create a directory for Calibre in /opt with write permissions for the current user:

    sudo mkdir /opt/calibre
    sudo chown $USER:$USER /opt/calibre
  2. Download launch.sh: Download the launch.sh file and place it in the /opt/calibre directory:

    cp /path/to/launch.sh /opt/calibre/
  3. Make the Script Executable: Ensure that the launch.sh script is executable:

    chmod +x /opt/calibre/launch.sh
  4. Launch the Script: On first startup, the script will download the latest available version of the Calibre AppImage; it may take a while.
    From the next startup onward, the script will check the version and update the app if necessary.

  5. (Optional) Install Desktop Entry: To have Calibre available in your application menu, you can install the calibre-appimage.desktop file. You can do this using the following command:

    xdg-desktop-menu install /path/to/calibre-appimage.desktop

    Alternatively, you can manually copy the .desktop file to the ~/.local/share/applications directory:

    cp /path/to/calibre-appimage.desktop ~/.local/share/applications/

References

Notes

Make sure to check the permissions and ownership of the files in /opt/calibre to ensure that the script runs smoothly.
If you encounter any issues, refer to the documentation provided in the respective repositories.

Any and all suggestions are welcome.

[Desktop Entry]
Type=Application
Name=Calibre
GenericName=E-book library management
Comment=E-book library management: Convert, view, share, catalogue all your e-books
Exec=/opt/calibre/launch.sh %F
Icon=calibre
MimeType=application/x-mobipocket-ebook;application/epub+zip;x-content/ebook-reader
Categories=Office;Graphics;Viewer;
X-GNOME-UsesNotifications=true
#!/usr/bin/env sh
# Repository config
GITHUB_REPOSITORY="KushagraKarira/calibre-appimage"
APPIMAGE_FILENAME="Calibre-%#version#%-x86_64.AppImage"
# Useful constants
BASEDIR=$(dirname "$(readlink -f "$0")")
RAND_NUM=$(awk 'BEGIN { srand(); print int(10000 + rand() * 90000) }' /dev/null)
remote_version() {
wget -qO- "https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/refs/heads/main/README.md?_=${RAND_NUM}" 2>/dev/null | \
sed -ne 's/.*Calibre: //p'
}
download_appimage() {
FILENAME=$(echo "${APPIMAGE_FILENAME}" | sed "s/%#version#%/$1/")
wget -qO "$2" "https://github.com/${GITHUB_REPOSITORY}/releases/latest/download/${FILENAME}?_=${RAND_NUM}" 2>/dev/null
}
send_notification() {
notify-send "Calibre AppImage" "$1"
echo "$1"
}
main() {
REMOTE_VERSION=$(remote_version)
LOCAL_VERSION=$(cat "${BASEDIR}/version.txt" 2>/dev/null)
APPIMAGE_PATH="${BASEDIR}/calibre.appimage"
if [ -z "$REMOTE_VERSION" ] && [ ! -f "$APPIMAGE_PATH" ]; then
send_notification "Unable to retrieve the remote version."
exit 1
elif [ "$REMOTE_VERSION" != "$LOCAL_VERSION" ]; then
send_notification "Update available for Calibre. Downloading..."
if download_appimage "$REMOTE_VERSION" "$APPIMAGE_PATH"; then
send_notification "Calibre successfully updated to version $REMOTE_VERSION."
echo "$REMOTE_VERSION" > "${BASEDIR}/version.txt"
chmod +x "$APPIMAGE_PATH"
else
send_notification "Error during the download of Calibre."
exit 1
fi
fi
"$APPIMAGE_PATH" "$@"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment