Last active
August 22, 2026 23:29
-
-
Save danielmrdev/d2f4f39a8681d120f87182d4a7576034 to your computer and use it in GitHub Desktop.
Pinned Storefront installer for jailbroken Kindle KOReader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Install the pinned Storefront release into KOReader on a jailbroken Kindle. | |
| # Run this script as the Kindle user, not as root. | |
| set -eu | |
| VERSION=${STOREFRONT_VERSION:-26.8.18.2} | |
| KINDLE_ROOT=${KINDLE_ROOT:-/mnt/us} | |
| PLUGINS_DIR="$KINDLE_ROOT/koreader/plugins" | |
| TMP_ROOT=${TMPDIR:-/tmp} | |
| WORK_DIR="$TMP_ROOT/storefront-install.$$" | |
| ZIP_FILE="$TMP_ROOT/storefront.koplugin.$$.zip" | |
| STAGING_DIR="$PLUGINS_DIR/.storefront.koplugin.new.$$" | |
| DEST_DIR="$PLUGINS_DIR/storefront.koplugin" | |
| BACKUP_DIR="$PLUGINS_DIR/.storefront.koplugin.backup.$$" | |
| URL="https://github.com/ultimatejimmy/storefront.koplugin/releases/download/$VERSION/storefront.koplugin.zip" | |
| BACKUP_ACTIVE=0 | |
| fail() { | |
| echo "Storefront installation failed: $*" >&2 | |
| exit 1 | |
| } | |
| cleanup() { | |
| status=$? | |
| # If replacement was interrupted, put the previous plugin back. | |
| if [ "$BACKUP_ACTIVE" -eq 1 ] && [ ! -e "$DEST_DIR" ] && [ -e "$BACKUP_DIR" ]; then | |
| mv "$BACKUP_DIR" "$DEST_DIR" || echo "Warning: restore failed: $DEST_DIR" >&2 | |
| fi | |
| rm -rf "$WORK_DIR" "$ZIP_FILE" "$STAGING_DIR" | |
| exit "$status" | |
| } | |
| trap cleanup 0 1 2 3 15 | |
| case "$VERSION" in | |
| ''|*[!A-Za-z0-9._-]*) fail "invalid STOREFRONT_VERSION: $VERSION" ;; | |
| esac | |
| command -v curl >/dev/null 2>&1 || fail "curl is required" | |
| command -v unzip >/dev/null 2>&1 || fail "unzip is required" | |
| [ -d "$KINDLE_ROOT" ] || fail "Kindle storage not found: $KINDLE_ROOT" | |
| [ -d "$KINDLE_ROOT/koreader" ] || fail "KOReader not found: $KINDLE_ROOT/koreader" | |
| [ -d "$PLUGINS_DIR" ] || fail "KOReader plugin directory not found: $PLUGINS_DIR" | |
| rm -rf "$WORK_DIR" "$ZIP_FILE" "$STAGING_DIR" "$BACKUP_DIR" | |
| mkdir -p "$WORK_DIR" | |
| echo "Downloading Storefront $VERSION..." | |
| curl -fL --retry 3 --retry-delay 2 -o "$ZIP_FILE" "$URL" | |
| [ -s "$ZIP_FILE" ] || fail "downloaded archive is empty" | |
| echo "Checking archive contents..." | |
| unzip -q "$ZIP_FILE" -d "$WORK_DIR" | |
| PLUGIN_COUNT=$(find "$WORK_DIR" -type d -name 'storefront.koplugin' | wc -l | tr -d ' ') | |
| [ "$PLUGIN_COUNT" = 1 ] || fail "expected one storefront.koplugin directory, found $PLUGIN_COUNT" | |
| PLUGIN_DIR=$(find "$WORK_DIR" -type d -name 'storefront.koplugin' | sed -n '1p') | |
| [ -f "$PLUGIN_DIR/main.lua" ] || fail "archive does not contain storefront.koplugin/main.lua" | |
| # Prepare the replacement outside the destination path so a failed copy leaves | |
| # an existing installation untouched. | |
| echo "Installing Storefront..." | |
| cp -R "$PLUGIN_DIR" "$STAGING_DIR" | |
| [ -f "$STAGING_DIR/main.lua" ] || fail "staged plugin is incomplete" | |
| if [ -e "$DEST_DIR" ]; then | |
| mv "$DEST_DIR" "$BACKUP_DIR" | |
| BACKUP_ACTIVE=1 | |
| fi | |
| if mv "$STAGING_DIR" "$DEST_DIR"; then | |
| BACKUP_ACTIVE=0 | |
| rm -rf "$BACKUP_DIR" | |
| else | |
| fail "could not activate the new plugin" | |
| fi | |
| sync | |
| rm -rf "$WORK_DIR" "$ZIP_FILE" | |
| echo "Storefront $VERSION installed. Restart KOReader, then open Tools > Storefront." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment