Repository Public
1#!/bin/zsh2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : MacLustr Social Engine & Remote Navigator8# File : infra/launchd/install-worker.sh9# Module : infra10# Repository : https://git.spboucher.ai/maclustr-social11# Project Website : https://social.spboucher.ai12# Created : 2026-12-0113# Last Modified : 2026-12-0114#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: admin@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041# install-worker.sh <prod|staging> — run on the node as the console user (asks for sudo once).42# Creates the worker token file in the dedicated account, installs Chromium there, the sudoers rule and the LaunchAgent.43set -euo pipefail44INSTANCE="${1:?prod ou staging}"; APP="${0:A:h:h:h}"; NAVUSER=mlnav45[[ "$INSTANCE" == prod ]] && { SUFFIX=""; CONTROL=http://127.0.0.1:8880; GATEWAY=ws://127.0.0.1:8882/worker; ENVF=scripts/prod-env.sh; } || { SUFFIX="-staging"; CONTROL=http://127.0.0.1:8890; GATEWAY=ws://127.0.0.1:8892/worker; ENVF=scripts/staging-env.sh; }46id $NAVUSER >/dev/null || { echo "compte $NAVUSER absent (voir docs/DEPLOYMENT.md)"; exit 1; }47dscl . -read /Groups/admin GroupMembership | grep -qw $NAVUSER && { echo "$NAVUSER est administrateur : refus"; exit 1; }48RULE="$USER ALL=($NAVUSER) NOPASSWD: SETENV: $APP/infra/launchd/run-worker.sh"49echo "$RULE" | sudo tee /etc/sudoers.d/maclustr-navigator >/dev/null; sudo chmod 440 /etc/sudoers.d/maclustr-navigator; sudo visudo -cf /etc/sudoers.d/maclustr-navigator >/dev/null50sudo -H -u $NAVUSER /bin/zsh -c "umask 077; mkdir -p /Users/$NAVUSER/.config/maclustr-navigator-worker /Users/$NAVUSER/maclustr-navigator-profiles"51TOK=/Users/$NAVUSER/.config/maclustr-navigator-worker/$INSTANCE.token52if ! sudo test -s "$TOK"; then (cd "$APP" && source $ENVF && node dist/cli.mjs worker-create "$(scutil --get LocalHostName)-$INSTANCE" "$(scutil --get LocalHostName)") | sudo -H -u $NAVUSER /bin/zsh -c "umask 077; cat > $TOK"; echo " jeton worker créé ($TOK)"; fi53sudo -H -u $NAVUSER /bin/zsh -c "cd /Users/$NAVUSER && HOME=/Users/$NAVUSER PATH=/opt/homebrew/bin:/usr/bin:/bin PLAYWRIGHT_BROWSERS_PATH=/Users/$NAVUSER/Library/Caches/ms-playwright /opt/homebrew/bin/node $APP/node_modules/playwright/cli.js install chromium" | tail -154mkdir -p ~/Library/Logs/maclustr-social ~/Library/LaunchAgents55P=~/Library/LaunchAgents/ai.spboucher.maclustr-navigator-worker$SUFFIX.plist56sed -e "s#__APP__#$APP#g" -e "s#__INSTANCE__#$INSTANCE#g" -e "s#__SUFFIX__#$SUFFIX#g" -e "s#__CONTROL__#$CONTROL#g" -e "s#__GATEWAY__#$GATEWAY#g" -e "s#__HEADED__#${MLS_HEADED:-1}#g" -e "s#__LOGS__#$HOME/Library/Logs/maclustr-social#g" "$APP/infra/launchd/ai.spboucher.maclustr-navigator-worker.plist" > "$P"57launchctl bootout "gui/$(id -u)/ai.spboucher.maclustr-navigator-worker$SUFFIX" 2>/dev/null || true58launchctl bootstrap "gui/$(id -u)" "$P" && echo " LaunchAgent chargé : ai.spboucher.maclustr-navigator-worker$SUFFIX"59