-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall_script.sh
executable file
·128 lines (106 loc) · 2.78 KB
/
install_script.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
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
#!/bin/sh
# Universal installer script
set -e
# REQUIREMENTS:
# curl
# Configuration
GITHUB_REPO="darko-mesaros/shuk"
BINARY_NAME="shuk"
INSTALL_DIR="$HOME/.local/bin"
# Print error and exit
error() {
echo "Error: $1"
exit 1
}
# Detect OS and architecture
detect_platform() {
local os arch
# Detect OS
case "$(uname -s)" in
Linux)
os="unknown-linux-musl"
;;
Darwin)
os="apple-darwin"
;;
MINGW*|MSYS*|CYGWIN*)
os="pc-windows-msvc"
;;
*)
error "unsupported OS: $(uname -s)"
;;
esac
# Detect architecture
case "$(uname -m)" in
x86_64|amd64)
arch="x86_64"
;;
arm64|aarch64)
arch="aarch64"
;;
*)
error "unsupported architecture: $(uname -m)"
;;
esac
echo "${arch}-${os}"
}
# Get latest version from GitHub
get_latest_version() {
curl --silent "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
# Download and install the binary
install() {
local platform="$1"
local version="$2"
local tmp_dir
local ext
# Determine file extension
case "$platform" in
*windows*)
ext=".exe"
;;
*)
ext=""
;;
esac
# Create temporary directory
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
echo "Downloading ${BINARY_NAME} ${version} for ${platform}..."
# Download and extract
# https://github.com/darko-mesaros/shuk/releases/download/v0.4.6/shuk-x86_64-unknown-linux-gnu.tar.gz
curl -sL "https://github.com/${GITHUB_REPO}/releases/download/${version}/${BINARY_NAME}-${platform}.tar.gz" |
tar xz -C "$tmp_dir"
# Create install directory if it doesn't exist
mkdir -p "$INSTALL_DIR"
# Install binary
mv "${tmp_dir}/${BINARY_NAME}${ext}" "${INSTALL_DIR}/${BINARY_NAME}${ext}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}${ext}"
echo "Successfully installed ${BINARY_NAME} to ${INSTALL_DIR}/${BINARY_NAME}${ext}"
}
# Check if curl is available
command -v curl >/dev/null 2>&1 || error "curl is required but not installed"
# Detect platform
PLATFORM=$(detect_platform)
# Get latest version if not specified
VERSION=${1:-$(get_latest_version)}
# Install
install "$PLATFORM" "$VERSION"
# Add to PATH instructions
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*)
echo "
Please add ${INSTALL_DIR} to your PATH:
setx PATH \"%PATH%;${INSTALL_DIR}\"
"
;;
*)
echo "
Please add ${INSTALL_DIR} to your PATH:
export PATH=\"\$PATH:${INSTALL_DIR}\"
You can add this line to your ~/.bashrc or ~/.zshrc file to make it permanent.
"
;;
esac