Repository Public
1#!/bin/bash2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : KA Maps Engine8# File : server/deploy/install-maps-studio.sh9# Module : server10# Repository : https://git.spboucher.ai/ka-maps-engine11# Created : 2026-12-0112# Last Modified : 2026-12-0113#14# Author : Simon-Pierre Boucher15# Position : Professor of Finance16# Institution : Université du Québec en Outaouais (UQO)17# Organization : SP Boucher18# Website : https://spboucher.ai19# Git : https://git.spboucher.ai20#21# Preferred Contact: support@spboucher.ai22# Technical Contact: dev@spboucher.ai23# Security/Admin : admin@spboucher.ai24#25# Copyright (c) 202626# Simon-Pierre Boucher27# All rights reserved where applicable. This file is governed by the28# applicable project license, copyright notices and relevant law.29# Existing third-party rights and notices remain unaffected.30#31# License : None specified (no license file in this repository)32#33# Do not embed credentials, private keys, access tokens,34# certificates or confidential personal information.35#36# =============================================================================37# END OF SP BOUCHER SOURCE HEADER38# =============================================================================3940# KA Maps — installe ou met à jour le service de manifeste (km-maps, 8904) et le Studio (8905) sur BHS64b.41# À lancer depuis le clone (~/ka-maps/server/deploy), utilisateur ubuntu. Idempotent.42# ./install-maps-studio.sh [--skip-kmr] [--skip-web]43# Déploie l'état du répertoire de travail pour studio/ et server/km-maps/ ; kmr est compilé contre44# le moteur du dernier commit (clone de compilation séparé, pour ne pas dépendre de fichiers en45# cours de modification dans engine/).46set -euo pipefail47HERE=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$HERE/../.." && pwd)48export PATH=/opt/node/bin:$PATH49CARGO=${CARGO:-$HOME/.cargo/bin/cargo}50skip_kmr=0; skip_web=051for a in "$@"; do case $a in --skip-kmr) skip_kmr=1;; --skip-web) skip_web=1;; esac; done5253"$HERE/setup-maps-studio-db.sh"5455if [ $skip_kmr = 0 ]; then56 BUILD=$HOME/.cache/kamaps-engine-src57 [ -d "$BUILD/.git" ] || git clone -q "$REPO" "$BUILD"58 git -C "$BUILD" fetch -q "$REPO" HEAD && git -C "$BUILD" checkout -q -f FETCH_HEAD59 mkdir -p "$BUILD/server/km-maps" && rsync -a --delete --exclude target "$REPO/server/km-maps/kmr" "$BUILD/server/km-maps/"60 ( cd "$BUILD/server/km-maps/kmr" && CARGO_TARGET_DIR=$HOME/.cache/kamaps-studio-target nice -n 10 "$CARGO" build --release --locked )61 sudo install -m 755 "$HOME/.cache/kamaps-studio-target/release/kmr" /usr/local/bin/kmr.new && sudo mv /usr/local/bin/kmr.new /usr/local/bin/kmr62 dpkg -s mesa-vulkan-drivers >/dev/null 2>&1 || sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q mesa-vulkan-drivers libvulkan163fi6465if [ $skip_web = 0 ]; then66 ( cd "$REPO/studio" && { [ -d node_modules ] || npm ci --no-audit --no-fund; } && nice npm run build )67fi6869sudo mkdir -p /opt/kamaps/app/server /opt/kamaps/app/docs /var/lib/kamaps/static-maps /var/lib/kamaps/sdk70sudo chown kamaps:kamaps /var/lib/kamaps/static-maps /var/lib/kamaps/sdk71sudo rsync -a --delete --exclude node_modules --exclude kmr --exclude test "$REPO/server/km-maps" /opt/kamaps/app/server/72sudo rsync -a --delete --exclude node_modules --exclude test --exclude e2e --exclude test-results --exclude playwright-report --exclude 'web/src' "$REPO/studio" /opt/kamaps/app/73sudo rsync -a --delete "$REPO/themes" /opt/kamaps/app/74[ -f "$REPO/docs/DATA_LICENSING.md" ] && sudo install -m 644 "$REPO/docs/DATA_LICENSING.md" /opt/kamaps/app/docs/DATA_LICENSING.md75for d in server/km-maps studio; do ( cd /opt/kamaps/app/$d && sudo env PATH="$PATH" npm ci --omit=dev --no-audit --no-fund --loglevel=error ); done76sudo chown -R root:root /opt/kamaps/app && sudo chmod -R a+rX /opt/kamaps/app7778sudo install -m 644 "$HERE/km-maps.service" "$HERE/km-studio.service" /etc/systemd/system/79sudo install -m 755 "$HERE/studio-cli" /usr/local/bin/studio80sudo systemctl daemon-reload81/usr/local/bin/studio migrate82if [ "$(psql -X -At kamaps -c 'SELECT count(*) FROM studio.theme')" = 0 ]; then /usr/local/bin/studio import-themes "$REPO/themes"; fi83for s in km-maps km-studio; do sudo systemctl enable -q $s; sudo systemctl restart $s; done84# Pare-feu : 8904 et 8905 ouverts à la seule passerelle, sur l'interface WireGuard.85for p in 8904 8905; do sudo ufw allow in on wg1 from 10.67.0.1 to any port $p proto tcp >/dev/null; done86sleep 287for s in km-maps km-studio; do printf '%s : ' $s; systemctl is-active $s; done88curl -fsS http://127.0.0.1:8904/healthz; echo; curl -fsS http://127.0.0.1:8905/healthz; echo89