aboutsummaryrefslogtreecommitdiff
path: root/share/hoarder/tor-browser/unix/linux/install
blob: 2503eebe2118a84a42439ea3511f3fcf258a83d7 (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
93
94
95
96
97
98
99
#!/usr/bin/env sh
#
# Installs the latest Tor Browser stable or alpha
#

# 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"
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-linux-${ARCH}-${VERSION}.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

# Prepare the destination folder
mkdir -p $HOME/.local/share || exit 1

# Install
if [ "$APP" == "tor-browser" ]; then
  # Always use the "latest" folder. Tor Browser has a self-update mechanism that
  # will ensure that this installation is always the latest.
  mkdir -p $HOME/.local/share            || exit 1
  cd $HOME/.local/share                  || exit 1
  rm -rf $APP/$ARCH/latest               || exit 1
  mkdir -p $APP/$ARCH                    || exit 1
  mv $WORK/tor-browser $APP/$ARCH/latest || exit 1
  rm -rf $WORK                           || exit 1
elif [ "$APP" == "tor-browser-alpha" ]; then
  # Since this is an alpha version, use per-version folders
  cd $HOME/.local/share                    || exit 1
  rm -rf $APP/$ARCH/$VERSION               || exit 1
  mkdir -p $APP/$ARCH                      || exit 1
  mv $WORK/tor-browser $APP/$ARCH/$VERSION || exit 1
  rm -rf $WORK                             || exit 1
  rm -rf $APP/$ARCH/latest                 || exit 1
  cd $APP/$ARCH && ln -s $VERSION latest   || exit 1
fi

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

# Additional symlink for the alpha version
if [ "$APP" == "tor-browser-alpha" ]; then
  ln -sf $HOME/.local/share/$APP/$ARCH/$VERSION/Browser/start-tor-browser $APP-${ARCH}-${VERSION} || exit 1
fi

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

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