forked from zyedidia/eget
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
116 lines (94 loc) · 2.79 KB
/
setup
File metadata and controls
116 lines (94 loc) · 2.79 KB
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
#!/usr/bin/env bash
set -euo pipefail
prepare_installer() {
echo "Initializing installer..."
SSI_VERSION="0.1.9"
# Set up tmp dir where all work is done
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
cd "$tmpdir"
export PATH="$tmpdir:$PATH"
# Download ssi if needed
if ! command -v ssi >/dev/null 2>&1 || [ "$(ssi --version 2>/dev/null)" != "$SSI_VERSION" ]; then
if command -v curl >/dev/null 2>&1; then
curl -fSsL https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi -o ssi
elif command -v wget >/dev/null 2>&1; then
wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi
else
echo "Error: please install wget or curl, then try again" >&2
exit 1
fi
chmod +x ssi
fi
}
github_latest_tag() {
local body
if command -v curl >/dev/null 2>&1; then
body="$(curl -fSsL https://api.github.com/repos/DannyBen/eget/releases/latest)"
else
body="$(wget -qO- https://api.github.com/repos/DannyBen/eget/releases/latest)"
fi
printf "%s\n" "$body" | sed -n 's/.*"tag_name":[[:space:]]*"v\([^"]*\)".*/\1/p' | head -n 1
}
detect_platform() {
local os machine
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
machine="$(uname -m)"
case "$os" in
linux)
case "$machine" in
arm64*|aarch64*) printf "linux_arm64\n" ;;
*64) printf "linux_amd64\n" ;;
esac
;;
darwin)
case "$machine" in
arm64*|aarch64*) printf "darwin_arm64\n" ;;
*64) printf "darwin_amd64\n" ;;
esac
;;
esac
}
prepare_installer
platform="${GETEGET_PLATFORM:-$(detect_platform)}"
if [[ -z "${platform:-}" ]]; then
cat <<'EOF'
Could not detect a supported platform automatically.
Set GETEGET_PLATFORM and rerun this script.
Supported values:
- linux_amd64
- linux_arm64
- darwin_amd64
- darwin_arm64
EOF
exit 1
fi
tag="$(github_latest_tag)"
if [[ -z "$tag" ]]; then
echo "Error: unable to determine the latest eget release tag" >&2
exit 1
fi
extension="tar.gz"
binary_name="eget"
archive_name="eget-${tag}-${platform}.${extension}"
download_url="https://github.com/DannyBen/eget/releases/download/v${tag}/${archive_name}"
ssi log info "Installing eget ${tag} for ${platform}"
ssi log debug "Downloading ${download_url}"
if command -v curl >/dev/null 2>&1; then
curl -fSsL "$download_url" -o "$archive_name"
else
wget -nv -O "$archive_name" "$download_url"
fi
tar -xzf "$archive_name"
ssi install bin "${binary_name}" --name "$binary_name"
if [[ -f "eget.1" ]]; then
ssi install man "eget.1"
else
ssi log warn "eget.1 not found in release archive; skipping man page install"
fi
if command -v eget >/dev/null 2>&1; then
ssi log info "eget --version : $(eget --version)"
else
ssi log warn "eget not found on PATH after install"
fi
ssi log debug "Installation complete"