SPB Git

Repository Public

env.sh 2.9 KB 65 lines shellscript

1# =============================================================================2#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION3#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# Project          : KA Maps Engine7# File             : server/pipeline/geo/env.sh8# Module           : server9# Repository       : https://git.spboucher.ai/ka-maps-engine10# Created          : 2026-12-0111# Last Modified    : 2026-12-0112#13# Author           : Simon-Pierre Boucher14# Position         : Professor of Finance15# Institution      : Université du Québec en Outaouais (UQO)16# Organization     : SP Boucher17# Website          : https://spboucher.ai18# Git              : https://git.spboucher.ai19#20# Preferred Contact: support@spboucher.ai21# Technical Contact: dev@spboucher.ai22# Security/Admin   : admin@spboucher.ai23#24# Copyright (c) 202625# Simon-Pierre Boucher26# All rights reserved where applicable. This file is governed by the27# applicable project license, copyright notices and relevant law.28# Existing third-party rights and notices remain unaffected.29#30# License          : None specified (no license file in this repository)31#32# Do not embed credentials, private keys, access tokens,33# certificates or confidential personal information.34#35# =============================================================================36# END OF SP BOUCHER SOURCE HEADER37# =============================================================================3839# KA Maps — environnement commun du pipeline géographique (à « sourcer »).40#   GEO_SCHEMA : schéma de construction (défaut geo_next). Les fichiers SQL ne nomment aucun schéma : tout passe par41#   search_path = $GEO_SCHEMA, public — une construction ne peut donc ni lire ni détruire les tables servies (geo).42SRC=${SRC:-/var/lib/kamaps/src/geo}43GEO_SCHEMA=${GEO_SCHEMA:-geo_next}44case "$GEO_SCHEMA" in geo) echo "refus : on ne construit jamais directement dans le schéma servi" >&2; exit 2;; esac45if [ -z "${PGPASSWORD:-}" ]; then46  set -a47  if [ -r /etc/kamaps/db-geo.env ]; then . /etc/kamaps/db-geo.env; else . <(sudo cat /etc/kamaps/db-geo.env); fi48  set +a49fi50export PGOPTIONS="-c search_path=$GEO_SCHEMA,public"51PSQL="psql -X -q -v ON_ERROR_STOP=1"52log() { echo "$(date -u +%FT%TZ) $*"; }53# csv_load <table> <fichier.csv> [encodage] : crée la table (colonnes texte d'après l'en-tête) et charge le CSV.54csv_load() {55  local t=$1 f=$2 enc=${3:-UTF8} cols56  cols=$(head -1 "$f" | sed 's/^\xEF\xBB\xBF//' | tr -d '"\r' | tr 'A-Z' 'a-z' | sed 's/[^a-z0-9_,]/_/g' \57         | awk -F, '{for(i=1;i<=NF;i++) printf "%s\"%s\" text", (i>1?", ":""), $i}')58  $PSQL -c "DROP TABLE IF EXISTS $t; CREATE UNLOGGED TABLE $t ($cols);"59  csv_append "$t" "$f" "$enc"60}61csv_append() {62  local t=$1 f=$2 enc=${3:-UTF8}63  $PSQL -c "\\copy $t FROM '$f' WITH (FORMAT csv, HEADER true, ENCODING '$enc')"64}65
Files main
Menu

Theme