Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·130 lines (117 loc) · 3.73 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·130 lines (117 loc) · 3.73 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
set -eu
repository="solongate/psirtmap"
install_dir="${PSIRTMAP_INSTALL_DIR:-}"
version="${PSIRTMAP_VERSION:-}"
action="${1:-install}"
need_command() {
if ! command -v "$1" >/dev/null 2>&1; then
printf 'Error: %s is required.\n' "$1" >&2
exit 1
fi
}
if [ "$action" = "uninstall" ]; then
if [ -n "$install_dir" ]; then
set -- "$install_dir"
else
set -- "$HOME/.local/bin" "/usr/local/bin"
if command -v brew >/dev/null 2>&1; then
set -- "$@" "$(brew --prefix)/bin"
fi
fi
removed=0
for dir do
if [ -f "$dir/psirtmap" ]; then
rm -f "$dir/psirtmap"
printf 'Removed %s/psirtmap\n' "$dir"
removed=1
fi
done
if [ "$removed" = 0 ]; then
printf 'PSIRTMap was not found in any common install location.\n' >&2
printf 'If you installed it elsewhere, remove that copy manually.\n' >&2
exit 1
fi
exit 0
fi
need_command curl
need_command tar
if [ -z "$install_dir" ]; then
if command -v brew >/dev/null 2>&1 && [ -w "$(brew --prefix)/bin" ]; then
install_dir="$(brew --prefix)/bin"
elif [ -d /usr/local/bin ] && [ -w /usr/local/bin ]; then
install_dir="/usr/local/bin"
else
install_dir="$HOME/.local/bin"
fi
fi
if [ -z "$version" ]; then
version=$(curl -fsSL --proto '=https' --tlsv1.2 "https://api.github.com/repos/$repository/releases/latest" |
sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)
fi
if [ -z "$version" ]; then
printf 'Error: could not determine the latest PSIRTMap release.\n' >&2
exit 1
fi
case "$version" in
v*) ;;
*) version="v$version" ;;
esac
case "$(uname -s)" in
Darwin) platform="darwin" ;;
Linux) platform="linux" ;;
*)
printf 'Error: this installer supports macOS and Linux.\n' >&2
exit 1
;;
esac
case "$(uname -m)" in
arm64|aarch64) architecture="arm64" ;;
x86_64|amd64) architecture="amd64" ;;
*)
printf 'Error: unsupported architecture %s.\n' "$(uname -m)" >&2
exit 1
;;
esac
release_version=${version#v}
package="psirtmap_${release_version}_${platform}_${architecture}"
archive="$package.tar.gz"
base_url="https://github.com/$repository/releases/download/$version"
temporary_dir=$(mktemp -d "${TMPDIR:-/tmp}/psirtmap-install.XXXXXX")
trap 'rm -rf "$temporary_dir"' EXIT HUP INT TERM
printf 'Downloading PSIRTMap %s for %s/%s...\n' "$version" "$platform" "$architecture"
curl -fsSL --proto '=https' --tlsv1.2 "$base_url/$archive" -o "$temporary_dir/$archive"
curl -fsSL --proto '=https' --tlsv1.2 "$base_url/checksums.txt" -o "$temporary_dir/checksums.txt"
expected=$(awk -v name="$archive" '{ file=$2; sub(/^\.\//, "", file); if (file == name) { print $1; exit } }' "$temporary_dir/checksums.txt")
if [ -z "$expected" ]; then
printf 'Error: release checksum for %s was not found.\n' "$archive" >&2
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$temporary_dir/$archive" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "$temporary_dir/$archive" | awk '{print $1}')
else
printf 'Error: sha256sum or shasum is required.\n' >&2
exit 1
fi
if [ "$expected" != "$actual" ]; then
printf 'Error: checksum verification failed.\n' >&2
exit 1
fi
tar -xzf "$temporary_dir/$archive" -C "$temporary_dir"
mkdir -p "$install_dir"
cp "$temporary_dir/$package/psirtmap" "$install_dir/psirtmap.new"
chmod 0755 "$install_dir/psirtmap.new"
mv "$install_dir/psirtmap.new" "$install_dir/psirtmap"
printf '\nInstalled PSIRTMap %s to %s/psirtmap\n' "$version" "$install_dir"
case ":$PATH:" in
*":$install_dir:"*)
printf 'Run: psirtmap\n'
;;
*)
printf '\nAdd this directory to PATH once, then restart your terminal:\n'
printf ' export PATH="%s:$PATH"\n' "$install_dir"
printf '\nAfter that, run: psirtmap\n'
;;
esac