|
|
@@ -25,19 +25,10 @@ YELLOW='\033[1;33m'
|
|
|
BLUE='\033[0;34m'
|
|
|
NC='\033[0m' # No Color
|
|
|
|
|
|
-# Resolve the real user when run via sudo
|
|
|
-if [[ -n "$SUDO_USER" ]]; then
|
|
|
- REAL_USER="$SUDO_USER"
|
|
|
- REAL_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
|
|
|
-else
|
|
|
- REAL_USER="$USER"
|
|
|
- REAL_HOME="$HOME"
|
|
|
-fi
|
|
|
-
|
|
|
# Default options
|
|
|
FIX_WIFI=true # Applied by default for stability
|
|
|
SETUP_HOTSPOT=true # Autohotspot for first-time WiFi setup
|
|
|
-INSTALL_DIR="$REAL_HOME/dune-weaver"
|
|
|
+INSTALL_DIR="$HOME/dune-weaver"
|
|
|
REPO_URL="https://github.com/tuanchris/dune-weaver"
|
|
|
|
|
|
# Parse arguments
|
|
|
@@ -97,13 +88,37 @@ install_system_deps() {
|
|
|
sudo apt update
|
|
|
sudo DEBIAN_FRONTEND=noninteractive apt install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
|
|
|
python3-venv python3-pip python3-dev \
|
|
|
- gcc g++ make swig scons \
|
|
|
+ gcc g++ make swig unzip wget \
|
|
|
libjpeg-dev zlib1g-dev \
|
|
|
libgpiod-dev gpiod \
|
|
|
- curl nginx git vim
|
|
|
+ nginx git vim
|
|
|
print_success "System dependencies installed"
|
|
|
}
|
|
|
|
|
|
+# Install lgpio C library from source (not packaged in Trixie)
|
|
|
+install_lgpio() {
|
|
|
+ # Check if already installed
|
|
|
+ if ldconfig -p | grep -q liblgpio; then
|
|
|
+ echo "lgpio C library already installed"
|
|
|
+ return
|
|
|
+ fi
|
|
|
+
|
|
|
+ print_step "Building lgpio C library from source..."
|
|
|
+ local tmpdir
|
|
|
+ tmpdir=$(mktemp -d)
|
|
|
+ cd "$tmpdir"
|
|
|
+ wget -q https://github.com/joan2937/lg/archive/master.zip
|
|
|
+ unzip -q master.zip
|
|
|
+ cd lg-master
|
|
|
+ make
|
|
|
+ sudo make install
|
|
|
+ cd /
|
|
|
+ rm -rf "$tmpdir"
|
|
|
+ # Update linker cache so pip can find liblgpio.so
|
|
|
+ sudo ldconfig
|
|
|
+ print_success "lgpio C library installed"
|
|
|
+}
|
|
|
+
|
|
|
# Install Node.js 20 via nodesource
|
|
|
install_nodejs() {
|
|
|
print_step "Installing Node.js..."
|
|
|
@@ -227,45 +242,33 @@ ensure_repo() {
|
|
|
return
|
|
|
fi
|
|
|
|
|
|
- # Clone the repository (as the real user, not root)
|
|
|
+ # Clone the repository
|
|
|
print_step "Cloning dune-weaver repository..."
|
|
|
- if [[ -n "$SUDO_USER" ]]; then
|
|
|
- sudo -u "$REAL_USER" git clone "$REPO_URL" --single-branch "$INSTALL_DIR"
|
|
|
- else
|
|
|
- git clone "$REPO_URL" --single-branch "$INSTALL_DIR"
|
|
|
- fi
|
|
|
+ git clone "$REPO_URL" --single-branch "$INSTALL_DIR"
|
|
|
cd "$INSTALL_DIR"
|
|
|
print_success "Cloned to $INSTALL_DIR"
|
|
|
}
|
|
|
|
|
|
-# Run a command as the real user (handles sudo case)
|
|
|
-run_as_user() {
|
|
|
- if [[ -n "$SUDO_USER" ]]; then
|
|
|
- sudo -u "$REAL_USER" "$@"
|
|
|
- else
|
|
|
- "$@"
|
|
|
- fi
|
|
|
-}
|
|
|
-
|
|
|
# Deploy native (venv + systemd + nginx)
|
|
|
deploy_native() {
|
|
|
print_step "Setting up Python virtual environment..."
|
|
|
|
|
|
cd "$INSTALL_DIR"
|
|
|
|
|
|
- # Create venv (as real user, not root)
|
|
|
- run_as_user python3 -m venv .venv
|
|
|
+ # Create venv
|
|
|
+ python3 -m venv .venv
|
|
|
+ source .venv/bin/activate
|
|
|
|
|
|
# Install dependencies
|
|
|
print_step "Installing Python packages..."
|
|
|
- run_as_user .venv/bin/pip install --upgrade pip
|
|
|
- run_as_user .venv/bin/pip install -r requirements.txt
|
|
|
+ pip install --upgrade pip
|
|
|
+ pip install -r requirements.txt
|
|
|
|
|
|
# Build frontend
|
|
|
print_step "Building frontend..."
|
|
|
cd "$INSTALL_DIR/frontend"
|
|
|
- run_as_user npm ci
|
|
|
- run_as_user npm run build
|
|
|
+ npm ci
|
|
|
+ npm run build
|
|
|
cd "$INSTALL_DIR"
|
|
|
|
|
|
# Configure nginx
|
|
|
@@ -281,7 +284,7 @@ deploy_native() {
|
|
|
# Create systemd service
|
|
|
print_step "Creating systemd service..."
|
|
|
sudo cp "$INSTALL_DIR/dune-weaver.service" /etc/systemd/system/dune-weaver.service
|
|
|
- sudo sed -i "s|USER_PLACEHOLDER|$REAL_USER|g" /etc/systemd/system/dune-weaver.service
|
|
|
+ sudo sed -i "s|USER_PLACEHOLDER|$USER|g" /etc/systemd/system/dune-weaver.service
|
|
|
sudo sed -i "s|INSTALL_DIR_PLACEHOLDER|$INSTALL_DIR|g" /etc/systemd/system/dune-weaver.service
|
|
|
|
|
|
# Enable and start service
|
|
|
@@ -292,11 +295,11 @@ deploy_native() {
|
|
|
# Create sudoers entry for passwordless systemctl commands
|
|
|
print_step "Configuring sudo permissions..."
|
|
|
sudo tee /etc/sudoers.d/dune-weaver > /dev/null << EOF
|
|
|
-$REAL_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart dune-weaver
|
|
|
-$REAL_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop dune-weaver
|
|
|
-$REAL_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl start dune-weaver
|
|
|
-$REAL_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl poweroff
|
|
|
-$REAL_USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx
|
|
|
+$USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart dune-weaver
|
|
|
+$USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop dune-weaver
|
|
|
+$USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl start dune-weaver
|
|
|
+$USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl poweroff
|
|
|
+$USER ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx
|
|
|
EOF
|
|
|
sudo chmod 0440 /etc/sudoers.d/dune-weaver
|
|
|
|
|
|
@@ -412,6 +415,7 @@ main() {
|
|
|
setup_autohotspot
|
|
|
fi
|
|
|
|
|
|
+ install_lgpio
|
|
|
deploy_native
|
|
|
install_cli
|
|
|
print_final_instructions
|