-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·157 lines (129 loc) · 3.67 KB
/
install.sh
File metadata and controls
executable file
·157 lines (129 loc) · 3.67 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
154
155
156
157
#!/bin/bash
#
# Devstrap installer script
# Usage: curl -fsSL https://raw.githubusercontent.com/codoworks/devstrap/main/install.sh | bash
#
set -e
REPO="codoworks/devstrap"
BINARY_NAME="devstrap"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Detect OS
detect_os() {
case "$(uname -s)" in
Darwin)
echo "darwin"
;;
Linux)
echo "linux"
;;
*)
error "Unsupported operating system: $(uname -s)"
;;
esac
}
# Detect architecture
detect_arch() {
case "$(uname -m)" in
x86_64|amd64)
echo "amd64"
;;
arm64|aarch64)
echo "arm64"
;;
*)
error "Unsupported architecture: $(uname -m)"
;;
esac
}
# Get the latest release version from GitHub
get_latest_version() {
local latest_url="https://api.github.com/repos/${REPO}/releases/latest"
local version
if command -v curl &> /dev/null; then
version=$(curl -fsSL "$latest_url" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
elif command -v wget &> /dev/null; then
version=$(wget -qO- "$latest_url" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
else
error "curl or wget is required to download devstrap"
fi
if [ -z "$version" ]; then
error "Failed to get latest version from GitHub"
fi
echo "$version"
}
# Download and install the binary
install_binary() {
local os="$1"
local arch="$2"
local version="$3"
# Remove 'v' prefix if present for filename
local version_num="${version#v}"
local filename="${BINARY_NAME}_${version_num}_${os}_${arch}.tar.gz"
local download_url="https://github.com/${REPO}/releases/download/${version}/${filename}"
info "Downloading ${BINARY_NAME} ${version} for ${os}/${arch}..."
local tmp_dir
tmp_dir=$(mktemp -d)
trap "rm -rf ${tmp_dir}" EXIT
if command -v curl &> /dev/null; then
curl -fsSL "$download_url" -o "${tmp_dir}/${filename}" || error "Failed to download from ${download_url}"
else
wget -q "$download_url" -O "${tmp_dir}/${filename}" || error "Failed to download from ${download_url}"
fi
info "Extracting..."
tar -xzf "${tmp_dir}/${filename}" -C "${tmp_dir}"
# Check if we need sudo
if [ -w "$INSTALL_DIR" ]; then
mv "${tmp_dir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
else
info "Installing to ${INSTALL_DIR} (requires sudo)..."
sudo mv "${tmp_dir}/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"
sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
fi
}
# Verify installation
verify_installation() {
if command -v "$BINARY_NAME" &> /dev/null; then
info "Successfully installed ${BINARY_NAME}!"
echo ""
"$BINARY_NAME" --help
else
warn "${BINARY_NAME} was installed to ${INSTALL_DIR}/${BINARY_NAME}"
warn "Make sure ${INSTALL_DIR} is in your PATH"
fi
}
main() {
echo ""
echo " Devstrap Installer"
echo " =================="
echo ""
local os
local arch
local version
os=$(detect_os)
arch=$(detect_arch)
version=$(get_latest_version)
info "Detected: ${os}/${arch}"
info "Latest version: ${version}"
install_binary "$os" "$arch" "$version"
verify_installation
echo ""
info "Get started with: devstrap init"
echo ""
}
main "$@"