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
78set -e
89
@@ -18,6 +19,33 @@ REPO="abdoufermat5/bayesian-ssh"
1819BINARY_NAME=" bayesian-ssh"
1920INSTALL_DIR=" /usr/local/bin"
2021TEMP_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
2351detect_system () {
@@ -61,11 +89,15 @@ detect_system() {
6189check_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