Skip to content

Commit bae2df5

Browse files
committed
feat(install): enhance installer with force option and version detection
- Add --force flag to allow non-interactive reinstallation/upgrade. - Improve download progress output with speed information. - Automatically detect and display the latest version from GitHub. - Update README with usage instructions for the force option.
1 parent f8891d9 commit bae2df5

File tree

5 files changed

+91
-21
lines changed

5 files changed

+91
-21
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535
```bash
3636
# Install latest version for your platform (auto-detects OS/arch)
3737
curl -fsSL https://raw.githubusercontent.com/ali-master/pingu/master/scripts/install.sh | sh
38+
39+
# Force reinstall/upgrade without prompts
40+
curl -fsSL https://raw.githubusercontent.com/ali-master/pingu/master/scripts/install.sh | sh -s -- --force
3841
```
3942

40-
> **Note**: The installer automatically detects your operating system and CPU architecture, downloads the appropriate binary, and installs it to your system. It will try to install to `/usr/local/bin` (with sudo if needed) or fall back to `~/bin`.
43+
> **Note**: The installer automatically detects your operating system and CPU architecture, downloads the appropriate binary, and installs it to your system. It will try to install to `/usr/local/bin` (with sudo if needed) or fall back to `~/.local/bin`. When run non-interactively (piped), it will automatically proceed with upgrades.
4144
4245
### Platform-specific Downloads
4346

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@usex/pingu",
3-
"version": "0.0.0",
3+
"version": "1.0.4",
44
"description": "A modern ping utility with beautiful CLI output, real-time network analysis, and comprehensive performance metrics",
55
"keywords": [
66
"ping",

scripts/install.sh

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@ echo_e() {
1010

1111
# Pingu installer script
1212
# Usage: curl -fsSL https://raw.githubusercontent.com/ali-master/pingu/master/scripts/install.sh | sh
13+
# Force reinstall: curl -fsSL https://raw.githubusercontent.com/ali-master/pingu/master/scripts/install.sh | sh -s -- --force
1314

1415
REPO="ali-master/pingu"
1516
VERSION="latest"
17+
FORCE_INSTALL=false
18+
19+
# Parse command line arguments
20+
for arg in "$@"; do
21+
case $arg in
22+
-f|--force)
23+
FORCE_INSTALL=true
24+
shift
25+
;;
26+
*)
27+
;;
28+
esac
29+
done
1630

1731
# Colors for output
1832
RED='\033[0;31m'
@@ -95,14 +109,18 @@ download_with_progress() {
95109
echo ""
96110

97111
if command_exists curl; then
98-
# Use curl with detailed progress
112+
# Use curl with detailed progress including speed
99113
echo_e " ${DIM}Download Progress:${NC}"
100-
if ! curl -L --progress-bar \
114+
if ! curl -L \
115+
--progress-bar \
116+
--speed-time 5 \
117+
--speed-limit 1 \
101118
--connect-timeout 30 \
102119
--max-time 600 \
103120
--retry 3 \
104121
--retry-delay 2 \
105122
--user-agent "Pingu-Installer/1.0" \
123+
-w "\n ${INFO} Average download speed: ${GREEN}%{speed_download}${NC} bytes/sec\n" \
106124
"$url" -o "$output"; then
107125
return 1
108126
fi
@@ -116,7 +134,14 @@ download_with_progress() {
116134
--tries=3 \
117135
--waitretry=2 \
118136
--user-agent="Pingu-Installer/1.0" \
119-
"$url" -O "$output"; then
137+
"$url" -O "$output" 2>&1 | while IFS= read -r line; do
138+
# Extract and display speed from wget output
139+
if echo "$line" | grep -q "K/s\|M/s"; then
140+
speed=$(echo "$line" | grep -oE '[0-9.]+[KM]/s' | tail -1)
141+
printf "\r ${INFO} Download speed: ${GREEN}%s${NC} " "$speed"
142+
fi
143+
echo "$line"
144+
done; then
120145
return 1
121146
fi
122147

@@ -245,27 +270,61 @@ fi
245270
print_step "Checking Existing Installation"
246271
if command_exists pingu; then
247272
EXISTING_VERSION=$(pingu --version 2>/dev/null || echo "unknown")
248-
echo_e "${WARN} Pingu is already installed (version: ${EXISTING_VERSION})"
249-
echo -n "Do you want to reinstall/upgrade? [y/N] "
250-
read -r response
251-
case "$response" in
252-
[yY][eE][sS]|[yY])
253-
echo_e "${INFO} Proceeding with installation..."
254-
;;
255-
*)
256-
echo_e "${INFO} Installation cancelled"
257-
exit 0
258-
;;
259-
esac
273+
echo_e "${WARN} Pingu is already installed"
274+
echo_e " ${INFO} Current version: ${YELLOW}${EXISTING_VERSION}${NC}"
275+
276+
if [ "$FORCE_INSTALL" = "true" ]; then
277+
echo_e "${INFO} Force flag detected. Proceeding with installation..."
278+
else
279+
printf "Do you want to reinstall/upgrade? [y/N] "
280+
281+
# Handle non-interactive mode (when piped)
282+
if [ -t 0 ]; then
283+
# Interactive mode - read from terminal
284+
read -r response
285+
else
286+
# Non-interactive mode - assume yes for upgrades
287+
echo "y"
288+
echo_e "${INFO} Non-interactive mode detected. Auto-proceeding with upgrade..."
289+
response="y"
290+
fi
291+
292+
case "$response" in
293+
[yY][eE][sS]|[yY])
294+
echo_e "${INFO} Proceeding with installation..."
295+
;;
296+
*)
297+
echo_e "${INFO} Installation cancelled"
298+
echo_e "${DIM}Tip: Use --force flag to skip this prompt${NC}"
299+
exit 0
300+
;;
301+
esac
302+
fi
260303
else
261304
echo_e " ${CHECKMARK} No existing installation found"
262305
fi
263306
echo ""
264307

265-
# Download URL
308+
# Download URL and version detection
266309
if [ "$VERSION" = "latest" ]; then
310+
# Get latest version tag from GitHub
311+
echo_e "${INFO} Checking latest version..."
312+
if command_exists curl; then
313+
LATEST_VERSION=$(curl -s "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
314+
elif command_exists wget; then
315+
LATEST_VERSION=$(wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
316+
fi
317+
318+
if [ -n "$LATEST_VERSION" ]; then
319+
echo_e " ${CHECKMARK} Latest version: ${GREEN}${LATEST_VERSION}${NC}"
320+
else
321+
echo_e " ${WARN} Could not detect latest version, proceeding anyway..."
322+
LATEST_VERSION="latest"
323+
fi
324+
267325
DOWNLOAD_URL="https://github.com/${REPO}/releases/latest/download/${BINARY_NAME}"
268326
else
327+
LATEST_VERSION="$VERSION"
269328
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY_NAME}"
270329
fi
271330

@@ -419,9 +478,14 @@ echo ""
419478
# Verify installation
420479
print_step "Verification"
421480
if command_exists pingu; then
422-
VERSION_OUTPUT=$(pingu --version 2>/dev/null || echo "Version check failed")
481+
NEW_VERSION=$(pingu --version 2>/dev/null || echo "Version check failed")
423482
echo_e " ${CHECKMARK} Pingu is ready to use!"
424-
echo_e " ${INFO} Version: ${VERSION_OUTPUT}"
483+
484+
if [ -n "$EXISTING_VERSION" ] && [ "$EXISTING_VERSION" != "unknown" ]; then
485+
echo_e " ${INFO} Upgraded from: ${YELLOW}${EXISTING_VERSION}${NC}${GREEN}${NEW_VERSION}${NC}"
486+
else
487+
echo_e " ${INFO} Installed version: ${GREEN}${NEW_VERSION}${NC}"
488+
fi
425489
else
426490
echo_e " ${WARN} Pingu was installed but is not in PATH"
427491
echo_e " ${INFO} Binary location: ${GREEN}$INSTALL_PATH${NC}"

src/cli.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { render } from "ink";
55
import meow from "meow";
66
import App from "./app";
77
import { generateCompletion, printCompletionHelp } from "./utils/completions";
8+
import pkg from "../package.json";
89

910
const cli = meow(
1011
`
@@ -33,6 +34,7 @@ const cli = meow(
3334
`,
3435
{
3536
importMeta: import.meta,
37+
version: pkg.version,
3638
flags: {
3739
display: {
3840
type: "number",

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"module": "esnext",
1010
"moduleResolution": "bundler",
1111
"noUnusedLocals": false,
12-
"noUnusedParameters": false
12+
"noUnusedParameters": false,
13+
"resolveJsonModule": true
1314
},
1415
"include": ["src"]
1516
}

0 commit comments

Comments
 (0)