forked from gobackup/gobackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·58 lines (45 loc) · 1.44 KB
/
install
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
#!/usr/bin/env sh
set -u
type curl > /dev/null || { echo "curl: not found"; exit 1; }
set -e
get_latest_release() {
local repo="$1"
curl -sSL "https://api.github.com/repos/${repo}/releases/latest" | \
awk 'BEGIN{FS=": |,|\""}; /tag_name/{print $5}'
}
repo="gobackup/gobackup"
version="$(get_latest_release "${repo}")" # v1.2.0
# if args has version override it and not eq "latest"
if test $# -eq 1; then
if test "$1" != "latest"; then
version="$1"
echo "Install ${version}"
fi
fi
platform="$(uname | tr "[A-Z]" "[a-z]")" # Linux => linux
arch="$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')" # x86_64 => amd64, aarch64 => arm64
package="gobackup-${platform}-${arch}.tar.gz"
package_url="https://github.com/${repo}/releases/download/${version}/${package}"
bin="gobackup"
dest_dir="/usr/local/bin"
bin_path="${dest_dir}/${bin}"
tmp_dir="$(mktemp -d)"
trap "rm -r ${tmp_dir}" EXIT
if test -e "${bin_path}"; then
current_version="v$("${bin_path}" -v | awk '{print $NF}')"
if test "${current_version}" = "${version}"; then
echo "${bin} is already updated, no need to upgrade."
exit 0
else
echo "There is a new version of ${bin}, starting to upgrade from ${current_version} to ${version}."
fi
fi
cd "${tmp_dir}"
curl -sSL "${package_url}" | tar xzf -
if test $(id -u) -eq 0; then
mv "${bin}" "${dest_dir}"
else
sudo mv "${bin}" "${dest_dir}"
fi
mkdir -p ~/.gobackup
echo "${bin} ${version} has been installed."