Files
photoBooth/Opencode/scripts/setup-photobooth.sh
T
admin 209f81aa3d
🚀 Deploy — JH Photomaton / 🔍 Vérification (push) Has been cancelled
🚀 Deploy — JH Photomaton / 🍓 Deploy sur le Pi (push) Has been cancelled
first commit
2026-07-16 00:55:29 +02:00

277 lines
9.7 KiB
Bash

#!/bin/bash
# =============================================================================
# setup-photobooth.sh - Installation et deploiement complet du photomaton
# =============================================================================
# Usage: bash setup-photobooth.sh
# A executer sur un Raspberry Pi 4 fraichement installe
# =============================================================================
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_step() { echo -e "\n${CYAN}=== $1 ===${NC}\n"; }
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
REAL_USER="${SUDO_USER:-$(logname 2>/dev/null || whoami)}"
USER_HOME=$(eval echo "~$REAL_USER")
echo "============================================="
echo " Installation complete du Photomaton"
echo " Raspberry Pi 4 - 2 Go RAM"
echo "============================================="
echo ""
echo " Utilisateur: $REAL_USER"
echo " Home: $USER_HOME"
echo " Projet: $PROJECT_DIR"
echo ""
# Verifier qu'on est root pour certaines operations
NEED_SUDO=false
if [ "$EUID" -ne 0 ]; then
log_warn "Certaines etapes necessitent sudo. Vous serez peut-etre invite a entrer le mot de passe."
NEED_SUDO=true
fi
# ===================================================================
# ETAPE 1: Optimisation systeme
# ===================================================================
log_step "1/7 - Optimisation systeme"
if [ "$EUID" -eq 0 ]; then
bash "$SCRIPT_DIR/optimize-system.sh"
else
log_warn "Lancez optimize-system.sh separement avec sudo:"
echo " sudo bash $SCRIPT_DIR/optimize-system.sh"
fi
# ===================================================================
# ETAPE 2: Installation des dependances
# ===================================================================
log_step "2/7 - Installation des dependances"
sudo apt-get update -qq
sudo apt-get install -y -qq \
python3 \
python3-pip \
python3-venv \
python3-picamera2 \
libcamera-apps \
libcap-dev \
curl \
unclutter \
chromium \
git \
cups \
printer-driver-gutenprint \
cups-client
log_info "Dependances installees"
# ===================================================================
# ETAPE 3: Installation de photobooth-app
# ===================================================================
log_step "3/7 - Installation de photobooth-app"
# Creer le dossier de donnees
su - "$REAL_USER" -c "mkdir -p $USER_HOME/photobooth-data"
# Installer photobooth-app via pip (mode utilisateur)
su - "$REAL_USER" -c "pip install --user --upgrade photobooth-app" || {
log_warn "pip install --user a echoue, essai avec pipx..."
su - "$REAL_USER" -c "pip install --user pipx && pipx install photobooth-app" || {
log_warn "pipx a echoue, essai avec venv..."
su - "$REAL_USER" -c "
python3 -m venv $USER_HOME/photobooth-venv
$USER_HOME/photobooth-venv/bin/pip install photobooth-app
"
log_info "photobooth-app installe dans un venv: $USER_HOME/photobooth-venv"
log_warn "Adapter le chemin dans le service systemd (ExecStart)"
}
}
log_info "photobooth-app installe"
# ===================================================================
# ETAPE 4: Configuration du service systemd
# ===================================================================
log_step "4/7 - Configuration des services systemd"
# Service photobooth-app (service utilisateur)
su - "$REAL_USER" -c "mkdir -p $USER_HOME/.config/systemd/user/"
# Copier le service utilisateur
cp "$PROJECT_DIR/systemd/photobooth-app.service" \
"$USER_HOME/.config/systemd/user/photobooth-app.service"
chown "$REAL_USER:$REAL_USER" "$USER_HOME/.config/systemd/user/photobooth-app.service"
# Activer le linger pour que les services utilisateur demarrent au boot
loginctl enable-linger "$REAL_USER" 2>/dev/null || true
# Activer le service
su - "$REAL_USER" -c "
systemctl --user daemon-reload
systemctl --user enable photobooth-app
"
log_info "Service photobooth-app configure"
# Services systeme (watchdog + maintenance)
# Adapter les chemins dans les services
SCRIPTS_PATH="$PROJECT_DIR/scripts"
sed "s|/home/pi/photomaton/scripts|$SCRIPTS_PATH|g" \
"$PROJECT_DIR/systemd/photobooth-watchdog.service" \
> /etc/systemd/system/photobooth-watchdog.service
cp "$PROJECT_DIR/systemd/photobooth-watchdog.timer" \
/etc/systemd/system/photobooth-watchdog.timer
sed "s|/home/pi/photomaton/scripts|$SCRIPTS_PATH|g" \
"$PROJECT_DIR/systemd/photobooth-maintenance.service" \
> /etc/systemd/system/photobooth-maintenance.service
cp "$PROJECT_DIR/systemd/photobooth-maintenance.timer" \
/etc/systemd/system/photobooth-maintenance.timer
# Rendre les scripts executables
chmod +x "$SCRIPTS_PATH"/*.sh
systemctl daemon-reload
systemctl enable photobooth-watchdog.timer
systemctl enable photobooth-maintenance.timer
log_info "Watchdog et maintenance configures"
# ===================================================================
# ETAPE 5: Configuration de l'imprimante
# ===================================================================
log_step "5/7 - Configuration imprimante"
if [ "$EUID" -eq 0 ]; then
bash "$SCRIPT_DIR/setup-printer.sh"
else
log_warn "Lancez setup-printer.sh separement avec sudo:"
echo " sudo bash $SCRIPT_DIR/setup-printer.sh"
fi
# ===================================================================
# ETAPE 6: Configuration de l'auto-login et kiosk
# ===================================================================
log_step "6/7 - Configuration auto-login et mode kiosk"
# Activer l'auto-login en mode graphique
# (depand de la config actuelle, peut necessiter raspi-config)
if command -v raspi-config &>/dev/null; then
# Mode desktop auto-login
raspi-config nonint do_boot_behaviour B4 2>/dev/null || true
log_info "Auto-login graphique configure via raspi-config"
fi
# Creer le fichier .desktop pour le kiosk Chromium
# Sur RPi OS Trixie (Wayland), le fichier va dans ~/Desktop/
DESKTOP_DIR="$USER_HOME/Desktop"
su - "$REAL_USER" -c "mkdir -p $DESKTOP_DIR"
# Detecter chromium
CHROMIUM_BIN=$(command -v chromium || command -v chromium-browser || echo "chromium")
cat > "$DESKTOP_DIR/photobooth-app.desktop" << EOF
[Desktop Entry]
X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=120
Terminal=false
Type=Application
Name=Photobooth-App
Exec=bash -c "sleep 60 && $CHROMIUM_BIN --kiosk --accept-lang=fr-FR --incognito --password-store=basic --disable-features=Translate,OverscrollHistoryNavigation --noerrdialogs --disable-infobars --no-first-run --ozone-platform=wayland --enable-features=OverlayScrollbar --start-maximized --process-per-site --js-flags='--max-old-space-size=128' --renderer-process-limit=1 --disable-dev-shm-usage http://127.0.0.1:8083/"
StartupNotify=false
EOF
chown "$REAL_USER:$REAL_USER" "$DESKTOP_DIR/photobooth-app.desktop"
log_info "Mode kiosk configure (Wayland, ~/Desktop/photobooth-app.desktop)"
# ===================================================================
# ETAPE 7: Configuration finale et verification
# ===================================================================
log_step "7/7 - Verification finale"
echo ""
echo "=== Verification des composants ==="
echo ""
# Verifier photobooth-app
if su - "$REAL_USER" -c "which photobooth" &>/dev/null || \
[ -f "$USER_HOME/photobooth-venv/bin/photobooth" ]; then
echo -e " photobooth-app: ${GREEN}INSTALLE${NC}"
else
echo -e " photobooth-app: ${RED}NON TROUVE${NC}"
fi
# Verifier CUPS
if systemctl is-active cups &>/dev/null; then
echo -e " CUPS: ${GREEN}ACTIF${NC}"
else
echo -e " CUPS: ${YELLOW}INACTIF${NC}"
fi
# Verifier les imprimantes
printers=$(lpstat -p 2>/dev/null | grep -c "printer" || echo "0")
echo -e " Imprimantes: ${printers} detectee(s)"
# Verifier la camera
if libcamera-hello --list-cameras 2>/dev/null | grep -q "Available"; then
echo -e " Camera: ${GREEN}DETECTEE${NC}"
elif [ -e /dev/video0 ]; then
echo -e " Camera: ${GREEN}/dev/video0${NC}"
else
echo -e " Camera: ${YELLOW}NON DETECTEE (verifier apres reboot)${NC}"
fi
# Verifier la memoire
mem_total=$(awk '/MemTotal/ {printf "%.0f", $2/1024}' /proc/meminfo)
mem_available=$(awk '/MemAvailable/ {printf "%.0f", $2/1024}' /proc/meminfo)
echo -e " RAM: ${mem_available}Mo disponible / ${mem_total}Mo total"
# Verifier le swap
swap_total=$(awk '/SwapTotal/ {printf "%.0f", $2/1024}' /proc/meminfo)
echo -e " Swap: ${swap_total}Mo"
echo ""
echo "============================================="
echo " Installation terminee !"
echo "============================================="
echo ""
echo "Prochaines etapes:"
echo ""
echo " 1. REBOOTER le Raspberry Pi:"
echo " sudo reboot"
echo ""
echo " 2. Apres reboot, acceder a l'admin photobooth:"
echo " http://localhost:8083/admin"
echo ""
echo " 3. Configurer dans l'admin:"
echo " - Camera: Backends -> picamera2"
echo " - GPIO: hardwareinput -> activer GPIO"
echo " - Photo trigger: GPIO 27 (ou votre GPIO relay)"
echo " - Impression: Share & Print -> ajouter une action Print"
echo " Commande: /home/pi/photobooth-data/script/script_print.sh \"{filename}\" \"{media_type}\" \"{action_config_name}\" \"{copies}\""
echo " - QR Share: configurer le service QR"
echo ""
echo " 4. Si vous utilisez encore Node-RED pour le bouton:"
echo " -> Envisagez de passer au GPIO natif de photobooth-app"
echo " -> Gain: ~200 Mo de RAM en desactivant Node-RED"
echo " -> sudo systemctl disable nodered.service"
echo ""
echo " 5. Verifier que tout fonctionne:"
echo " bash $SCRIPT_DIR/health-check.sh"
echo ""