aboutsummaryrefslogtreecommitdiff
path: root/share/hoarder/tor-browser/unix/linux/install
blob: 5e70d84ae324784a94e7204fdd0490b543c692ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env sh
#
# Install Tor Browser
#

# Parameters
BASENAME="$0"
SHARE="$1"
LIB="$2"

# Additional parameters
DIST="https://dist.torproject.org/torbrowser/"
WORK="`mktemp -d`" || exit 1
ARCH="`uname -m`"

# Determine the application name
if echo $BASENAME | grep -q 'tor-browser-alpha'; then
  APP="tor-browser-alpha"
else
  APP="tor-browser"
  FILE_SUFFIX="_ALL"
fi

# Determine architecture
if [ "$ARCH" = "i386" ]; then
  ARCH="linux32"
elif [ "$ARCH" = "i686" ]; then
  ARCH="linux32"
elif [ "$ARCH" = "x86_64" ]; then
  if [ "$APP" = "tor-browser" ]; then
    ARCH="linux64"
  else
    ARCH="linux-x86_64"
  fi
fi

# Include basic functions
. $LIB/trashman/functions || exit 1

# Requirements
trashman_require wget lynx gpg tar xz

# Determine the current version filter
if [ "$APP" = "tor-browser" ]; then
  VERSION_FILTER="-v"
fi

# Try to get the current version
# Use a large (10000) number for grep to make sure we get all available versions
VERSION="`LC_ALL=C lynx -dump https://dist.torproject.org/torbrowser/ 2> /dev/null | grep -A 10000 References | grep -e 'torbrowser' | grep -v '?' | sort -V | sed -e 's|^.*dist.torproject.org/torbrowser/||' -e 's|/||g' | grep $VERSION_FILTER a | tail -n 1`"

# Check for available versions
if [ -z "$VERSION" ]; then
  trashman_echo "error determining the available $APP version, aborting"
  exit 1
fi

# Build the URL and filename strings
URL="${DIST}/${VERSION}/"
FILE="tor-browser-${ARCH}-${VERSION}${FILE_SUFFIX}.tar.xz"

# Download
wget "$URL/$FILE"     -O $WORK/$FILE     || exit 1
wget "$URL/$FILE.asc" -O $WORK/$FILE.asc || exit 1

# Verify
gpg --homedir $WORK/.gnupg --import $SHARE/$APP/unix/linux/files/$APP.asc || exit 1
gpg --homedir $WORK/.gnupg --verify $WORK/$FILE.asc                       || exit 1
rm -rf $WORK/.gnupg                                                       || exit 1

# Unpack
tar xvf $WORK/$FILE -C $WORK || exit 1

# Install
mkdir -p $HOME/.local/share     || exit 1
cd $HOME/.local/share           || exit 1
rm -rf $APP/$ARCH               || exit 1
mkdir -p $APP                   || exit 1
mv $WORK/tor-browser $APP/$ARCH || exit 1
rm -rf $WORK                    || exit 1

# Create symlink to scripts
mkdir -p $HOME/.local/bin                                                     || exit 1
cd $HOME/.local/bin                                                           || exit 1
ln -sf $HOME/.local/share/$APP/${ARCH}/Browser/start-tor-browser $APP-${ARCH} || exit 1

# Remove old symlink to the Tor Browser script
rm -f $HOME/.local/bin/$APP

# Done
trashman_installed_at $HOME/.local/share/$APP/$ARCH
trashman_run_with $HOME/.local/bin/$APP-$ARCH