2014-06-20 18:41:18 +00:00
|
|
|
#!/bin/sh
|
|
|
|
PRG="$0"
|
2014-03-26 07:06:39 +00:00
|
|
|
|
2014-06-20 18:41:18 +00:00
|
|
|
# resolve relative symlinks
|
2016-06-08 12:31:16 +00:00
|
|
|
while [ -h "$PRG" ]; do
|
2015-06-29 12:04:34 +00: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 18:41:18 +00: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 12:04:34 +00:00
|
|
|
# update core application files
|
2017-04-13 09:54:09 +00:00
|
|
|
PACKAGE_NAME="FileBot.jar.xz.gpg"
|
|
|
|
PACKAGE_FILE="$APP_ROOT/$PACKAGE_NAME"
|
|
|
|
PACKAGE_URL="https://sourceforge.net/projects/filebot/files/filebot/HEAD/$PACKAGE_NAME"
|
2016-06-08 12:31:16 +00:00
|
|
|
|
|
|
|
# check if file has changed
|
2017-04-13 09:54:09 +00:00
|
|
|
PACKAGE_SHA1_EXPECTED=`curl --retry 5 "$PACKAGE_URL/list" | egrep -o "[a-z0-9]{40}"`
|
|
|
|
PACKAGE_SHA1=`sha1sum $PACKAGE_FILE | cut -d' ' -f1`
|
2016-06-08 12:31:16 +00:00
|
|
|
|
2017-04-13 09:54:09 +00:00
|
|
|
if [ -z "$PACKAGE_SHA1_EXPECTED" ]; then
|
2016-07-08 09:39:05 +00:00
|
|
|
echo "SHA1 hash unknown"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-04-13 09:54:09 +00:00
|
|
|
if [ "$PACKAGE_SHA1" == "$PACKAGE_SHA1_EXPECTED" ]; then
|
|
|
|
echo "$PACKAGE_FILE [SHA1: $PACKAGE_SHA1]"
|
2016-06-08 12:31:16 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2015-06-29 12:04:34 +00:00
|
|
|
|
2017-04-13 09:54:09 +00: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 12:31:16 +00:00
|
|
|
|
2016-10-24 20:17:47 +00:00
|
|
|
# check if file has been corrupted (or modified) in transit
|
2017-04-13 09:54:09 +00:00
|
|
|
PACKAGE_SHA1=`sha1sum $PACKAGE_FILE | cut -d' ' -f1`
|
|
|
|
echo "$PACKAGE_FILE [SHA1: $PACKAGE_SHA1]"
|
2015-06-29 12:04:34 +00:00
|
|
|
|
2017-04-13 09:54:09 +00:00
|
|
|
if [ "$PACKAGE_SHA1" != "$PACKAGE_SHA1_EXPECTED" ]; then
|
|
|
|
echo "SHA1 hash mismatch [SHA1: $PACKAGE_SHA1_EXPECTED]"
|
|
|
|
rm -vf "$PACKAGE_FILE"
|
2016-06-08 12:31:16 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-10-24 20:17:47 +00:00
|
|
|
|
2017-04-13 09:54:09 +00:00
|
|
|
|
|
|
|
# initialize gpg
|
|
|
|
GPG_HOME="$APP_ROOT/.gpg"
|
|
|
|
JAR_XZ_FILE="$APP_ROOT/FileBot.jar.xz"
|
|
|
|
|
|
|
|
if [ -d "$GPG_HOME" ]; then
|
|
|
|
mkdir -p -m 700 "$GPG_HOME" && gpg --homedir "$GPG_HOME" --import "$APP_ROOT/filebot.pub"
|
|
|
|
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"
|