Last active
January 3, 2016 15:29
-
-
Save aeris/8483548 to your computer and use it in GitHub Desktop.
Tor Browser Bundle auto updater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (C) 2014 aeris | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
TBB_LANG="fr" | |
TBB_DIST="https://www.torproject.org/dist/torbrowser" | |
TBB_DIR="tor-browser_${TBB_LANG}" | |
TBB_CHECKSUM=sha256sums.txt | |
TBB_TEMP=.tbb | |
LAST_VERSION="$(curl -s ${TBB_DIST}/ | sed -n 's#.*<img src="/icons/folder.gif" alt="\[DIR\]"> <a href="\([0-9.]*\)/">\1/</a>.*#\1#p' | sort -n | tail -1)" | |
TBB_FILENAME="tor-browser-linux64-${LAST_VERSION}_${TBB_LANG}.tar.xz" | |
TBB_DIST="${TBB_DIST}/${LAST_VERSION}" | |
declare -A TBB_GPG | |
TBB_GPG[erinn]="8738 A680 B84B 3031 A630 F2DB 416F 0610 63FE E659" | |
TBB_GPG[linus]="8C4C D511 095E 982E B0EF BFA2 1E8B F349 2329 1265" | |
TBB_GPG[mikeperry]="C963 C21D 6356 4E2B 10BB 335B 2984 6B3C 6836 86CC" | |
TBB_GPG[gk]="35CD 74C2 4A9B 15A1 9E1A 81A1 9437 3AA9 4B7C 3223" | |
SIGNERS_NEED=3 | |
CURRENT_VERSION=$(sed -n 's#TORBROWSER_VERSION=\([0-9.]*\)#\1#p' ${TBB_DIR}/Docs/sources/versions 2>/dev/null) | |
if [ "${CURRENT_VERSION}" != "${LAST_VERSION}" ]; then | |
mkdir "${TBB_TEMP}" &> /dev/null | |
#if [ -d "${TBB_DIR}" ]; then | |
# mv "${TBB_DIR}/Data" "${TBB_TEMP}" | |
#fi | |
cd "${TBB_TEMP}" | |
OLD_PWD="${OLDPWD}" | |
function clean_on_exit() { | |
echo "Cleaning" | |
rm -rf "${OLD_PWD}/${TBB_TEMP}" | |
} | |
trap clean_on_exit EXIT | |
echo "Updating from ${CURRENT_VERSION} to ${LAST_VERSION}" | |
echo " Downloading ${TBB_CHECKSUM}" | |
curl -Os "${TBB_DIST}/${TBB_CHECKSUM}" | |
echo " Verifying checksum GPG sign" | |
SIGNERS=0 | |
for TBB_DEV in "${!TBB_GPG[@]}"; do | |
TBB_CHECKSUM_ASC="${TBB_CHECKSUM}-${TBB_DEV}.asc" | |
echo " Downloading ${TBB_CHECKSUM_ASC}" | |
wget -q "${TBB_DIST}/${TBB_CHECKSUM_ASC}" | |
if [ -r "${TBB_CHECKSUM_ASC}" ]; then | |
echo " Verifying ${TBB_CHECKSUM_ASC}" | |
EXPECTED_FINGERPRINT="${TBB_GPG[${TBB_DEV}]}" | |
FINGERPRINT="$(LANG=C gpg --verify "${TBB_CHECKSUM_ASC}" "${TBB_CHECKSUM}" 2>&1 | sed -n "s#Primary key fingerprint: \(.*\)#\1#p")" | |
if [ -z "${FINGERPRINT}" ]; then | |
echo "/!\ Warning /!\ Invalid GPG signature for ${TBB_DEV} !!!" | |
exit 1 | |
fi | |
if [ "${FINGERPRINT}" != "${EXPECTED_FINGERPRINT}" ]; then | |
echo "/!\ Warning /!\ Wrong GPG fingerprint for ${TBB_DEV} !!!" | |
echo "Expecting ${EXPECTED_FINGERPRINT}" | |
echo "Having ${FINGERPRINT}" | |
exit 1 | |
fi | |
((++SIGNERS)) | |
else | |
echo " Missing ${TBB_CHECKSUM_ASC}" | |
fi | |
done | |
if [ ${SIGNERS} -lt ${SIGNERS_NEED} ]; then | |
echo "/!\ Warning /!\ Not enough GPG signers ${SIGNERS}/${SIGNERS_NEED} !!!" | |
exit 1 | |
fi | |
echo " Downloading ${TBB_FILENAME}" | |
curl -O "${TBB_DIST}/${TBB_FILENAME}" | |
echo " Verifying ${TBB_FILENAME} checksum" | |
egrep "\s+${TBB_FILENAME}$" "${TBB_CHECKSUM}" | sha256sum -c >/dev/null | |
if [ $? -ne 0 ]; then | |
echo "/!\ Warning /!\ Checksums don't match !!!" | |
exit 1 | |
fi | |
echo "All seems good, unpacking ${TBB_FILENAME}" | |
rm -rf "${TBB_DIR}" | |
tar -xf "${TBB_FILENAME}" -C "${OLD_PWD}" | |
#if [ -d "Data" ]; then | |
# mv -f "Data" "${OLD_PWD}/${TBB_DIR}" | |
#fi | |
cd "${OLD_PWD}" | |
trap - EXIT | |
clean_on_exit | |
else | |
echo "Up-to-date" | |
fi | |
${TBB_DIR}/start-tor-browser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment