blob: 3ad6f46bb52e1b52edbf23b095aaf59d4b12cf37 (
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#!/bin/bash
# Shell script to update ungoogled-chromium Portable Linux 64-bit to the latest version
# $1 -> Wrapper symlink location
# $2 (optional) -> Install location
# Return Values:
# 0 -> failed
# 1 -> success, installed new version
# 2 -> success, did not install new version
# If first time installing: user must specify a symlink location and an installation directory
# If checking for updates: user must pass a symlink for ungoogled-chromium (this is typically just the command name if a symlink is part of the path)
# Use the symlink target to determine installation directory
PLATFORM="Portable Linux 64-bit"
# Print help message
print_help() {
echo "Usage: $0 LINK [LOCATION]"
echo
echo "LINK is the path for a symlink pointing to the ungoogled-chromium executable"
echo "LOCATION is the desired install location for ungoogled-chromium. It does not need to be specified unless installing ungoogled-chromium for the first time"
}
# Function to determine absolute path of helper scripts
# $1 -> script name
get_absolute_path() {
echo "$(dirname "$(which "$1")")/$1"
}
# Function to determine path to install to
# $1 -> LOCATION or LINK target
# Return Values:
# 0 -> failed, should print_help and exit after returning
# 1 -> success
get_install_path() {
if [ -n "$1" ]; then
if [ ! -e "$1" ]; then
echo "Error: $1 does not exist"
return 0
fi
if [ ! -w "$1" ]; then
echo "Error: cannot write to $1; insufficient permissions"
return 0
fi
echo "$1"
return 1
fi
return 0
}
# Exit if $1 does not exist
if [ -z "$1" ]; then
echo "Error: too few arguments"
print_help
exit 0
fi
# Fetch info, break and store into variables
FULL_INFO=$($(get_absolute_path "fetch_info.sh") "$PLATFORM")
if [ $? -eq 0 ]; then
echo "Error: Could not get latest version info"
exit 0
fi
NAME=$(echo "$FULL_INFO" | head -n 1 | cut -d ':' -f 1)
VERSION=$(echo "$FULL_INFO" | head -n 1 | cut -d ':' -f 2 | sed 's/^[ ]*//g' | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
URL=$(echo "$FULL_INFO" | sed -n "2p")
echo "$NAME"
echo "$VERSION"
echo "$URL"
# Check installed version number (if exists)
if [ -h "$1" ]; then
MY_VERSION=$($1 --version | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
echo "$MY_VERSION"
# Compare versions to determine if an update is necessary
$(get_absolute_path "compare_versions.sh") "$VERSION" "$MY_VERSION"
if [ $? -eq 0 ]; then
echo "ungoogled-chromium $MY_VERSION is up to date"
exit 2
fi
echo -n "Upgrade ungoogled-chromium to $VERSION? [Y/n] "
read INPUT
if [ "$INPUT" == "n" ]; then
exit 2
fi
# Get install path
INSTALL_TO=$(get_install_path $(echo "$2" | sed 's/[/]*$//g'))
if [ $? -eq 0 ]; then
INSTALL_TO=$(get_install_path $(readlink -f "$1" | sed 's/[/][^/]*[/][^/]*$//g'))
if [ $? -eq 0 ]; then
print_help
exit 0
fi
fi
echo "$INSTALL_TO"
echo "ready to go"
else
# First time installation
if [ -z "$2" ]; then
echo "Error: Missing LOCATION argument"
print_help
exit 0
fi
# Check install path argument
INSTALL_TO=$(get_install_path $(echo "$2" | sed 's/[/]*$//g'))
if [ $? -eq 0 ]; then
print_help
exit 0
fi
echo -n "Install ungoogled-chromium $VERSION to $INSTALL_TO/? [Y/n] "
read INPUT
if [ "$INPUT" == "n" ]; then
exit 2
fi
fi
# Download tar file to /tmp
DOWNLOAD_URL=$(curl -s "$URL" | grep -E -o "href=\".*tar\.xz\"" | cut -d '"' -f 2)
# wget --quiet -O "/tmp/ungoogled-chromium_${VERSION}_linux.tar.xz" "$DOWNLOAD_URL"
TAR_FILE="/tmp/ungoogled-chromium_${VERSION}_linux.tar.xz"
if [ ! -r "$TAR_FILE" ]; then
echo "Error: Issue downloading ungoogled-chromium $VERSION from $DOWNLOAD_URL"
exit 0
fi
# Check hash
HASH=$(curl -s "$URL" | grep "MD5" | sed 's/<[^<>]*>//g;s/[ ]//g' | cut -d ':' -f 2)
if [ "$HASH" != $(md5sum "$TAR_FILE" | cut -d ' ' -f 1) ]; then
echo "Error: MD5 checksum failed"
rm "$TAR_FILE"
exit 0
fi
# Extract to INSTALL_TO
|