forked from JHUISI/charm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·673 lines (595 loc) · 22.5 KB
/
install.sh
File metadata and controls
executable file
·673 lines (595 loc) · 22.5 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
#!/bin/bash
#
# Charm-Crypto Installation Script
# Supports: Ubuntu/Debian, Fedora/RHEL/CentOS, Arch Linux, and macOS
#
# Usage:
# curl -sSL https://raw.githubusercontent.com/JHUISI/charm/dev/install.sh | bash
# curl -sSL ... | bash -s -- --from-source
#
# Options:
# --from-pypi Install from PyPI (default)
# --from-source Clone and build from source
# --deps-only Only install system dependencies
# --no-sudo Don't use sudo (for containers)
# --prefix=PATH Installation prefix (default: /usr/local)
# --python=PATH Path to Python interpreter
# --help Show this help message
set -euo pipefail
# Configuration
CHARM_VERSION="0.62"
PBC_VERSION="1.0.0"
CHARM_REPO="https://github.com/JHUISI/charm.git"
PBC_URL="https://crypto.stanford.edu/pbc/files/pbc-${PBC_VERSION}.tar.gz"
# Default options
INSTALL_MODE="pypi"
USE_SUDO="yes"
PREFIX="/usr/local"
PYTHON_PATH=""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Detected values (set by detect_os)
OS=""
ARCH=""
DISTRO=""
HOMEBREW_PREFIX=""
PYTHON=""
SUDO=""
# Track temp directories for cleanup on error
CLEANUP_DIRS=""
# Cleanup function for error handling
cleanup() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo -e "${RED}[ERROR]${NC} Installation failed with exit code $exit_code" >&2
fi
# Clean up any temp directories we created
if [ -n "$CLEANUP_DIRS" ]; then
for dir in $CLEANUP_DIRS; do
if [ -d "$dir" ]; then
rm -rf "$dir" 2>/dev/null || true
fi
done
fi
}
trap cleanup EXIT
#######################################
# Logging functions
#######################################
info() { echo -e "${BLUE}[INFO]${NC} $*"; }
success() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
fatal() { error "$*"; exit 1; }
#######################################
# OS Detection
#######################################
detect_os() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux)
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO="$ID"
else
DISTRO="unknown"
fi
;;
Darwin)
DISTRO="macos"
if [ "$ARCH" = "arm64" ]; then
HOMEBREW_PREFIX="/opt/homebrew"
else
HOMEBREW_PREFIX="/usr/local"
fi
;;
*)
fatal "Unsupported operating system: $OS"
;;
esac
info "Detected: $OS ($DISTRO) on $ARCH"
}
#######################################
# Python Detection
#######################################
detect_python() {
if [ -n "$PYTHON_PATH" ]; then
PYTHON="$PYTHON_PATH"
else
for py in python3.12 python3.11 python3.10 python3.9 python3.8 python3; do
if command -v "$py" &> /dev/null; then
local version
# Use format() instead of f-strings for Python 2.x compatibility during detection
version=$("$py" -c "import sys; print('{0}.{1}'.format(sys.version_info.major, sys.version_info.minor))" 2>/dev/null)
if [ -z "$version" ]; then
continue
fi
local major minor
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
# Check for Python 3.8+ (major > 3, or major == 3 and minor >= 8)
if [ "$major" -gt 3 ] || { [ "$major" -eq 3 ] && [ "$minor" -ge 8 ]; }; then
PYTHON="$py"
break
fi
fi
done
fi
if [ -z "${PYTHON:-}" ]; then
fatal "Python 3.8+ not found. Please install Python 3.8 or later."
fi
info "Using Python: $PYTHON ($($PYTHON --version))"
}
#######################################
# Install System Dependencies
#######################################
install_deps_ubuntu() {
info "Installing dependencies for Ubuntu/Debian..."
$SUDO apt-get update
$SUDO apt-get install -y \
build-essential gcc g++ make flex bison m4 wget git \
python3 python3-dev python3-pip python3-venv \
libgmp-dev libssl-dev
success "Ubuntu/Debian dependencies installed"
}
install_deps_fedora() {
info "Installing dependencies for Fedora/RHEL..."
$SUDO dnf install -y \
gcc gcc-c++ make flex flex-devel bison m4 wget git \
python3 python3-devel python3-pip \
gmp-devel openssl-devel \
diffutils coreutils
success "Fedora/RHEL dependencies installed"
}
install_deps_arch() {
info "Installing dependencies for Arch Linux..."
$SUDO pacman -S --noconfirm --needed \
base-devel flex bison wget git m4 \
python python-pip \
gmp openssl
success "Arch Linux dependencies installed"
}
install_deps_macos() {
info "Installing dependencies for macOS..."
if ! command -v brew &> /dev/null; then
warn "Homebrew not found. Installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [ "$ARCH" = "arm64" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi
fi
# Issue #4: Install each package separately with proper error handling
# Only ignore "already installed" warnings, not genuine failures
local brew_packages="gmp openssl@3 wget python@3"
for pkg in $brew_packages; do
if brew list "$pkg" &>/dev/null; then
info "$pkg is already installed"
else
info "Installing $pkg..."
if ! brew install "$pkg"; then
error "Failed to install $pkg"
fatal "Homebrew package installation failed. Please check the error above."
fi
fi
done
success "macOS dependencies installed"
}
install_system_deps() {
case "$DISTRO" in
ubuntu|debian|linuxmint|pop)
install_deps_ubuntu
;;
fedora)
install_deps_fedora
;;
rhel|centos|rocky|alma|ol)
# Issue #5: RHEL-based distros may need EPEL - improved detection for RHEL 9+
if ! $SUDO dnf repolist 2>/dev/null | grep -qi epel; then
info "Enabling EPEL repository..."
# Try epel-release first (works on CentOS, Rocky, Alma)
if $SUDO dnf install -y epel-release 2>/dev/null; then
success "EPEL repository enabled via epel-release"
# For RHEL proper, try the EPEL RPM directly
elif command -v subscription-manager &> /dev/null; then
# Get RHEL major version
local rhel_version
rhel_version=$(rpm -E %rhel 2>/dev/null || echo "9")
info "Attempting to install EPEL for RHEL ${rhel_version}..."
$SUDO dnf install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${rhel_version}.noarch.rpm" 2>/dev/null || \
warn "Could not install EPEL - some packages may not be available"
else
warn "Could not enable EPEL repository - some packages may not be available"
fi
fi
install_deps_fedora
;;
arch|manjaro|endeavouros|artix)
install_deps_arch
;;
macos)
install_deps_macos
;;
*)
# Try to detect by package manager
if command -v apt-get &> /dev/null; then
warn "Unknown distro '$DISTRO', but apt-get found. Trying Ubuntu/Debian method..."
install_deps_ubuntu
elif command -v dnf &> /dev/null; then
warn "Unknown distro '$DISTRO', but dnf found. Trying Fedora method..."
install_deps_fedora
elif command -v pacman &> /dev/null; then
warn "Unknown distro '$DISTRO', but pacman found. Trying Arch method..."
install_deps_arch
elif command -v yum &> /dev/null; then
warn "Unknown distro '$DISTRO', but yum found. Trying RHEL method..."
$SUDO yum install -y \
gcc gcc-c++ make flex bison m4 wget git \
python3 python3-devel python3-pip \
gmp-devel openssl-devel
success "Dependencies installed via yum"
else
fatal "Unsupported distribution: $DISTRO. Please install dependencies manually."
fi
;;
esac
}
#######################################
# Build and Install PBC Library
#######################################
install_pbc() {
info "Building PBC library v${PBC_VERSION}..."
# Check if already installed
if [ -f "${PREFIX}/lib/libpbc.so" ] || [ -f "${PREFIX}/lib/libpbc.dylib" ] || \
[ -f "${PREFIX}/lib/libpbc.a" ]; then
success "PBC library already installed at ${PREFIX}/lib"
return 0
fi
local PBC_TMPDIR
PBC_TMPDIR=$(mktemp -d)
CLEANUP_DIRS="$CLEANUP_DIRS $PBC_TMPDIR"
cd "$PBC_TMPDIR"
info "Downloading PBC from ${PBC_URL}..."
# Issue #10: Use curl as fallback if wget is not available
if command -v wget &> /dev/null; then
wget -q "$PBC_URL" -O "pbc-${PBC_VERSION}.tar.gz"
elif command -v curl &> /dev/null; then
curl -sSL "$PBC_URL" -o "pbc-${PBC_VERSION}.tar.gz"
else
fatal "Neither wget nor curl found. Please install one of them."
fi
tar xzf "pbc-${PBC_VERSION}.tar.gz"
cd "pbc-${PBC_VERSION}"
info "Configuring PBC..."
# Issue #2 & #3: PBC's configure script requires yywrap from libfl, but modern flex doesn't always provide it
# Create a stub library in our temp directory (not hardcoded /tmp)
local STUB_DIR="${PBC_TMPDIR}/stubs"
mkdir -p "$STUB_DIR"
local STUB_LDFLAGS=""
if echo 'int yywrap(void) { return 1; }' | gcc -c -x c - -o "${STUB_DIR}/yywrap.o" 2>/dev/null; then
if ar rcs "${STUB_DIR}/libfl.a" "${STUB_DIR}/yywrap.o" 2>/dev/null; then
STUB_LDFLAGS="-L${STUB_DIR}"
info "Created yywrap stub library at ${STUB_DIR}/libfl.a"
else
warn "Could not create libfl.a archive - PBC build may fail if flex doesn't provide yywrap"
fi
else
warn "Could not compile yywrap stub - PBC build may fail if flex doesn't provide yywrap"
fi
# Add -lfl to link our stub library if we created it
local FL_LINK=""
if [ -n "$STUB_LDFLAGS" ]; then
FL_LINK="-lfl"
fi
if [ "$DISTRO" = "macos" ]; then
./configure --prefix="$PREFIX" \
LDFLAGS="-L${HOMEBREW_PREFIX}/lib ${STUB_LDFLAGS} ${FL_LINK} -lgmp" \
CPPFLAGS="-I${HOMEBREW_PREFIX}/include"
else
./configure --prefix="$PREFIX" LDFLAGS="${STUB_LDFLAGS} ${FL_LINK} -lgmp"
fi
info "Building PBC (this may take a few minutes)..."
local NPROC
NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
make -j"$NPROC"
info "Installing PBC..."
$SUDO make install
# Issue #7: Update library cache on Linux - use full path or check existence
if [ "$OS" = "Linux" ]; then
if command -v ldconfig &> /dev/null; then
$SUDO ldconfig
elif [ -x /sbin/ldconfig ]; then
$SUDO /sbin/ldconfig
else
warn "ldconfig not found - you may need to run 'sudo ldconfig' manually"
fi
fi
# Cleanup
cd /
rm -rf "$PBC_TMPDIR"
success "PBC library installed to ${PREFIX}"
}
#######################################
# Install Charm-Crypto
#######################################
install_from_pypi() {
info "Installing Charm-Crypto v${CHARM_VERSION} from PyPI..."
# Set library/include paths
if [ "$OS" = "Linux" ]; then
export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH:-}"
elif [ "$OS" = "Darwin" ]; then
export DYLD_LIBRARY_PATH="${PREFIX}/lib:${DYLD_LIBRARY_PATH:-}"
export LDFLAGS="-L${PREFIX}/lib -L${HOMEBREW_PREFIX}/lib"
export CFLAGS="-I${PREFIX}/include -I${HOMEBREW_PREFIX}/include"
export CPPFLAGS="-I${PREFIX}/include -I${HOMEBREW_PREFIX}/include"
fi
# Issue #6: Detect PEP 668 (externally managed Python) by checking for EXTERNALLY-MANAGED marker
# This works on Ubuntu 23.04+, Fedora 38+, Debian 12+, Arch, and other modern distros
local PIP_EXTRA_ARGS=""
local python_lib_path
python_lib_path=$($PYTHON -c "import sys; print('{0}/lib/python{1}.{2}'.format(sys.prefix, sys.version_info.major, sys.version_info.minor))" 2>/dev/null)
# Check for EXTERNALLY-MANAGED marker in Python's lib path or common system locations
local pep668_detected="no"
if [ -n "$python_lib_path" ] && [ -f "${python_lib_path}/EXTERNALLY-MANAGED" ]; then
pep668_detected="yes"
elif [ -f /usr/lib/python3/EXTERNALLY-MANAGED ]; then
pep668_detected="yes"
elif find /usr/lib -maxdepth 2 -name "EXTERNALLY-MANAGED" -print -quit 2>/dev/null | grep -q .; then
pep668_detected="yes"
fi
if [ "$pep668_detected" = "yes" ]; then
info "Detected PEP 668 externally managed Python environment"
PIP_EXTRA_ARGS="--break-system-packages"
fi
# shellcheck disable=SC2086
$PYTHON -m pip install --upgrade pip $PIP_EXTRA_ARGS
# shellcheck disable=SC2086
$PYTHON -m pip install "charm-crypto-framework==${CHARM_VERSION}" $PIP_EXTRA_ARGS
success "Charm-Crypto installed from PyPI"
}
install_from_source() {
info "Installing Charm-Crypto from source..."
local SOURCE_TMPDIR
SOURCE_TMPDIR=$(mktemp -d)
CLEANUP_DIRS="$CLEANUP_DIRS $SOURCE_TMPDIR"
cd "$SOURCE_TMPDIR"
# Issue #11: Use --depth 1 for faster clone (only need latest commit)
info "Cloning Charm repository (shallow clone)..."
git clone --depth 1 "$CHARM_REPO"
cd charm
info "Configuring Charm..."
if [ "$DISTRO" = "macos" ]; then
./configure.sh --enable-darwin --prefix="$PREFIX"
else
./configure.sh --prefix="$PREFIX"
fi
info "Building Charm (this may take several minutes)..."
local NPROC
NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
make -j"$NPROC"
info "Installing Charm..."
$SUDO make install
# Issue #7: Use full path or check existence for ldconfig
if [ "$OS" = "Linux" ]; then
if command -v ldconfig &> /dev/null; then
$SUDO ldconfig
elif [ -x /sbin/ldconfig ]; then
$SUDO /sbin/ldconfig
else
warn "ldconfig not found - you may need to run 'sudo ldconfig' manually"
fi
fi
# Cleanup
cd /
rm -rf "$SOURCE_TMPDIR"
success "Charm-Crypto installed from source"
}
#######################################
# Verify Installation
#######################################
verify_installation() {
info "Verifying installation..."
# Set library paths for verification
if [ "$OS" = "Linux" ]; then
export LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH:-}"
elif [ "$OS" = "Darwin" ]; then
export DYLD_LIBRARY_PATH="${PREFIX}/lib:${DYLD_LIBRARY_PATH:-}"
fi
local TESTS_PASSED=0
local TESTS_TOTAL=3
# Test 1: Version check (Issue #8: use format() instead of f-string for consistency)
if $PYTHON -c "import charm; print('Version: {0}'.format(charm.__version__))" 2>/dev/null; then
success "Version check passed"
TESTS_PASSED=$((TESTS_PASSED + 1))
else
warn "Version check failed (optional - older versions may not have __version__)"
fi
# Test 2: Core module import
if $PYTHON -c "from charm.toolbox.ecgroup import ECGroup; print('ECGroup: OK')" 2>/dev/null; then
success "ECGroup module works"
TESTS_PASSED=$((TESTS_PASSED + 1))
else
error "ECGroup module failed"
fi
# Test 3: Threshold ECDSA (new in v0.62)
if $PYTHON -c "from charm.schemes.threshold.gg18_dkg import GG18_DKG; print('Threshold ECDSA: OK')" 2>/dev/null; then
success "Threshold ECDSA schemes available"
TESTS_PASSED=$((TESTS_PASSED + 1))
else
warn "Threshold ECDSA import failed (optional)"
fi
echo ""
if [ "$TESTS_PASSED" -ge 2 ]; then
success "Verification complete: ${TESTS_PASSED}/${TESTS_TOTAL} tests passed"
return 0
else
error "Verification failed: ${TESTS_PASSED}/${TESTS_TOTAL} tests passed"
return 1
fi
}
#######################################
# Configure Shell Environment
#######################################
configure_shell() {
info "Configuring shell environment..."
# Issue #9: Add fish shell support
local SHELL_RC=""
local IS_FISH="no"
case "${SHELL:-/bin/bash}" in
*/zsh) SHELL_RC="$HOME/.zshrc" ;;
*/bash) SHELL_RC="$HOME/.bashrc" ;;
*/fish)
SHELL_RC="$HOME/.config/fish/config.fish"
IS_FISH="yes"
# Ensure fish config directory exists
mkdir -p "$HOME/.config/fish"
;;
*) SHELL_RC="$HOME/.profile" ;;
esac
local LIB_VAR=""
if [ "$OS" = "Linux" ]; then
LIB_VAR="LD_LIBRARY_PATH"
elif [ "$OS" = "Darwin" ]; then
LIB_VAR="DYLD_LIBRARY_PATH"
fi
if [ -n "$LIB_VAR" ]; then
if ! grep -q "charm-crypto" "$SHELL_RC" 2>/dev/null; then
if [ "$IS_FISH" = "yes" ]; then
# Fish shell uses different syntax
{
echo ""
echo "# charm-crypto library paths (added by install.sh)"
echo "set -gx ${LIB_VAR} ${PREFIX}/lib \$${LIB_VAR}"
} >> "$SHELL_RC"
else
# POSIX-compatible shells (bash, zsh, sh)
local ENV_LINE="export ${LIB_VAR}=${PREFIX}/lib:\$${LIB_VAR}"
{
echo ""
echo "# charm-crypto library paths (added by install.sh)"
echo "$ENV_LINE"
} >> "$SHELL_RC"
fi
info "Added library paths to $SHELL_RC"
warn "Run 'source $SHELL_RC' or restart your shell to apply changes"
else
info "Shell already configured for charm-crypto"
fi
fi
}
#######################################
# Print Usage
#######################################
usage() {
local BOLD='\033[1m'
local RESET='\033[0m'
echo -e "${BOLD}Charm-Crypto Installation Script v${CHARM_VERSION}${RESET}"
echo ""
echo -e "${BOLD}Supported Platforms:${RESET}"
cat << EOF
- Ubuntu/Debian (and derivatives: Linux Mint, Pop!_OS)
- Fedora/RHEL/CentOS (and derivatives: Rocky, Alma, Oracle Linux)
- Arch Linux (and derivatives: Manjaro, EndeavourOS, Artix)
- macOS (Intel and Apple Silicon)
EOF
echo -e "${BOLD}Usage:${RESET} $0 [OPTIONS]"
echo ""
echo -e "${BOLD}Options:${RESET}"
cat << EOF
--from-pypi Install from PyPI (default, recommended)
--from-source Clone and build from source
--deps-only Only install system dependencies and PBC
--no-sudo Don't use sudo (for containers/CI)
--prefix=PATH Installation prefix (default: /usr/local)
--python=PATH Path to Python interpreter
--help, -h Show this help message
EOF
echo -e "${BOLD}Examples:${RESET}"
cat << EOF
# Default installation (recommended)
curl -sSL https://raw.githubusercontent.com/JHUISI/charm/dev/install.sh | bash
# Install from source
curl -sSL ... | bash -s -- --from-source
# Install in container without sudo
./install.sh --no-sudo
# Only install dependencies (for development)
./install.sh --deps-only
EOF
}
#######################################
# Main
#######################################
main() {
# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
--from-pypi) INSTALL_MODE="pypi" ;;
--from-source) INSTALL_MODE="source" ;;
--deps-only) INSTALL_MODE="deps-only" ;;
--no-sudo) USE_SUDO="no" ;;
--prefix=*) PREFIX="${1#*=}" ;;
--python=*) PYTHON_PATH="${1#*=}" ;;
--help|-h) usage; exit 0 ;;
*) warn "Unknown option: $1" ;;
esac
shift
done
# Banner
echo ""
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ Charm-Crypto Installation Script ║"
echo "║ Version ${CHARM_VERSION} ║"
echo "║ (Ubuntu/Debian, Fedora/RHEL, Arch Linux, macOS) ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo ""
# Set up sudo
if [ "$USE_SUDO" = "yes" ] && [ "$(id -u)" -ne 0 ]; then
SUDO="sudo"
info "Will use sudo for system installations"
else
SUDO=""
if [ "$(id -u)" -eq 0 ]; then
info "Running as root"
else
info "Running without sudo (--no-sudo)"
fi
fi
# Run installation steps
detect_os
install_system_deps
detect_python # Detect Python AFTER installing deps (which may install Python)
install_pbc
if [ "$INSTALL_MODE" != "deps-only" ]; then
if [ "$INSTALL_MODE" = "pypi" ]; then
install_from_pypi
else
install_from_source
fi
verify_installation
configure_shell
echo ""
success "═══════════════════════════════════════════════════════════"
success " Installation complete!"
success "═══════════════════════════════════════════════════════════"
echo ""
echo "Next steps:"
echo " 1. Restart your shell or run: source ~/.bashrc (or ~/.zshrc)"
echo " 2. Test the installation:"
echo " python3 -c \"from charm.toolbox.pairinggroup import PairingGroup; print('OK')\""
echo ""
else
echo ""
success "Dependencies installed. You can now build Charm from source:"
echo " git clone ${CHARM_REPO}"
echo " cd charm"
echo " ./configure.sh && make && sudo make install"
echo ""
fi
}
main "$@"