Guest User

Untitled

a guest
Mar 10th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.62 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2009 Benjamin Drung <bdrung at ubuntu dot com>
  4. # Copyright (C) 2012 Alessio Sergi <al3hex at gmail dot com>
  5. #
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. set -e
  21.  
  22. # filled by the PKGBUILD
  23. NAME='REPL_NAME'
  24. VERSION='REPL_VERSION'
  25. LANGUAGE="REPL_LANGUAGE"
  26.  
  27. DIRECTORY=~/.$NAME
  28. INSTALL_DIRECTORY=$DIRECTORY/INSTALL
  29. VERSION_FILE=$DIRECTORY/VERSION
  30. LOG_FILE=$DIRECTORY/LOG
  31. ARCH=$(uname -m)
  32. DOWNLOAD_URL="https://www.torproject.org/dist/torbrowser/linux/tor-browser-gnu-linux-${ARCH}-${VERSION}-${LANGUAGE}.tar.gz"
  33. SIG_URL=$DOWNLOAD_URL.asc
  34.  
  35. notify() {
  36.   local title="$1"
  37.   local message="$2"
  38.  
  39.   if [ $(which zenity 2>/dev/null) ]; then
  40.     zenity --info --title "$title" --text "$message"
  41.   elif [ $(which notify-send 2>/dev/null) ]; then
  42.     notify-send "$title" "$message"
  43.   elif [ $(which kdialog 2>/dev/null) ]; then
  44.     kdialog --title "$title" --passivepopup "$message"
  45.   else
  46.     echo -e "$0: [$title] $message" >&2
  47.   fi
  48. }
  49.  
  50. update() {
  51.     # remove previous installation and archives
  52.     rm -rf $INSTALL_DIRECTORY/* $DIRECTORY/*.tar.gz $DIRECTORY/*.asc
  53.  
  54.     notify "Info" "Downloading and installing package archive, please be patient.\
  55.         \nTor-Browser will start automatically afterwards." &
  56.  
  57.     echo "$0: Downloading $DOWNLOAD_URL." >> $LOG_FILE
  58.     wget $DOWNLOAD_URL >> $LOG_FILE 2>&1 || notify "Error" \
  59.         "The tor-browser archive could not be downloaded. \
  60.         \nCheck your Internet connection and try again. \
  61.         \nThe error log can be found in $LOG_FILE."
  62.  
  63.     echo "$0: Downloading $SIG_URL" >> $LOG_FILE
  64.     wget $SIG_URL >> $LOG_FILE 2>&1 || notify "Error" \
  65.         "The tor-browser archive signature file could not be downloaded. \
  66.         \nCheck your Internet connection and try again. \
  67.         \nThe error log can be found in $LOG_FILE."
  68.  
  69. #   if [ $(which gpg 2>/dev/null) ]; then
  70. #       gpg --auto-key-locate x-hkp://pool.sks-keyservers.net \
  71. #           --verify tor-browser-gnu-linux-${ARCH}-${VERSION}-${LANGUAGE}.tar.gz.asc \
  72. #           tor-browser-gnu-linux-${ARCH}-${VERSION}-${LANGUAGE}.tar.gz \
  73. #           >> $LOG_FILE 2>&1 || notify "Warning" \
  74. #           "Problems checking the signature of \
  75. #           tor-browser-gnu-linux-${ARCH}-${VERSION}.tar.gz. \
  76. #           \nEither there was an error retrieving the public key or the signature is incorrect!\
  77. #           \nThe log file can be found in $LOG_FILE."
  78. #   fi
  79.  
  80.     tar -xzf tor-browser-gnu-linux-${ARCH}-${VERSION}-${LANGUAGE}.tar.gz -C $INSTALL_DIRECTORY >> $LOG_FILE 2>&1 || notify "Error" \
  81.         "Error unpacking tor-browser-gnu-linux-${ARCH}-${VERSION}-${LANGUAGE}.tar.gz. \
  82.         \nThe error log can be found in $LOG_FILE."
  83.  
  84.     mv $INSTALL_DIRECTORY/tor-browser_${LANGUAGE}/* $INSTALL_DIRECTORY >> $LOG_FILE 2>&1
  85.     rm -rf $INSTALL_DIRECTORY/tor-browser_${LANGUAGE}/ tor-browser-gnu-linux-${ARCH}-${VERSION}-${LANGUAGE}.tar.gz tor-browser-gnu-linux-${ARCH}-${VERSION}-${LANGUAGE}.tar.gz.asc >> $LOG_FILE 2>&1
  86.     [[ -f $INSTALL_DIRECTORY/start-tor-browser ]] && echo $VERSION > $VERSION_FILE
  87. }
  88.  
  89. usage() {
  90.   cat <<EOF
  91. Usage: ${0##*/} [option]
  92.  
  93. Options:
  94.   -h                Show this help message and exit
  95.   -u                Force update
  96.   -r <directory>    The Tor-Browser directory to use
  97. EOF
  98. }
  99.  
  100. while getopts ':hr:u' opt; do
  101.     case "$opt" in
  102.         h) usage; exit 0 ;;
  103.         r) DIRECTORY="$OPTARG" ;;
  104.         u) update=1 ;;
  105.         :) echo "$0: Option '-$OPTARG' requires an argument" >&2
  106.             exit 1 ;;
  107.         *) echo "$0: Invalid option '-$OPTARG'" >&2
  108.             usage; exit 1 ;;
  109.     esac
  110. done
  111.  
  112. # create directory, if it is missing (e.g. first run)
  113. [[ ! -d "$INSTALL_DIRECTORY" ]] && mkdir -p "$INSTALL_DIRECTORY"
  114. cd "$DIRECTORY"
  115.  
  116. # clear log
  117. > $LOG_FILE
  118.  
  119. # create version file if missing
  120. [[ ! -f $VERSION_FILE ]] && echo 0 > $VERSION_FILE
  121.  
  122. #get installed version
  123. while read line
  124. do
  125.     INSTALLED_VERSION=$line
  126. done < $VERSION_FILE
  127.  
  128. # start update if old or no tor-browser is installed
  129. if [[ "$INSTALLED_VERSION" == "$VERSION" ]] && [[ $update != 1 ]]; then
  130.     cd $INSTALL_DIRECTORY && './start-tor-browser'
  131. else
  132.     echo "$0: Your version in $DIRECTORY is outdated or you do not have installed $NAME yet." >> $LOG_FILE
  133.     update
  134.  
  135.     # fire up
  136.     $NAME
  137. fi
Advertisement
Add Comment
Please, Sign In to add comment