#!/bin/sh # This expects one argument: the name of the EPUB to edit. # Modify these if the programs were installed elsewhere ZIP=/mnt/ext1/system/bin/zip UNZIP=/mnt/ext1/system/bin/unzip PI=/mnt/ext1/applications/pi.app SH_IVTOOL=/mnt/ext1/system/bin/sh_ivtool.app # The rest should be system independent. # This is where we temporarily unpack the EPUB files. # (It has to be inside a Unix directory, because unpacking and packing # within a FAT directory seems to produce invalid EPUB files.) BASENAME=`basename "$1"` TMPDIR="/tmp/${BASENAME}.dir" # Delete the temporary files later, no matter how we leave. trap 'rm -rf "$TMPDIR"' 0 # Unpack the files. mkdir -p "$TMPDIR" cd "$TMPDIR" $UNZIP -q -u "$1" -d "$TMPDIR" if [ $? -gt 0 ]; then $SH_IVTOOL -s "Problems while unzipping. Giving up!" exit -1 fi EXT=`$SH_IVTOOL -t "Enter filename extension (or leave blank to see all files)"` # Edit whatever files are chosen $SH_IVTOOL -s "Select file(s) to edit, or click Back button to exit selection" DO_MORE=1 while [ $DO_MORE -eq 1 ]; do FILE=`$SH_IVTOOL -f "$TMPDIR" "$EXT"` if [ $? -eq 0 ]; then $PI "$FILE" else DO_MORE=0 fi done # Get the name of the output file NEWFILE=`basename "$1"` RESP=`$SH_IVTOOL -q "Overwrite the old file?"` if [ $? -ne 0 -o "$RESP" == 'n' ]; then NEWFILE=`$SH_IVTOOL -t "Enter new file name (without .epub), or leave blank to discard"`.epub if [ $? -ne 0 ]; then $SH_IVTOOL -s "No filename given. Discarding results." exit -1 fi fi # Zip up the contents $ZIP "$NEWFILE" -0 mimetype $ZIP -r "$NEWFILE" * -x mimetype # Move the new file into the same directory as the old file # (overwriting it if the names are the same) mv "$NEWFILE" `dirname "$1"`