#!/bin/sh
SOURCE_PATH=/tmp/fdroid
GIT_PATH=$SOURCE_PATH/git
WORKDIR=$SOURCE_PATH/work
TARGET_PATH=/repo
REPO_PATH=$SOURCE_PATH/work/repo
S3_PATH=$SOURCE_PATH/s3

mkdir -p $SOURCE_PATH
mkdir -p $WORKDIR
mkdir -p $REPO_PATH
mkdir -p $S3_PATH
cd $WORKDIR
while true; do
  rsync -rlpcgoDv --exclude=".*" $GIT_PATH/ $WORKDIR/
  s3cmd sync --preserve s3://releases/quasseldroid-ng/ $S3_PATH/
  rsync -rlpcgoDv $S3_PATH/*-release.apk $REPO_PATH/
  fdroid update --use-date-from-apk
  fdroid signindex
  fdroid deploy
  rsync -rlpcgoDv $REPO_PATH/ $TARGET_PATH/
  sleep $UPDATE_WAIT
done
