-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·153 lines (127 loc) · 3.58 KB
/
install.sh
File metadata and controls
executable file
·153 lines (127 loc) · 3.58 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
set -e
# Constants
DEFAULT_INSTALL_DIR="$HOME/.privateer/bin"
PVTR_REPO="privateerproj/privateer"
LATEST_RELEASE_URL="https://api.github.com/repos/${PVTR_REPO}/releases/latest"
# Detect OS (darwin = macOS, linux = Linux, msys or cygwin = Windows)
OS=""
case "$(uname -s)" in
Darwin)
OS="darwin"
;;
Linux)
OS="linux"
;;
CYGWIN*|MSYS*|MINGW*)
OS="windows"
;;
*)
echo "Unsupported Environment: $(uname -s)"
exit 1
;;
esac
# Detect Architecture (x86_64 = amd64, arm64 = arm64, i386/i686 = 386)
ARCH=""
case "$(uname -m)" in
x86_64)
ARCH="x86_64"
;;
i386)
ARCH="i386"
;;
arm64)
ARCH="arm64"
;;
*)
echo "Unsupported Architecture: $(uname -m)"
exit 1
;;
esac
download_latest_release() {
local install_dir="$1"
local install_file="$install_dir/pvtr"
# Ensure the directory exists
mkdir -p "$install_dir"
# Build the grep pattern based on OS
local pattern
if [[ "$OS" == "darwin" ]]; then
pattern="browser_download_url.*${OS}.*"
else
pattern="browser_download_url.*${OS}.*${ARCH}.*"
fi
# Fetch the download URL for the latest release
local url
url=$(curl -s ${LATEST_RELEASE_URL} | grep -i "$pattern" | cut -d '"' -f 4)
if [[ -z "$url" ]]; then
echo "Failed to fetch the download URL for the latest release."
exit 1
fi
echo "Downloading from: $url"
# Download the binary to the specified install directory
curl -L -0 "$url" | tar xvf - -C "$install_dir"
if [[ $? -ne 0 ]]; then
echo "Failed to download the binary."
exit 1
fi
# Ensure the binary is executable
chmod +x "$install_file"
echo "Downloaded binary to $install_file"
}
update_path() {
local install_dir="$1"
# Check if the install directory is already in PATH
if [[ ":$PATH:" != *":$install_dir:"* ]]; then
echo "$install_dir is not in the PATH."
# Detect current shell
current_shell=$(basename "$SHELL")
case "$current_shell" in
bash)
config_file="$HOME/.bash_profile"
;;
zsh)
config_file="$HOME/.zshrc"
;;
fish)
config_file="$HOME/.config/fish/config.fish"
;;
*)
echo "Unsupported shell: $current_shell. You may need to manually add $install_dir to your PATH."
return
;;
esac
# Check if the path is already added to the config file
if ! grep -q "$install_dir" "$config_file"; then
echo "export PATH=\"$install_dir:\$PATH\"" >> "$config_file"
echo "$install_dir added to $config_file"
source $config_file
else
echo "$install_dir is already in $config_file."
fi
else
echo "$install_dir is already in the PATH."
fi
}
# Main logic
main() {
local install_dir="$DEFAULT_INSTALL_DIR"
# Handle CLI arguments for installation path override
while getopts "p:" opt; do
case $opt in
p)
install_dir="$OPTARG"
;;
*)
echo "Usage: $0 [-p install_path]"
exit 1
;;
esac
done
mkdir -p "$install_dir"
# Download the latest release
download_latest_release "$install_dir"
# Ensure the binary is accessible via PATH
update_path "$install_dir"
echo "pvtr installation complete!"
}
main "$@"