Auto-install Go and create Python venv in run_all.sh

This commit is contained in:
2026-08-07 14:06:18 -05:00
parent fcf55cc03c
commit 9aea92b21a
2 changed files with 89 additions and 10 deletions
+2 -2
View File
@@ -58,8 +58,8 @@ Provides a webpage where voters can vote
## Quick Start
1. Create and activate a Python virtual environment:
```bash
python3 -m venv .env
source .env/bin/activate
python3 -m venv .venv
source .venv/bin/activate
```
2. Install dependencies:
+87 -8
View File
@@ -25,6 +25,68 @@ detect_os() {
OS=$(detect_os)
echo -e "${BLUE}Detected OS: $OS${NC}"
# Ensure Go is installed, attempting native package manager install if missing
ensure_go() {
if command -v go >/dev/null 2>&1; then
echo -e "${GREEN}Go found: $(go version)${NC}"
return 0
fi
echo -e "${YELLOW}Go not found. Attempting to install via native package manager...${NC}"
local pm=""
if command -v apt-get >/dev/null 2>&1; then
pm="apt"
elif command -v pacman >/dev/null 2>&1; then
pm="pacman"
elif command -v dnf >/dev/null 2>&1; then
pm="dnf"
elif command -v pkg >/dev/null 2>&1 && [ "$OS" = "freebsd" ]; then
pm="pkg"
fi
if [ -z "$pm" ]; then
echo -e "${RED}Error: No supported package manager found (apt/pacman/dnf/pkg).${NC}"
echo -e "${YELLOW}Please install Go manually: https://go.dev/dl/${NC}"
exit 1
fi
local sudo_cmd=""
if [ "$(id -u)" -ne 0 ]; then
if command -v sudo >/dev/null 2>&1; then
sudo_cmd="sudo"
else
echo -e "${RED}Error: Need root privileges to install Go but sudo is unavailable.${NC}"
exit 1
fi
fi
case "$pm" in
apt)
$sudo_cmd apt-get update
$sudo_cmd apt-get install -y golang-go
;;
pacman)
$sudo_cmd pacman -Syu --noconfirm go
;;
dnf)
$sudo_cmd dnf install -y golang
;;
pkg)
$sudo_cmd pkg install -y go
;;
esac
if command -v go >/dev/null 2>&1; then
echo -e "${GREEN}Go installed successfully: $(go version)${NC}"
else
echo -e "${RED}Error: Go installation failed. Please install Go manually: https://go.dev/dl/${NC}"
exit 1
fi
}
ensure_go
# Set OS-specific binary names
get_bin_name() {
local base=$1
@@ -139,7 +201,7 @@ start_python_service() {
echo -e "${GREEN}Starting $label...${NC}"
# Activate virtual environment and run script
(source .env/bin/activate && python3 "$script" $config_arg > "$LOG_DIR/$label.log" 2>&1) &
(source .venv/bin/activate && python3 "$script" $config_arg > "$LOG_DIR/$label.log" 2>&1) &
echo $! > "$PID_DIR/$label.pid"
# Brief wait to check if it started successfully
@@ -153,13 +215,30 @@ start_python_service() {
fi
}
# Check if virtual environment exists
if [ ! -d ".env" ]; then
echo -e "${RED}Error: Python virtual environment not found at .env${NC}"
echo -e "${YELLOW}Please create it with: python3 -m venv .env${NC}"
echo -e "${YELLOW}Then install dependencies: source .env/bin/activate && pip install matrix-nio pyyaml requests${NC}"
exit 1
fi
# Ensure Python virtual environment exists, creating it if missing
ensure_venv() {
if [ -d ".venv" ]; then
echo -e "${GREEN}Python virtual environment found at .venv${NC}"
return 0
fi
echo -e "${YELLOW}Python virtual environment not found. Creating it...${NC}"
python3 -m venv .venv || {
echo -e "${RED}Error: Failed to create virtual environment. Is python3-venv installed?${NC}"
echo -e "${YELLOW}Try: sudo apt install python3-venv (or the equivalent for your distro)${NC}"
exit 1
}
echo -e "${GREEN}Virtual environment created. Installing dependencies...${NC}"
if source .venv/bin/activate && pip install matrix-nio pyyaml requests; then
echo -e "${GREEN}Dependencies installed successfully.${NC}"
else
echo -e "${RED}Error: Failed to install Python dependencies.${NC}"
exit 1
fi
}
ensure_venv
# Check if config.yaml exists
if [ ! -f "configs/config.yaml" ]; then