diff options
author | grufo | 2017-07-05 22:02:18 +0200 |
---|---|---|
committer | grufo | 2017-07-05 22:02:18 +0200 |
commit | f43d0cdf789c94afaa56a05b1de5db490856cc9d (patch) | |
tree | d897d2192db5a7a0b52926c6cee92aeb7d87174f /tor-browser.sh | |
parent | 1f1a1ef87513085c0931e5e3d1bcf4c5c1711700 (diff) | |
download | aur-f43d0cdf789c94afaa56a05b1de5db490856cc9d.tar.gz |
PKGBUILD only (added `--aurupdate` argument to tor-browser.sh)
Diffstat (limited to 'tor-browser.sh')
-rwxr-xr-x | tor-browser.sh | 129 |
1 files changed, 89 insertions, 40 deletions
diff --git a/tor-browser.sh b/tor-browser.sh index 288b7561ec2e..d54faa917191 100755 --- a/tor-browser.sh +++ b/tor-browser.sh @@ -4,6 +4,7 @@ # Copyright (C) 2012 Alessio Sergi <al3hex at gmail dot com> # modified 2012 for tor-browser (Max Roder <maxroder at web dot de>) # modified 2014 by Yardena Cohen <yardenack at gmail dot com> +# modified 2017 by grufo <madmurphy333 at gmail dot com> # # 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 @@ -21,45 +22,86 @@ set -e # filled by the PKGBUILD -NAME='REPL_NAME' -VERSION='REPL_VERSION' -LANGUAGE="REPL_LANGUAGE" +TB_PKGNAME='REPL_NAME' +TB_VERSION='REPL_VERSION' +TB_RELEASE='REPL_RELEASE' +TB_LANGUAGE="REPL_LANGUAGE" ARCH=$(getconf LONG_BIT) notify() { - local title="$1" - local message="$2" - - if [ $(which zenity 2>/dev/null) ]; then - zenity --info --title "$title" --text "$message" - elif [ $(which notify-send 2>/dev/null) ]; then - notify-send "$title" "$message" - elif [ $(which kdialog 2>/dev/null) ]; then - kdialog --title "$title" --passivepopup "$message" - else - echo -e "$0: [$title] $message" >&2 - fi + local title="${1}" + local message="${2}" + + if [ $(which zenity 2>/dev/null) ]; then + zenity --info --title "${title}" --text "${message}" + elif [ $(which notify-send 2>/dev/null) ]; then + notify-send "${title}" "${message}" + elif [ $(which kdialog 2>/dev/null) ]; then + kdialog --title "${title}" --passivepopup "${message}" + else + echo -e "${0}: [${title}] ${message}" >&2 + fi +} + +compare_versions() { + [ "${1}" = "${2}" ] && return 1 || [ "${1}" = "`echo -e "${1}\n${2}" | sort -V | head -n1`" ] } update() { - echo "$0: Extracting files to $INSTALL_DIRECTORY." >> $LOG_FILE - rm -rf $INSTALL_DIRECTORY/* - tar --strip-components=1 -xJf /opt/$NAME/tor-browser-linux${ARCH}-${VERSION}_${LANGUAGE}.tar.xz \ - -C $INSTALL_DIRECTORY >> $LOG_FILE 2>&1 || notify "Error" \ + echo "${0}: Extracting files to ${TB_APP_DIR}." >> "${TB_LOG_FILE}" + rm -rf "${TB_APP_DIR}"/* + tar --strip-components=1 -xJf "/opt/${TB_PKGNAME}/tor-browser-linux${ARCH}-${TB_VERSION}_${TB_LANGUAGE}.tar.xz" \ + -C "${TB_APP_DIR}" >> "${TB_LOG_FILE}" 2>&1 || notify "Error" \ "The tor-browser archive could not be extracted to your home directory. \ - \nCheck permissions of $INSTALL_DIRECTORY. \ - \nThe error log can be found in $LOG_FILE." + \nCheck permissions of ${TB_APP_DIR}. \ + \nThe error log can be found in ${TB_LOG_FILE}." + + [[ -f "${TB_APP_DIR}/Browser/start-tor-browser" ]] && echo "${TB_VERSION}" > "${TB_VER_FILE}" +} + +aur_update() { + + local DO_UPDATE='0' + local TMP_PKGBUILD="$(mktemp -d)" + + if [ "$(id -u)" == '0' ]; then + echo 'It is not a good idea to do this as root. Abort.' 1>&2 + exit 1 + fi + + cd "${TMP_PKGBUILD}" + + curl --silent "https://aur.archlinux.org/cgit/aur.git/snapshot/${TB_PKGNAME}.tar.gz" | tar xz + + cd "${TMP_PKGBUILD}/${TB_PKGNAME}" + + local NEW_VERSION="$(grep 'pkgver' '.SRCINFO' | cut -d = -f2 | sed -e 's/^[[:space:]]*//')" + local NEW_RELEASE="$(grep 'pkgrel' '.SRCINFO' | cut -d = -f2 | sed -e 's/^[[:space:]]*//')" + + if compare_versions ${TB_VERSION} ${NEW_VERSION}; then + echo 'Found new version.' + local DO_UPDATE='1' + elif [ "${TB_VERSION}" == "${NEW_VERSION}" ] && [ "${TB_RELEASE}" != "${NEW_RELEASE}" ] && [ "${TB_RELEASE}" = "`echo -e "${TB_RELEASE}\n${NEW_RELEASE}" | sort | head -n1`" ]; then + echo 'Found new PKGBUILD release.' + local DO_UPDATE='1' + else + echo 'Everything is up to date' + fi + + [ "${DO_UPDATE}" == '1' ] && makepkg -si + + rm -rf "${TMP_PKGBUILD}" - [[ -f $INSTALL_DIRECTORY/Browser/start-tor-browser ]] && echo $VERSION > $VERSION_FILE } usage() { - cat <<EOF + cat <<EOF Usage: ${0##*/} [option] Options: -h|--help Show this help message and exit + -a|--aurupdate Search for a new release on Arch User Repository (AUR) and install it -u|--update Force update of the copy in your home directory --dir=<directory> The Tor-Browser directory to use @@ -67,42 +109,49 @@ Options: EOF } -DIRECTORY=~/.$NAME +DIRECTORY=~/.${TB_PKGNAME} + +# remove old INSTALL directory (temporary command to be removed in the next versions) +if [ -d "${DIRECTORY}/INSTALL" ]; then + rm -rf "${DIRECTORY}" +fi + args=() for arg; do - case "$arg" in - -h|--help) usage; exit 0 ;; + case "${arg}" in + -h|--help) usage; exit 0 ;; + -a|--aurupdate) aur_update; exit 0 ;; -u|--update) update=1 ;; - --dir=*) DIRECTORY="${arg#*=}" ;; + --dir=*) DIRECTORY="${arg#*=}" ;; *) args+=("$arg") ;; esac done -INSTALL_DIRECTORY=$DIRECTORY/INSTALL -VERSION_FILE=$DIRECTORY/VERSION -LOG_FILE=$DIRECTORY/LOG +TB_APP_DIR="${DIRECTORY}/APP" +TB_VER_FILE="${DIRECTORY}/VERSION" +TB_LOG_FILE="${DIRECTORY}/LOG" # create directory, if it is missing (e.g. first run) -[[ ! -d "$INSTALL_DIRECTORY" ]] && mkdir -p "$INSTALL_DIRECTORY" -cd "$DIRECTORY" +[[ ! -d "${TB_APP_DIR}" ]] && mkdir -p "${TB_APP_DIR}" +cd "${DIRECTORY}" # create version file if missing -[[ ! -f $VERSION_FILE ]] && echo 0 > $VERSION_FILE +[[ ! -f "${TB_VER_FILE}" ]] && echo 0 > "${TB_VER_FILE}" -#get installed version +# get installed version while read line do - INSTALLED_VERSION=$line -done < $VERSION_FILE + TB_INSTALLED_VERSION="${line}" +done < ${TB_VER_FILE} # start update if old or no tor-browser is installed -if [[ "$INSTALLED_VERSION" == "$VERSION" ]] && [[ $update != 1 ]]; then +if [[ "${TB_INSTALLED_VERSION}" == "${TB_VERSION}" ]] && [[ ${update} != 1 ]]; then # clear log - > $LOG_FILE + > "${TB_LOG_FILE}" else - echo "$0: Your version in $DIRECTORY is outdated or you do not have installed $NAME yet." > $LOG_FILE + echo "${0}: Your version in ${DIRECTORY} is outdated or you do not have installed ${TB_PKGNAME} yet." > "${TB_LOG_FILE}" update fi # start tor-browser -cd $INSTALL_DIRECTORY/Browser && ./start-tor-browser "${args[@]}" +cd "${TB_APP_DIR}/Browser" && ./start-tor-browser "${args[@]}" |