summaryrefslogtreecommitdiff
path: root/update_ungoogled_chromium-portable_linux_64.sh
blob: 05ee765fd19eb13ebc813202fe6f08393b4da7d2 (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
#!/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"
}


# 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

	# Prepare variables for upgrade
	echo "ready to go"
fi