Skip to content

Commit 0c95af9

Browse files
authored
Merge pull request #14 from abdoufermat5/develop
feat: enhance install script with interactive mode
2 parents 4650864 + 84387a3 commit 0c95af9

2 files changed

Lines changed: 81 additions & 25 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323

2424
#### Option 1: One-liner Install (Recommended)
2525
```bash
26-
# Install latest release automatically
26+
# Install latest release automatically (non-interactive)
2727
curl -fsSL https://raw.githubusercontent.com/abdoufermat5/bayesian-ssh/main/install.sh | bash
2828
```
2929

30+
```
31+
# Interactive installation (choose options)
32+
curl -fsSL https://raw.githubusercontent.com/abdoufermat5/bayesian-ssh/main/install.sh | bash -s -- --interactive
33+
```
34+
3035
#### Option 2: Manual Build
3136
```bash
3237
# Clone and build

install.sh

Lines changed: 75 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Bayesian SSH Installer
44
# Automatically downloads and installs the latest release
55
# Usage: curl -fsSL https://raw.githubusercontent.com/abdoufermat5/bayesian-ssh/main/install.sh | bash
6+
# Usage: curl -fsSL https://raw.githubusercontent.com/abdoufermat5/bayesian-ssh/main/install.sh | bash -s -- --interactive
67

78
set -e
89

@@ -18,6 +19,33 @@ REPO="abdoufermat5/bayesian-ssh"
1819
BINARY_NAME="bayesian-ssh"
1920
INSTALL_DIR="/usr/local/bin"
2021
TEMP_DIR="/tmp/bayesian-ssh-install"
22+
INTERACTIVE=false
23+
24+
# Parse command line arguments
25+
while [[ $# -gt 0 ]]; do
26+
case $1 in
27+
--interactive)
28+
INTERACTIVE=true
29+
shift
30+
;;
31+
*)
32+
echo "Unknown option: $1"
33+
echo "Usage: $0 [--interactive]"
34+
exit 1
35+
;;
36+
esac
37+
done
38+
39+
# Check if script is being piped (non-interactive)
40+
check_interactive() {
41+
if [ "$INTERACTIVE" = true ]; then
42+
echo -e "${BLUE}📋 Interactive mode enabled${NC}"
43+
elif [ -t 0 ]; then
44+
echo -e "${BLUE}📋 Interactive mode available (use --interactive flag)${NC}"
45+
else
46+
echo -e "${BLUE}📋 Non-interactive mode (piped from curl)${NC}"
47+
fi
48+
}
2149

2250
# Detect system architecture and OS
2351
detect_system() {
@@ -61,11 +89,15 @@ detect_system() {
6189
check_permissions() {
6290
if [ "$EUID" -eq 0 ]; then
6391
echo -e "${YELLOW}⚠️ Running as root - this is not recommended${NC}"
64-
read -p "Continue anyway? (y/N): " -n 1 -r
65-
echo
66-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
67-
echo -e "${RED}❌ Installation cancelled${NC}"
68-
exit 1
92+
if [ "$INTERACTIVE" = true ]; then
93+
read -p "Continue anyway? (y/N): " -n 1 -r
94+
echo
95+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
96+
echo -e "${RED}❌ Installation cancelled${NC}"
97+
exit 1
98+
fi
99+
else
100+
echo -e "${YELLOW}⚠️ Continuing as root in non-interactive mode${NC}"
69101
fi
70102
fi
71103
}
@@ -179,11 +211,15 @@ install_binary() {
179211
# Check if binary already exists
180212
if [ -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
181213
echo -e "${YELLOW}⚠️ Binary already exists at ${INSTALL_DIR}/${BINARY_NAME}${NC}"
182-
read -p "Overwrite? (y/N): " -n 1 -r
183-
echo
184-
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
185-
echo -e "${YELLOW}Installation cancelled${NC}"
186-
exit 1
214+
if [ "$INTERACTIVE" = true ]; then
215+
read -p "Overwrite? (y/N): " -n 1 -r
216+
echo
217+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
218+
echo -e "${YELLOW}Installation cancelled${NC}"
219+
exit 1
220+
fi
221+
else
222+
echo -e "${YELLOW}⚠️ Overwriting existing binary in non-interactive mode${NC}"
187223
fi
188224
fi
189225

@@ -302,25 +338,40 @@ main() {
302338
echo -e "${BLUE}========================${NC}"
303339
echo ""
304340

341+
# Check if interactive first
342+
check_interactive
343+
305344
detect_system
306345
check_permissions
307346
check_dependencies
308347

309-
# Ask user preference
310-
echo -e "${BLUE}📋 Installation Options:${NC}"
311-
echo -e " 1. Download pre-built binary (recommended)"
312-
echo -e " 2. Build from source"
313-
echo ""
314-
read -p "Choose option (1 or 2): " -n 1 -r
315-
echo
316-
317-
if [[ $REPLY =~ ^[2]$ ]]; then
318-
# Build from source
319-
build_from_source
320-
cleanup
321-
show_build_success
348+
# Choose installation method
349+
if [ "$INTERACTIVE" = true ]; then
350+
# Ask user preference
351+
echo -e "${BLUE}📋 Installation Options:${NC}"
352+
echo -e " 1. Download pre-built binary (recommended)"
353+
echo -e " 2. Build from source"
354+
echo ""
355+
read -p "Choose option (1 or 2): " -n 1 -r
356+
echo
357+
358+
if [[ $REPLY =~ ^[2]$ ]]; then
359+
# Build from source
360+
build_from_source
361+
cleanup
362+
show_build_success
363+
else
364+
# Download pre-built binary
365+
get_latest_release
366+
download_binary
367+
verify_binary
368+
install_binary
369+
cleanup
370+
show_success
371+
fi
322372
else
323-
# Download pre-built binary
373+
# Non-interactive mode - use default option
374+
echo -e "${BLUE}📋 Using default option: Download pre-built binary${NC}"
324375
get_latest_release
325376
download_binary
326377
verify_binary

0 commit comments

Comments
 (0)