2014-06-20 14:41:18 -04:00
|
|
|
#!/bin/sh
|
|
|
|
PRG="$0"
|
2014-03-26 03:06:39 -04:00
|
|
|
|
2014-06-20 14:41:18 -04:00
|
|
|
# resolve relative symlinks
|
2016-06-08 08:31:16 -04:00
|
|
|
while [ -h "$PRG" ]; do
|
2015-06-29 08:04:34 -04:00
|
|
|
ls=`ls -ld "$PRG"`
|
|
|
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
|
|
if expr "$link" : '/.*' > /dev/null; then
|
|
|
|
PRG="$link"
|
|
|
|
else
|
|
|
|
PRG="`dirname "$PRG"`/$link"
|
|
|
|
fi
|
2014-06-20 14:41:18 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
# make it fully qualified
|
|
|
|
WORKING_DIR=`pwd`
|
|
|
|
PRG_DIR=`dirname "$PRG"`
|
|
|
|
APP_ROOT=`cd "$PRG_DIR" && pwd`
|
|
|
|
|
|
|
|
# restore original working dir
|
|
|
|
cd "$WORKING_DIR"
|
|
|
|
|
|
|
|
|
2015-06-29 08:04:34 -04:00
|
|
|
# update core application files
|
2017-04-13 12:11:11 -04:00
|
|
|
PACKAGE_NAME="FileBot.jar.xz.sig"
|
2017-04-13 05:54:09 -04:00
|
|
|
PACKAGE_FILE="$APP_ROOT/$PACKAGE_NAME"
|
|
|
|
PACKAGE_URL="https://sourceforge.net/projects/filebot/files/filebot/HEAD/$PACKAGE_NAME"
|
2016-06-08 08:31:16 -04:00
|
|
|
|
|
|
|
# check if file has changed
|
2017-04-13 07:15:37 -04:00
|
|
|
PACKAGE_HASH_EXPECTED=`curl --silent --retry 5 "$PACKAGE_URL/list" | egrep -o "\b[a-z0-9]{32}\b"`
|
|
|
|
PACKAGE_HASH=`openssl dgst -md5 "$PACKAGE_FILE" | egrep -o "\b[a-z0-9]{32}\b"`
|
2016-06-08 08:31:16 -04:00
|
|
|
|
2017-04-13 07:15:37 -04:00
|
|
|
if [ -z "$PACKAGE_HASH_EXPECTED" ]; then
|
|
|
|
echo "hash unknown"
|
2016-07-08 05:39:05 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-04-13 07:15:37 -04:00
|
|
|
if [ "$PACKAGE_HASH" == "$PACKAGE_HASH_EXPECTED" ]; then
|
2017-04-13 07:18:26 -04:00
|
|
|
echo "$PACKAGE_FILE [$PACKAGE_HASH]"
|
2016-06-08 08:31:16 -04:00
|
|
|
exit 0
|
|
|
|
fi
|
2015-06-29 08:04:34 -04:00
|
|
|
|
2017-04-13 05:54:09 -04:00
|
|
|
echo "Update $PACKAGE_FILE"
|
|
|
|
curl -L -o "$PACKAGE_FILE" -z "$PACKAGE_FILE" --retry 5 "$PACKAGE_URL" # FRS will redirect to (unsecure) HTTP download link
|
2016-06-08 08:31:16 -04:00
|
|
|
|
2016-10-24 16:17:47 -04:00
|
|
|
# check if file has been corrupted (or modified) in transit
|
2017-04-13 07:15:37 -04:00
|
|
|
PACKAGE_HASH=`openssl dgst -md5 "$PACKAGE_FILE" | egrep -o "\b[a-z0-9]{32}\b"`
|
2017-04-13 07:18:26 -04:00
|
|
|
echo "$PACKAGE_FILE [$PACKAGE_HASH]"
|
2015-06-29 08:04:34 -04:00
|
|
|
|
2017-04-13 07:15:37 -04:00
|
|
|
if [ "$PACKAGE_HASH" != "$PACKAGE_HASH_EXPECTED" ]; then
|
2017-04-13 07:18:26 -04:00
|
|
|
echo "HASH hash mismatch [$PACKAGE_HASH_EXPECTED]"
|
2017-04-13 05:54:09 -04:00
|
|
|
rm -vf "$PACKAGE_FILE"
|
2016-06-08 08:31:16 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-10-24 16:17:47 -04:00
|
|
|
|
2017-04-13 05:54:09 -04:00
|
|
|
|
|
|
|
# initialize gpg
|
2017-04-13 07:29:12 -04:00
|
|
|
GPG_HOME="$APP_ROOT/data/.gpg"
|
2017-04-13 05:54:09 -04:00
|
|
|
JAR_XZ_FILE="$APP_ROOT/FileBot.jar.xz"
|
|
|
|
|
2017-04-13 06:10:53 -04:00
|
|
|
if [ ! -d "$GPG_HOME" ]; then
|
2017-04-13 07:29:12 -04:00
|
|
|
mkdir -p "$GPG_HOME" && chmod 700 "$GPG_HOME" && gpg --homedir "$GPG_HOME" --import "$APP_ROOT/filebot.pub"
|
2017-04-13 05:54:09 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# verify signature and extract jar
|
|
|
|
gpg --batch --yes --homedir "$GPG_HOME" --trusted-key "4E402EBF7C3C6A71" --output "$JAR_XZ_FILE" --decrypt "$PACKAGE_FILE" && xz --decompress --force "$JAR_XZ_FILE"
|