-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
65 lines (55 loc) · 1.95 KB
/
install.sh
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
#!/bin/sh
set -e
owner=leonovk
repo=minicode
exe_name=minicode
githubUrl="https://github.com"
githubApiUrl="https://api.github.com"
get_os(){
os=$(uname -s | awk '{print tolower($0)}')
if [ "$os" = "linux" ]; then
echo "unknown-linux-gnu"
elif [ "$os" = "darwin" ]; then
echo "apple-darwin"
else
echo $os
fi
}
downloadFolder="${TMPDIR:-/tmp}"
os=$(get_os)
arch=$(uname -m)
file_name="${exe_name}-${arch}-${os}.tar.gz" # the file name should be download
downloaded_file="${downloadFolder}/${file_name}" # the file path should be download
executable_folder="$HOME/bin" # Eventually, the executable file will be placed here
mkdir -p ${executable_folder}
asset_path=$(
command curl -s -L \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${githubApiUrl}/repos/${owner}/${repo}/releases |
command grep -o "/${owner}/${repo}/releases/download/.*/${file_name}" |
command head -n 1
)
if [[ ! "$asset_path" ]]; then
echo "ERROR: unable to find a release asset called ${file_name}"
exit 1
fi
asset_uri="${githubUrl}${asset_path}"
echo "[1/3] Download ${asset_uri} to tmp dir ${downloadFolder}"
rm -f ${downloaded_file}
curl --silent --fail --location --output "${downloaded_file}" "${asset_uri}"
echo "[2/3] Install ${exe_name} to the ${executable_folder}"
tar -xz -f ${downloaded_file} -C ${executable_folder}
exe=${executable_folder}/${exe_name}
chmod +x ${exe}
echo "[3/3] Set environment variables"
echo ""
printf "\e[1;32m%s\e[0m was installed successfully to \e[1;34m%s\e[0m\n" "${exe_name}" "${exe}"
if command -v $exe_name --version >/dev/null; then
printf "Run '\e[1;32m%s --help\e[0m' to get started\n" "$exe_name"
else
echo "Manually add the directory to your \$HOME/.bash_profile (or similar)"
echo " echo 'export PATH=${executable_folder}:\$PATH' >> .bash_profile"
printf "Run '\e[1;32m%s --help\e[0m' to get started\n" "$exe_name"
fi
exit 0