#!/usr/bin/env bash

SCRIPT_DIR=$(dirname $(realpath $0))

[[ ! -e $SCRIPT_DIR/.Books/initted ]] && $SCRIPT_DIR/init.sh
[[ ! -e $SCRIPT_DIR/backgrounds ]] && ln -s "$SCRIPT_DIR/.Books/backgrounds" "$SCRIPT_DIR/backgrounds"

cd $SCRIPT_DIR && git pull
mv -f $SCRIPT_DIR/*.msk $SCRIPT_DIR/.Books/backup/

for dir in $SCRIPT_DIR/.Books/unpacked/*; do
  TITLE=${dir##*/}
  cd "$SCRIPT_DIR/.Books/unpacked/$TITLE" && zip -qu -9 -r "$SCRIPT_DIR/$TITLE.msk" *
done
