-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
211 lines (181 loc) · 6.37 KB
/
install.sh
File metadata and controls
211 lines (181 loc) · 6.37 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
set -e
# Parse command line arguments
TARGET="$1" # Optional target parameter (stable|latest|VERSION)
# Validate target if provided
if [[ -n "$TARGET" ]] && [[ ! "$TARGET" =~ ^(stable|latest|[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
echo "Usage: $0 [stable|latest|VERSION]" >&2
exit 1
fi
REPO="21nOrg/conduct"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
DOWNLOAD_DIR="$HOME/.conduct/downloads"
# Check for required dependencies
DOWNLOADER=""
if command -v curl >/dev/null 2>&1; then
DOWNLOADER="curl"
elif command -v wget >/dev/null 2>&1; then
DOWNLOADER="wget"
else
echo "Either curl or wget is required but neither is installed" >&2
exit 1
fi
# Download function that works with both curl and wget
download_file() {
local url="$1"
local output="$2"
if [ "$DOWNLOADER" = "curl" ]; then
if [ -n "$output" ]; then
curl -fsSL -o "$output" "$url"
else
curl -fsSL "$url"
fi
elif [ "$DOWNLOADER" = "wget" ]; then
if [ -n "$output" ]; then
wget -q -O "$output" "$url"
else
wget -q -O - "$url"
fi
else
return 1
fi
}
# Detect platform
case "$(uname -s)" in
Darwin) os="darwin" ;;
Linux) os="linux" ;;
*) echo "Windows is not supported by this installer. Use: npm install -g conduct-cli" >&2; exit 1 ;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="x64" ;;
arm64|aarch64) arch="arm64" ;;
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
esac
platform="${os}-${arch}"
echo "╔═══════════════════════════════════════╗"
echo "║ Conduct CLI Installer ║"
echo "╚═══════════════════════════════════════╝"
echo ""
# Determine version to install
if [ -z "$TARGET" ] || [ "$TARGET" = "stable" ]; then
# Get latest release from GitHub
version=$(download_file "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v?([^"]+)".*/\1/')
elif [ "$TARGET" = "latest" ]; then
version=$(download_file "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v?([^"]+)".*/\1/')
else
version="$TARGET"
fi
if [ -z "$version" ]; then
echo "⚠️ Could not fetch version from GitHub releases."
echo "Falling back to npm install..."
echo ""
# Fallback to npm/bun install
if command -v bun >/dev/null 2>&1; then
echo "Installing via Bun..."
bun install -g conduct-cli
elif command -v npm >/dev/null 2>&1; then
echo "Installing via npm..."
npm install -g conduct-cli
else
echo "Error: Neither Bun nor npm is installed" >&2
echo "Install Node.js or Bun, then run: npm install -g conduct-cli" >&2
exit 1
fi
echo ""
echo "✅ Installation complete!"
echo ""
echo "🚀 Get started:"
echo " conduct init # Initialize project"
echo " conduct --help # Show all commands"
echo ""
exit 0
fi
echo "📦 Version: v$version"
echo "🖥️ Platform: $platform"
echo ""
mkdir -p "$DOWNLOAD_DIR"
# Download binary from GitHub releases
binary_name="conduct-${platform}"
download_url="https://github.com/$REPO/releases/download/v$version/$binary_name"
binary_path="$DOWNLOAD_DIR/conduct-$version-$platform"
echo "⬇️ Downloading from GitHub releases..."
if ! download_file "$download_url" "$binary_path"; then
echo "⚠️ Pre-compiled binary not found for this platform."
echo "Falling back to npm install..."
echo ""
# Fallback to npm/bun install
if command -v bun >/dev/null 2>&1; then
echo "Installing via Bun..."
bun install -g conduct-cli
elif command -v npm >/dev/null 2>&1; then
echo "Installing via npm..."
npm install -g conduct-cli
else
echo "Error: Neither Bun nor npm is installed" >&2
echo "Install Node.js or Bun, then run: npm install -g conduct-cli" >&2
exit 1
fi
echo ""
echo "✅ Installation complete!"
echo ""
echo "🚀 Get started:"
echo " conduct init # Initialize project"
echo " conduct --help # Show all commands"
echo ""
exit 0
fi
# Optional: Verify checksum if checksums.txt exists
checksums_url="https://github.com/$REPO/releases/download/v$version/checksums.txt"
if download_file "$checksums_url" "$DOWNLOAD_DIR/checksums.txt" 2>/dev/null; then
echo "🔒 Verifying checksum..."
if command -v shasum >/dev/null 2>&1; then
actual=$(shasum -a 256 "$binary_path" | cut -d' ' -f1)
elif command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$binary_path" | cut -d' ' -f1)
else
echo "⚠️ Checksum verification skipped (shasum/sha256sum not found)"
actual=""
fi
if [ -n "$actual" ]; then
expected=$(grep "$binary_name" "$DOWNLOAD_DIR/checksums.txt" | cut -d' ' -f1)
if [ "$actual" != "$expected" ]; then
echo "❌ Checksum verification failed" >&2
rm -f "$binary_path"
exit 1
fi
echo "✅ Checksum verified"
fi
fi
chmod +x "$binary_path"
# Install to bin directory
mkdir -p "$INSTALL_DIR"
echo "📦 Installing to $INSTALL_DIR/conduct..."
if [ -w "$INSTALL_DIR" ]; then
mv "$binary_path" "$INSTALL_DIR/conduct"
else
echo "🔐 Requesting sudo access..."
sudo mv "$binary_path" "$INSTALL_DIR/conduct"
fi
# Clean up
rm -f "$DOWNLOAD_DIR/checksums.txt"
# Check if conduct is in PATH
if ! command -v conduct &> /dev/null; then
echo ""
echo "⚠️ conduct is installed but not in PATH"
echo "Add this to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo ""
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
echo ""
else
echo "✅ Installation complete!"
fi
echo ""
echo "═══════════════════════════════════════"
echo "🚀 Get started:"
echo ""
echo " conduct init # Initialize project"
echo " conduct --help # Show all commands"
echo " conduct --version # Show version"
echo ""
echo "📚 Documentation: https://conduct.run/docs"
echo "═══════════════════════════════════════"